migrate.php 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. /**
  3. * Database Migration Script
  4. * This file contains all database table creation scripts
  5. * Each table is checked for existence before creation
  6. */
  7. require_once __DIR__ . '/../vendor/autoload.php';
  8. try {
  9. $db = db();
  10. echo "Starting database migration...\n";
  11. // Migration: Create settings table
  12. $settingsTableSQL = "
  13. CREATE TABLE IF NOT EXISTS settings (
  14. id INTEGER PRIMARY KEY AUTOINCREMENT,
  15. grupa VARCHAR(255) NOT NULL,
  16. name VARCHAR(255) NOT NULL,
  17. value TEXT
  18. )";
  19. $db->execute($settingsTableSQL);
  20. echo " Settings table checked/created\n";
  21. // Create index for settings table
  22. $settingsIndexSQL = "CREATE INDEX IF NOT EXISTS idx_settings_grupa_name ON settings(grupa, name)";
  23. $db->execute($settingsIndexSQL);
  24. echo " Settings table index checked/created\n";
  25. // Migration: Create pages table
  26. $pagesTableSQL = "
  27. CREATE TABLE IF NOT EXISTS pages (
  28. id INTEGER PRIMARY KEY AUTOINCREMENT,
  29. name VARCHAR(255) NOT NULL,
  30. slug VARCHAR(255) UNIQUE NOT NULL,
  31. title VARCHAR(255),
  32. content TEXT,
  33. extra_fields JSON,
  34. layout VARCHAR(255) DEFAULT 'default',
  35. is_homepage BOOLEAN DEFAULT 0,
  36. created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
  37. updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
  38. )";
  39. $db->execute($pagesTableSQL);
  40. echo " Pages table checked/created\n";
  41. // Create index for pages table
  42. $pagesIndexSQL = "CREATE INDEX IF NOT EXISTS idx_pages_slug ON pages(slug)";
  43. $db->execute($pagesIndexSQL);
  44. echo " Pages table index checked/created\n";
  45. // Insert default settings if they don't exist
  46. $defaultSettings = [
  47. // Content settings
  48. ['grupa' => 'content', 'name' => 'title', 'value' => 'Welcome to Amazing Casino - Your Ultimate Gaming Destination'],
  49. ['grupa' => 'content', 'name' => 'top_text', 'value' => '<h2>Best Online Casino Experience</h2><p>Discover the most exciting online casino games with amazing bonuses and instant payouts!</p>'],
  50. ['grupa' => 'content', 'name' => 'bottom_text', 'value' => '<p>Join thousands of players who trust our platform for secure gaming. Play responsibly and enjoy the thrill of winning big!</p>'],
  51. ['grupa' => 'content', 'name' => 'author-name', 'value' => 'John Smith'],
  52. ['grupa' => 'content', 'name' => 'modified-date', 'value' => '2024-01-15'],
  53. ['grupa' => 'content', 'name' => 'login', 'value' => 'Login Now'],
  54. ['grupa' => 'content', 'name' => 'password', 'value' => 'Reset Password'],
  55. ['grupa' => 'content', 'name' => 'faq-title', 'value' => 'Frequently Asked Questions'],
  56. ['grupa' => 'content', 'name' => 'footer__text', 'value' => 'Your trusted casino partner since 2020. Licensed and regulated for your safety.'],
  57. ['grupa' => 'content', 'name' => 'copyright', 'value' => '© 2024 Amazing Casino. All rights reserved.'],
  58. ['grupa' => 'content', 'name' => 'contact-menu-name', 'value' => 'Contacts'],
  59. ['grupa' => 'content', 'name' => 'review-count', 'value' => '1250'],
  60. ['grupa' => 'content', 'name' => 'listing', 'value' => 'Top Rated Casinos'],
  61. ['grupa' => 'content', 'name' => 'content_btn', 'value' => 'Play Now'],
  62. ['grupa' => 'content', 'name' => 'hide-btns', 'value' => '0'],
  63. ['grupa' => 'content', 'name' => 'header-logo', 'value' => '{"src":"uploads/logo.png","title":"Amazing Casino Logo","alt":"Amazing Casino - Best Online Gaming"}'],
  64. ['grupa' => 'content', 'name' => 'banner-logo', 'value' => '{"src":"uploads/banner.jpg","title":"Welcome Bonus Banner","alt":"Get 200% Welcome Bonus","width":"800","height":"400"}'],
  65. ['grupa' => 'content', 'name' => 'footer-logo', 'value' => '{"src":"uploads/footer-logo.png","title":"Footer Logo","alt":"Amazing Casino Footer"}'],
  66. ['grupa' => 'content', 'name' => 'favicon', 'value' => 'uploads/favicon.ico'],
  67. ['grupa' => 'content', 'name' => 'author-img', 'value' => 'uploads/author.jpg'],
  68. ['grupa' => 'content', 'name' => 'hash', 'value' => 'ac123main'],
  69. ['grupa' => 'content', 'name' => 'hash-1', 'value' => 'ac123promo'],
  70. ['grupa' => 'content', 'name' => 'hash-2', 'value' => 'ac123bonus'],
  71. ['grupa' => 'content', 'name' => 'hash-3', 'value' => 'ac123games'],
  72. ['grupa' => 'content', 'name' => 'hash-4', 'value' => 'ac123vip'],
  73. ['grupa' => 'content', 'name' => 'hash-5', 'value' => 'ac123support'],
  74. ['grupa' => 'content', 'name' => 'casino_list', 'value' => '[{"heading":"Royal Casino","text":"200% Welcome Bonus + 50 Free Spins","button":"Claim Bonus","rating":"10"},{"heading":"Golden Palace","text":"100% Match Bonus up to $500","button":"Play Now","rating":"9.5"},{"heading":"Diamond Club","text":"$1000 Welcome Package + VIP Treatment","button":"Join VIP","rating":"9"}]'],
  75. ['grupa' => 'content', 'name' => 'faq', 'value' => '[{"question":"How do I create an account?","answer":"Click the Register button and fill in your details. Verification usually takes 5-10 minutes."},{"question":"What payment methods do you accept?","answer":"We accept credit cards, e-wallets, bank transfers, and cryptocurrencies."},{"question":"How long do withdrawals take?","answer":"Most withdrawals are processed within 24 hours."}]'],
  76. ['grupa' => 'content', 'name' => 'menu', 'value' => '[{"title":"Home","anchor":"#home"},{"title":"Games","anchor":"#games"},{"title":"Bonuses","anchor":"#bonuses"},{"title":"Reviews","anchor":"#reviews"},{"title":"Contact","anchor":"#contact"}]'],
  77. // Style settings
  78. ['grupa' => 'styles', 'name' => 'main_color', 'value' => '#1a1a2e'],
  79. ['grupa' => 'styles', 'name' => 'secondary_color', 'value' => '#16213e'],
  80. ['grupa' => 'styles', 'name' => 'accent_color', 'value' => '#e94560'],
  81. ['grupa' => 'styles', 'name' => 'font_color', 'value' => '#ffffff'],
  82. ['grupa' => 'styles', 'name' => 'hover_link_color', 'value' => '#f39c12'],
  83. ['grupa' => 'styles', 'name' => 'main-fz', 'value' => 'Arial, sans-serif'],
  84. ['grupa' => 'styles', 'name' => 'footer_color', 'value' => '#0f0f23'],
  85. ['grupa' => 'styles', 'name' => 'link_color', 'value' => '#3498db'],
  86. ['grupa' => 'styles', 'name' => 'header_color', 'value' => '#2c2c54'],
  87. ['grupa' => 'styles', 'name' => 'login_btn_color', 'value' => '#27ae60'],
  88. ['grupa' => 'styles', 'name' => 'pass_btn_color', 'value' => '#e74c3c'],
  89. ['grupa' => 'styles', 'name' => 'table', 'value' => '#ecf0f1'],
  90. ['grupa' => 'styles', 'name' => 'caption', 'value' => '#bdc3c7'],
  91. ['grupa' => 'styles', 'name' => 'faq-title-font-color', 'value' => '#2c3e50'],
  92. ['grupa' => 'styles', 'name' => 'faq-title-hover-font-color', 'value' => '#e94560'],
  93. ['grupa' => 'styles', 'name' => 'burger-color', 'value' => '#ffffff'],
  94. ['grupa' => 'styles', 'name' => 'burger-color2', 'value' => '#ffffff'],
  95. // SEO settings
  96. ['grupa' => 'seo', 'name' => 'title', 'value' => 'Amazing Casino - Best Online Gaming Experience 2024'],
  97. ['grupa' => 'seo', 'name' => 'description', 'value' => 'Join Amazing Casino for the ultimate online gaming experience. Enjoy 200+ games, generous bonuses, and secure payments. Licensed and trusted worldwide.'],
  98. ['grupa' => 'seo', 'name' => 'keywords', 'value' => 'online casino, casino games, slots, blackjack, poker, roulette, bonuses, secure gaming'],
  99. ['grupa' => 'seo', 'name' => 'canonical', 'value' => 'https://amazing-casino.com'],
  100. ['grupa' => 'seo', 'name' => 'og-type', 'value' => 'website'],
  101. ['grupa' => 'seo', 'name' => 'og-title', 'value' => 'Amazing Casino - Win Big with Our Casino Games'],
  102. ['grupa' => 'seo', 'name' => 'og-description', 'value' => 'Experience the thrill of premium casino games with Amazing Casino. Get your 200% welcome bonus today!'],
  103. ['grupa' => 'seo', 'name' => 'og-locale', 'value' => 'en_US'],
  104. ['grupa' => 'seo', 'name' => 'og-image', 'value' => 'uploads/og-image.jpg'],
  105. ['grupa' => 'seo', 'name' => 'lang', 'value' => 'en'],
  106. ['grupa' => 'seo', 'name' => 'lang-page', 'value' => 'en-US'],
  107. ['grupa' => 'seo', 'name' => 'hreflang', 'value' => '[{"hreflang":"en","href":"https://amazing-casino.com/en/"},{"hreflang":"es","href":"https://amazing-casino.com/es/"},{"hreflang":"fr","href":"https://amazing-casino.com/fr/"},{"hreflang":"x-default","href":"https://amazing-casino.com/"}]'],
  108. ];
  109. foreach ($defaultSettings as $setting) {
  110. $exists = $db->fetchOne(
  111. "SELECT id FROM settings WHERE grupa = ? AND name = ?",
  112. [$setting['grupa'], $setting['name']]
  113. );
  114. if (!$exists) {
  115. $db->execute(
  116. "INSERT INTO settings (grupa, name, value) VALUES (?, ?, ?)",
  117. [$setting['grupa'], $setting['name'], $setting['value']]
  118. );
  119. echo "✓ Default setting {$setting['grupa']}.{$setting['name']} created\n";
  120. }
  121. }
  122. // Migration: Create seo_metas table
  123. $seoMetasTableSQL = "
  124. CREATE TABLE IF NOT EXISTS seo_metas (
  125. id INTEGER PRIMARY KEY AUTOINCREMENT,
  126. seoable_type VARCHAR(255) NOT NULL,
  127. seoable_id INTEGER NOT NULL,
  128. title VARCHAR(255) NULL,
  129. description TEXT NULL,
  130. keywords TEXT NULL,
  131. canonical VARCHAR(255) NULL,
  132. image VARCHAR(255) NULL,
  133. extra_fields JSON NULL,
  134. created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
  135. updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
  136. )";
  137. $db->execute($seoMetasTableSQL);
  138. echo "✓ SEO Metas table checked/created\n";
  139. // Create index for seo_metas table
  140. $seoMetasIndexSQL = "CREATE INDEX IF NOT EXISTS idx_seo_metas_seoable ON seo_metas(seoable_type, seoable_id)";
  141. $db->execute($seoMetasIndexSQL);
  142. echo "✓ SEO Metas table index checked/created\n";
  143. echo "Migration completed successfully!\n";
  144. } catch (Exception $e) {
  145. echo " Migration failed: " . $e->getMessage() . "\n";
  146. exit(1);
  147. }