migrate.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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' => 'title', 'value' => 'Amazing Casino - Best Online Gaming Experience 2024'],
  108. ['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.'],
  109. ['grupa' => 'seo', 'name' => 'keywords', 'value' => 'online casino, casino games, slots, blackjack, poker, roulette, bonuses, secure gaming'],
  110. ['grupa' => 'seo', 'name' => 'canonical', 'value' => 'https://amazing-casino.com'],
  111. ['grupa' => 'seo', 'name' => 'og-type', 'value' => 'website'],
  112. ['grupa' => 'seo', 'name' => 'og-title', 'value' => 'Amazing Casino - Win Big with Our Casino Games'],
  113. ['grupa' => 'seo', 'name' => 'og-description', 'value' => 'Experience the thrill of premium casino games with Amazing Casino. Get your 200% welcome bonus today!'],
  114. ['grupa' => 'seo', 'name' => 'og-locale', 'value' => 'en_US'],
  115. ['grupa' => 'seo', 'name' => 'og-image', 'value' => 'media/og-image.jpg'],
  116. ['grupa' => 'seo', 'name' => 'lang', 'value' => 'en'],
  117. ['grupa' => 'seo', 'name' => 'lang-page', 'value' => 'en-US'],
  118. ['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/"}]'],
  119. ];
  120. foreach ($defaultSettings as $setting) {
  121. $exists = $db->fetchOne(
  122. "SELECT id FROM settings WHERE grupa = ? AND name = ?",
  123. [$setting['grupa'], $setting['name']]
  124. );
  125. if (!$exists) {
  126. $db->execute(
  127. "INSERT INTO settings (grupa, name, value) VALUES (?, ?, ?)",
  128. [$setting['grupa'], $setting['name'], $setting['value']]
  129. );
  130. echo "✓ Default setting {$setting['grupa']}.{$setting['name']} created\n";
  131. }
  132. }
  133. // Migration: Create seo_metas table
  134. $seoMetasTableSQL = "
  135. CREATE TABLE IF NOT EXISTS seo_metas (
  136. id INTEGER PRIMARY KEY AUTOINCREMENT,
  137. seoable_type VARCHAR(255) NOT NULL,
  138. seoable_id INTEGER NOT NULL,
  139. title VARCHAR(255) NULL,
  140. description TEXT NULL,
  141. keywords TEXT NULL,
  142. canonical VARCHAR(255) NULL,
  143. image VARCHAR(255) NULL,
  144. extra_fields JSON NULL,
  145. created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
  146. updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
  147. )";
  148. $db->execute($seoMetasTableSQL);
  149. echo "✓ SEO Metas table checked/created\n";
  150. // Create index for seo_metas table
  151. $seoMetasIndexSQL = "CREATE INDEX IF NOT EXISTS idx_seo_metas_seoable ON seo_metas(seoable_type, seoable_id)";
  152. $db->execute($seoMetasIndexSQL);
  153. echo "✓ SEO Metas table index checked/created\n";
  154. // Migration: Create faqs table
  155. $faqsTableSQL = "
  156. CREATE TABLE IF NOT EXISTS faqs (
  157. id INTEGER PRIMARY KEY AUTOINCREMENT,
  158. faqable_type VARCHAR(255) NOT NULL,
  159. faqable_id INTEGER NOT NULL,
  160. title VARCHAR(255) NULL,
  161. extra_fields JSON NULL,
  162. created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
  163. updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
  164. )";
  165. $db->execute($faqsTableSQL);
  166. echo "✓ FAQs table checked/created\n";
  167. // Create indexes for faqs
  168. $faqsIndexSQL = "CREATE INDEX IF NOT EXISTS idx_faqs_faqable ON faqs(faqable_type, faqable_id)";
  169. $db->execute($faqsIndexSQL);
  170. echo "✓ FAQs table index checked/created\n";
  171. // Migration: Create slots table
  172. $slotsTableSQL = "
  173. CREATE TABLE IF NOT EXISTS slots (
  174. id INTEGER PRIMARY KEY AUTOINCREMENT,
  175. name VARCHAR(255) NOT NULL,
  176. image VARCHAR(255) NULL,
  177. provider VARCHAR(255) NULL,
  178. rtp DECIMAL(5,2) NULL,
  179. demo_url VARCHAR(500) NULL,
  180. created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
  181. updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
  182. )";
  183. $db->execute($slotsTableSQL);
  184. echo "✓ Slots table checked/created\n";
  185. // Create indexes for slots
  186. $slotsNameIndexSQL = "CREATE INDEX IF NOT EXISTS idx_slots_name ON slots(name)";
  187. $db->execute($slotsNameIndexSQL);
  188. $slotsProviderIndexSQL = "CREATE INDEX IF NOT EXISTS idx_slots_provider ON slots(provider)";
  189. $db->execute($slotsProviderIndexSQL);
  190. echo "✓ Slots table indexes checked/created\n";
  191. // Migration: Create authors table
  192. $authorsTableSQL = "
  193. CREATE TABLE IF NOT EXISTS authors (
  194. id INTEGER PRIMARY KEY AUTOINCREMENT,
  195. name VARCHAR(255) NOT NULL,
  196. image VARCHAR(255) NULL,
  197. description TEXT NULL,
  198. social_links JSON NULL,
  199. created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
  200. updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
  201. )";
  202. $db->execute($authorsTableSQL);
  203. echo "✓ Authors table checked/created\n";
  204. // Create index for authors
  205. $authorsNameIndexSQL = "CREATE INDEX IF NOT EXISTS idx_authors_name ON authors(name)";
  206. $db->execute($authorsNameIndexSQL);
  207. echo "✓ Authors table index checked/created\n";
  208. echo "Migration completed successfully!\n";
  209. } catch (Exception $e) {
  210. echo " Migration failed: " . $e->getMessage() . "\n";
  211. exit(1);
  212. }