Guest User

initial_starter.sql

a guest
Feb 18th, 2025
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.93 KB | None | 0 0
  1. -- Users table: stores user credentials and account information
  2. CREATE TABLE IF NOT EXISTS users (
  3. id INT AUTO_INCREMENT PRIMARY KEY,
  4. username VARCHAR(50) NOT NULL UNIQUE,
  5. email VARCHAR(100) NOT NULL UNIQUE,
  6. password VARCHAR(255) NOT NULL,
  7. balance DECIMAL(12,2) NOT NULL DEFAULT 0,
  8. referral_code VARCHAR(20),
  9. is_admin TINYINT(1) DEFAULT 0,
  10. created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
  11. updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
  12. ) ENGINE=InnoDB;
  13.  
  14. -- Game Sessions table: logs each game played (case battles, slots, mines, coinflip, roulette, cases)
  15. CREATE TABLE IF NOT EXISTS game_sessions (
  16. id INT AUTO_INCREMENT PRIMARY KEY,
  17. user_id INT NOT NULL,
  18. game_type ENUM('case_battle', 'slot', 'mine', 'coinflip', 'roulette', 'case') NOT NULL,
  19. bet_amount DECIMAL(12,2) NOT NULL,
  20. win_amount DECIMAL(12,2) DEFAULT 0,
  21. outcome VARCHAR(50),
  22. game_data JSON, -- additional game-specific information
  23. client_seed VARCHAR(255),
  24. server_seed VARCHAR(255),
  25. nonce INT,
  26. created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
  27. FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
  28. ) ENGINE=InnoDB;
  29.  
  30. -- Transactions table: records deposits, withdrawals, bonuses, and adjustments
  31. CREATE TABLE IF NOT EXISTS transactions (
  32. id INT AUTO_INCREMENT PRIMARY KEY,
  33. user_id INT NOT NULL,
  34. transaction_type ENUM('deposit', 'withdrawal', 'bonus', 'adjustment') NOT NULL,
  35. amount DECIMAL(12,2) NOT NULL,
  36. status ENUM('pending', 'completed', 'failed') NOT NULL DEFAULT 'pending',
  37. reference VARCHAR(100),
  38. created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
  39. updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  40. FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
  41. ) ENGINE=InnoDB;
  42.  
  43. -- Chat Messages table: for the interactive chat system
  44. CREATE TABLE IF NOT EXISTS chat_messages (
  45. id INT AUTO_INCREMENT PRIMARY KEY,
  46. user_id INT NOT NULL,
  47. message TEXT NOT NULL,
  48. room VARCHAR(50) DEFAULT 'global',
  49. created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
  50. FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
  51. ) ENGINE=InnoDB;
  52.  
  53. -- Referrals table: links referrer and referred users and stores bonus information
  54. CREATE TABLE IF NOT EXISTS referrals (
  55. id INT AUTO_INCREMENT PRIMARY KEY,
  56. referrer_id INT NOT NULL,
  57. referred_id INT NOT NULL,
  58. bonus_awarded DECIMAL(12,2) DEFAULT 0,
  59. created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
  60. FOREIGN KEY (referrer_id) REFERENCES users(id) ON DELETE CASCADE,
  61. FOREIGN KEY (referred_id) REFERENCES users(id) ON DELETE CASCADE
  62. ) ENGINE=InnoDB;
  63.  
  64. -- Promo Codes table: manages promo codes and usage limits
  65. CREATE TABLE IF NOT EXISTS promo_codes (
  66. id INT AUTO_INCREMENT PRIMARY KEY,
  67. code VARCHAR(50) NOT NULL UNIQUE,
  68. description TEXT,
  69. discount_percentage DECIMAL(5,2) DEFAULT 0,
  70. max_usage INT DEFAULT 1,
  71. usage_count INT DEFAULT 0,
  72. valid_from DATETIME,
  73. valid_to DATETIME,
  74. created_at DATETIME DEFAULT CURRENT_TIMESTAMP
  75. ) ENGINE=InnoDB;
  76.  
  77. -- Competitions table: defines competitions or leaderboards with start/end times and prizes
  78. CREATE TABLE IF NOT EXISTS competitions (
  79. id INT AUTO_INCREMENT PRIMARY KEY,
  80. competition_name VARCHAR(100) NOT NULL,
  81. start_time DATETIME NOT NULL,
  82. end_time DATETIME NOT NULL,
  83. winner_id INT,
  84. prize DECIMAL(12,2),
  85. created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
  86. FOREIGN KEY (winner_id) REFERENCES users(id) ON DELETE SET NULL
  87. ) ENGINE=InnoDB;
  88.  
  89. -- Competition Entries table: records entries for competitions
  90. CREATE TABLE IF NOT EXISTS competition_entries (
  91. id INT AUTO_INCREMENT PRIMARY KEY,
  92. competition_id INT NOT NULL,
  93. user_id INT NOT NULL,
  94. score INT DEFAULT 0,
  95. created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
  96. FOREIGN KEY (competition_id) REFERENCES competitions(id) ON DELETE CASCADE,
  97. FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
  98. ) ENGINE=InnoDB;
  99.  
  100. -- Payments table: logs transactions made via payment gateways
  101. CREATE TABLE IF NOT EXISTS payments (
  102. id INT AUTO_INCREMENT PRIMARY KEY,
  103. user_id INT NOT NULL,
  104. payment_method VARCHAR(50),
  105. payment_reference VARCHAR(100),
  106. amount DECIMAL(12,2) NOT NULL,
  107. status ENUM('pending', 'completed', 'failed') DEFAULT 'pending',
  108. created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
  109. updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  110. FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
  111. ) ENGINE=InnoDB;
  112.  
  113. -- Admin Actions table: logs administrative actions for audit purposes
  114. CREATE TABLE IF NOT EXISTS admin_actions (
  115. id INT AUTO_INCREMENT PRIMARY KEY,
  116. admin_user_id INT NOT NULL,
  117. action_type VARCHAR(50) NOT NULL,
  118. description TEXT,
  119. created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
  120. FOREIGN KEY (admin_user_id) REFERENCES users(id) ON DELETE CASCADE
  121. ) ENGINE=InnoDB;
  122.  
Add Comment
Please, Sign In to add comment