migrate.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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' => 'main_color', 'value' => '#1a1a2e'],
  90. ['grupa' => 'styles', 'name' => 'secondary_color', 'value' => '#16213e'],
  91. ['grupa' => 'styles', 'name' => 'accent_color', 'value' => '#e94560'],
  92. ['grupa' => 'styles', 'name' => 'font_color', 'value' => '#ffffff'],
  93. ['grupa' => 'styles', 'name' => 'hover_link_color', 'value' => '#f39c12'],
  94. ['grupa' => 'styles', 'name' => 'main-fz', 'value' => 'Arial, sans-serif'],
  95. ['grupa' => 'styles', 'name' => 'footer_color', 'value' => '#0f0f23'],
  96. ['grupa' => 'styles', 'name' => 'link_color', 'value' => '#3498db'],
  97. ['grupa' => 'styles', 'name' => 'header_color', 'value' => '#2c2c54'],
  98. ['grupa' => 'styles', 'name' => 'login_btn_color', 'value' => '#27ae60'],
  99. ['grupa' => 'styles', 'name' => 'pass_btn_color', 'value' => '#e74c3c'],
  100. ['grupa' => 'styles', 'name' => 'table', 'value' => '#ecf0f1'],
  101. ['grupa' => 'styles', 'name' => 'caption', 'value' => '#bdc3c7'],
  102. ['grupa' => 'styles', 'name' => 'faq-title-font-color', 'value' => '#2c3e50'],
  103. ['grupa' => 'styles', 'name' => 'faq-title-hover-font-color', 'value' => '#e94560'],
  104. ['grupa' => 'styles', 'name' => 'burger-color', 'value' => '#ffffff'],
  105. ['grupa' => 'styles', 'name' => 'burger-color2', 'value' => '#ffffff'],
  106. // SEO settings
  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. // Migration: Create faqs table
  144. $faqsTableSQL = "
  145. CREATE TABLE IF NOT EXISTS faqs (
  146. id INTEGER PRIMARY KEY AUTOINCREMENT,
  147. faqable_type VARCHAR(255) NOT NULL,
  148. faqable_id INTEGER NOT NULL,
  149. title VARCHAR(255) NULL,
  150. extra_fields JSON NULL,
  151. created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
  152. updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
  153. )";
  154. $db->execute($faqsTableSQL);
  155. echo "✓ FAQs table checked/created\n";
  156. // Create indexes for faqs
  157. $faqsIndexSQL = "CREATE INDEX IF NOT EXISTS idx_faqs_faqable ON faqs(faqable_type, faqable_id)";
  158. $db->execute($faqsIndexSQL);
  159. echo "✓ FAQs table index checked/created\n";
  160. // Migration: Create slots table
  161. $slotsTableSQL = "
  162. CREATE TABLE IF NOT EXISTS slots (
  163. id INTEGER PRIMARY KEY AUTOINCREMENT,
  164. name VARCHAR(255) NOT NULL,
  165. image VARCHAR(255) NULL,
  166. provider VARCHAR(255) NULL,
  167. rtp DECIMAL(5,2) NULL,
  168. demo_url VARCHAR(500) NULL,
  169. created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
  170. updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
  171. )";
  172. $db->execute($slotsTableSQL);
  173. echo "✓ Slots table checked/created\n";
  174. // Create indexes for slots
  175. $slotsNameIndexSQL = "CREATE INDEX IF NOT EXISTS idx_slots_name ON slots(name)";
  176. $db->execute($slotsNameIndexSQL);
  177. $slotsProviderIndexSQL = "CREATE INDEX IF NOT EXISTS idx_slots_provider ON slots(provider)";
  178. $db->execute($slotsProviderIndexSQL);
  179. echo "✓ Slots table indexes checked/created\n";
  180. // Migration: Create authors table
  181. $authorsTableSQL = "
  182. CREATE TABLE IF NOT EXISTS authors (
  183. id INTEGER PRIMARY KEY AUTOINCREMENT,
  184. name VARCHAR(255) NOT NULL,
  185. image VARCHAR(255) NULL,
  186. description TEXT NULL,
  187. social_links JSON NULL,
  188. created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
  189. updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
  190. )";
  191. $db->execute($authorsTableSQL);
  192. echo "✓ Authors table checked/created\n";
  193. // Create index for authors
  194. $authorsNameIndexSQL = "CREATE INDEX IF NOT EXISTS idx_authors_name ON authors(name)";
  195. $db->execute($authorsNameIndexSQL);
  196. echo "✓ Authors table index checked/created\n";
  197. echo "Migration completed successfully!\n";
  198. } catch (Exception $e) {
  199. echo " Migration failed: " . $e->getMessage() . "\n";
  200. exit(1);
  201. }