migrate.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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. // Create database directory and file if they don't exist
  10. $dbPath = \Config::PATH['root'] . '/database/database.db';
  11. $dbDir = dirname($dbPath);
  12. if (!is_dir($dbDir)) {
  13. mkdir($dbDir, 0755, true);
  14. echo "✓ Created database directory\n";
  15. }
  16. if (!file_exists($dbPath)) {
  17. touch($dbPath);
  18. echo "✓ Created database file\n";
  19. }
  20. $db = db();
  21. echo "Starting database migration...\n";
  22. // Migration: Create settings table
  23. $settingsTableSQL = "
  24. CREATE TABLE IF NOT EXISTS settings (
  25. id INTEGER PRIMARY KEY AUTOINCREMENT,
  26. grupa VARCHAR(255) NOT NULL,
  27. name VARCHAR(255) NOT NULL,
  28. value TEXT
  29. )";
  30. $db->execute($settingsTableSQL);
  31. echo " Settings table checked/created\n";
  32. // Create index for settings table
  33. $settingsIndexSQL = "CREATE INDEX IF NOT EXISTS idx_settings_grupa_name ON settings(grupa, name)";
  34. $db->execute($settingsIndexSQL);
  35. echo " Settings table index checked/created\n";
  36. // Migration: Create pages table
  37. $pagesTableSQL = "
  38. CREATE TABLE IF NOT EXISTS pages (
  39. id INTEGER PRIMARY KEY AUTOINCREMENT,
  40. name VARCHAR(255) NOT NULL,
  41. slug VARCHAR(255) UNIQUE NOT NULL,
  42. title VARCHAR(255),
  43. content TEXT,
  44. extra_fields JSON,
  45. layout VARCHAR(255) DEFAULT 'default',
  46. is_homepage BOOLEAN DEFAULT 0,
  47. created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
  48. updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
  49. )";
  50. $db->execute($pagesTableSQL);
  51. echo " Pages table checked/created\n";
  52. // Create index for pages table
  53. $pagesIndexSQL = "CREATE INDEX IF NOT EXISTS idx_pages_slug ON pages(slug)";
  54. $db->execute($pagesIndexSQL);
  55. echo " Pages table index checked/created\n";
  56. // Insert default settings if they don't exist
  57. $defaultSettings = [
  58. // Content settings
  59. ['grupa' => 'content', 'name' => 'title', 'value' => 'Welcome to Amazing Casino - Your Ultimate Gaming Destination'],
  60. ['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>'],
  61. ['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>'],
  62. ['grupa' => 'content', 'name' => 'author-name', 'value' => 'John Smith'],
  63. ['grupa' => 'content', 'name' => 'modified-date', 'value' => '2024-01-15'],
  64. ['grupa' => 'content', 'name' => 'login', 'value' => 'Login Now'],
  65. ['grupa' => 'content', 'name' => 'password', 'value' => 'Reset Password'],
  66. ['grupa' => 'content', 'name' => 'faq-title', 'value' => 'Frequently Asked Questions'],
  67. ['grupa' => 'content', 'name' => 'footer__text', 'value' => 'Your trusted casino partner since 2020. Licensed and regulated for your safety.'],
  68. ['grupa' => 'content', 'name' => 'copyright', 'value' => '© 2024 Amazing Casino. All rights reserved.'],
  69. ['grupa' => 'content', 'name' => 'contact-menu-name', 'value' => 'Contacts'],
  70. ['grupa' => 'content', 'name' => 'review-count', 'value' => '1250'],
  71. ['grupa' => 'content', 'name' => 'listing', 'value' => 'Top Rated Casinos'],
  72. ['grupa' => 'content', 'name' => 'content_btn', 'value' => 'Play Now'],
  73. ['grupa' => 'content', 'name' => 'hide-btns', 'value' => '0'],
  74. ['grupa' => 'content', 'name' => 'header-logo', 'value' => '{"src":"media/logo.png","title":"Amazing Casino Logo","alt":"Amazing Casino - Best Online Gaming"}'],
  75. ['grupa' => 'content', 'name' => 'banner-logo', 'value' => '{"src":"media/banner.jpg","title":"Welcome Bonus Banner","alt":"Get 200% Welcome Bonus","width":"800","height":"400"}'],
  76. ['grupa' => 'content', 'name' => 'footer-logo', 'value' => '{"src":"media/footer-logo.png","title":"Footer Logo","alt":"Amazing Casino Footer"}'],
  77. ['grupa' => 'content', 'name' => 'favicon', 'value' => 'media/favicon.ico'],
  78. ['grupa' => 'content', 'name' => 'author-img', 'value' => 'media/author.jpg'],
  79. ['grupa' => 'content', 'name' => 'hash', 'value' => 'ac123main'],
  80. ['grupa' => 'content', 'name' => 'hash-1', 'value' => 'ac123promo'],
  81. ['grupa' => 'content', 'name' => 'hash-2', 'value' => 'ac123bonus'],
  82. ['grupa' => 'content', 'name' => 'hash-3', 'value' => 'ac123games'],
  83. ['grupa' => 'content', 'name' => 'hash-4', 'value' => 'ac123vip'],
  84. ['grupa' => 'content', 'name' => 'hash-5', 'value' => 'ac123support'],
  85. ['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"}]'],
  86. ['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."}]'],
  87. ['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"}]'],
  88. // Style settings
  89. ['grupa' => 'styles', 'name' => 'header_color', 'value' => '#ED0039'],
  90. ['grupa' => 'styles', 'name' => 'body_bg_color', 'value' => '#FFF'],
  91. ['grupa' => 'styles', 'name' => 'content_bg_color', 'value' => '#F6F6F6'],
  92. ['grupa' => 'styles', 'name' => 'text_color', 'value' => '#000'],
  93. ['grupa' => 'styles', 'name' => 'link_color', 'value' => '#ED0039'],
  94. ['grupa' => 'styles', 'name' => 'accent_color', 'value' => '#ED0039'],
  95. ['grupa' => 'styles', 'name' => 'content_border_color', 'value' => '#E4E4E4'],
  96. ['grupa' => 'styles', 'name' => 'table_bg_color', 'value' => '#fff'],
  97. ['grupa' => 'styles', 'name' => 'table_header_color', 'value' => '#FFF'],
  98. ['grupa' => 'styles', 'name' => 'footer_bg_color', 'value' => '#000'],
  99. // SEO settings
  100. ['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/"}]'],
  101. ];
  102. foreach ($defaultSettings as $setting) {
  103. $exists = $db->fetchOne(
  104. "SELECT id FROM settings WHERE grupa = ? AND name = ?",
  105. [$setting['grupa'], $setting['name']]
  106. );
  107. if (!$exists) {
  108. $db->execute(
  109. "INSERT INTO settings (grupa, name, value) VALUES (?, ?, ?)",
  110. [$setting['grupa'], $setting['name'], $setting['value']]
  111. );
  112. echo "✓ Default setting {$setting['grupa']}.{$setting['name']} created\n";
  113. }
  114. }
  115. // Migration: Create seo_metas table
  116. $seoMetasTableSQL = "
  117. CREATE TABLE IF NOT EXISTS seo_metas (
  118. id INTEGER PRIMARY KEY AUTOINCREMENT,
  119. seoable_type VARCHAR(255) NOT NULL,
  120. seoable_id INTEGER NOT NULL,
  121. title VARCHAR(255) NULL,
  122. description TEXT NULL,
  123. keywords TEXT NULL,
  124. canonical VARCHAR(255) NULL,
  125. image VARCHAR(255) NULL,
  126. extra_fields JSON NULL,
  127. created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
  128. updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
  129. )";
  130. $db->execute($seoMetasTableSQL);
  131. echo "✓ SEO Metas table checked/created\n";
  132. // Create index for seo_metas table
  133. $seoMetasIndexSQL = "CREATE INDEX IF NOT EXISTS idx_seo_metas_seoable ON seo_metas(seoable_type, seoable_id)";
  134. $db->execute($seoMetasIndexSQL);
  135. echo "✓ SEO Metas table index checked/created\n";
  136. // Migration: Create faqs table
  137. $faqsTableSQL = "
  138. CREATE TABLE IF NOT EXISTS faqs (
  139. id INTEGER PRIMARY KEY AUTOINCREMENT,
  140. faqable_type VARCHAR(255) NOT NULL,
  141. faqable_id INTEGER NOT NULL,
  142. title VARCHAR(255) NULL,
  143. extra_fields JSON NULL,
  144. created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
  145. updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
  146. )";
  147. $db->execute($faqsTableSQL);
  148. echo "✓ FAQs table checked/created\n";
  149. // Create indexes for faqs
  150. $faqsIndexSQL = "CREATE INDEX IF NOT EXISTS idx_faqs_faqable ON faqs(faqable_type, faqable_id)";
  151. $db->execute($faqsIndexSQL);
  152. echo "✓ FAQs table index checked/created\n";
  153. // Migration: Create slots table
  154. $slotsTableSQL = "
  155. CREATE TABLE IF NOT EXISTS slots (
  156. id INTEGER PRIMARY KEY AUTOINCREMENT,
  157. name VARCHAR(255) NOT NULL,
  158. image VARCHAR(255) NULL,
  159. provider VARCHAR(255) NULL,
  160. rtp DECIMAL(5,2) NULL,
  161. demo_url VARCHAR(500) NULL,
  162. created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
  163. updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
  164. )";
  165. $db->execute($slotsTableSQL);
  166. echo "✓ Slots table checked/created\n";
  167. // Create indexes for slots
  168. $slotsNameIndexSQL = "CREATE INDEX IF NOT EXISTS idx_slots_name ON slots(name)";
  169. $db->execute($slotsNameIndexSQL);
  170. $slotsProviderIndexSQL = "CREATE INDEX IF NOT EXISTS idx_slots_provider ON slots(provider)";
  171. $db->execute($slotsProviderIndexSQL);
  172. echo "✓ Slots table indexes checked/created\n";
  173. // Migration: Create authors table
  174. $authorsTableSQL = "
  175. CREATE TABLE IF NOT EXISTS authors (
  176. id INTEGER PRIMARY KEY AUTOINCREMENT,
  177. name VARCHAR(255) NOT NULL,
  178. image VARCHAR(255) NULL,
  179. description TEXT NULL,
  180. social_links JSON NULL,
  181. created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
  182. updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
  183. )";
  184. $db->execute($authorsTableSQL);
  185. echo "✓ Authors table checked/created\n";
  186. // Create index for authors
  187. $authorsNameIndexSQL = "CREATE INDEX IF NOT EXISTS idx_authors_name ON authors(name)";
  188. $db->execute($authorsNameIndexSQL);
  189. echo "✓ Authors table index checked/created\n";
  190. echo "Migration completed successfully!\n";
  191. } catch (Exception $e) {
  192. echo " Migration failed: " . $e->getMessage() . "\n";
  193. exit(1);
  194. }