exec(""" CREATE TABLE IF NOT EXISTS communities ( id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255) NOT NULL ) """); // Create members table $pdo->exec(""" CREATE TABLE IF NOT EXISTS members ( id INT AUTO_INCREMENT PRIMARY KEY, community_id INT NOT NULL, name VARCHAR(255) NOT NULL, email VARCHAR(255) NOT NULL, join_date DATE NOT NULL, FOREIGN KEY (community_id) REFERENCES communities(id) ) """); // Create classes table $pdo->exec(""" CREATE TABLE IF NOT EXISTS classes ( id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255) NOT NULL, instructor VARCHAR(255) NOT NULL ) """); // Create attendance table $pdo->exec(""" CREATE TABLE IF NOT EXISTS attendance ( id INT AUTO_INCREMENT PRIMARY KEY, member_id INT NOT NULL, class_id INT NOT NULL, attendance_date DATE NOT NULL, FOREIGN KEY (member_id) REFERENCES members(id), FOREIGN KEY (class_id) REFERENCES classes(id) ) """); // Create revenue table $pdo->exec(""" CREATE TABLE IF NOT EXISTS revenue ( id INT AUTO_INCREMENT PRIMARY KEY, member_id INT NOT NULL, amount DECIMAL(10, 2) NOT NULL, service_category VARCHAR(255) NOT NULL, transaction_date DATE NOT NULL, FOREIGN KEY (member_id) REFERENCES members(id) ) """); // Seed data $stmt = $pdo->query("SELECT COUNT(*) FROM communities"); if ($stmt->fetchColumn() == 0) { // Seed communities $communities = ['Valencia Sound', 'Valencia Reserve', 'Valencia Cove']; $stmt = $pdo->prepare("INSERT INTO communities (name) VALUES (?)"); foreach ($communities as $community) { $stmt->execute([$community]); } // Seed members $members = [ [1, 'John Doe', 'john.doe@email.com', '2025-01-15'], [1, 'Jane Smith', 'jane.smith@email.com', '2025-02-20'], [2, 'Peter Jones', 'peter.jones@email.com', '2025-03-10'], [2, 'Mary Johnson', 'mary.johnson@email.com', '2025-04-05'], [3, 'David Williams', 'david.williams@email.com', '2025-05-12'], [3, 'Susan Brown', 'susan.brown@email.com', '2025-06-18'], ]; $stmt = $pdo->prepare("INSERT INTO members (community_id, name, email, join_date) VALUES (?, ?, ?, ?)"); foreach ($members as $member) { $stmt->execute($member); } // Seed classes $classes = ['Yoga', 'Pilates', 'Zumba', 'Spin']; $stmt = $pdo->prepare("INSERT INTO classes (name, instructor) VALUES (?, ?)"); foreach ($classes as $class) { $stmt->execute([$class, 'Instructor ' . rand(1, 3)]); } // Seed attendance for ($i = 1; $i <= 500; $i++) { $member_id = rand(1, 6); $class_id = rand(1, 4); $date = date('Y-m-d', strtotime('-' . rand(0, 180) . ' days')); $pdo->prepare("INSERT INTO attendance (member_id, class_id, attendance_date) VALUES (?, ?, ?)")->execute([$member_id, $class_id, $date]); } // Seed revenue $service_categories = ['Group', 'PT', 'Massage', 'Events']; for ($i = 1; $i <= 200; $i++) { $member_id = rand(1, 6); $amount = rand(20, 200); $service_category = $service_categories[rand(0, 3)]; $date = date('Y-m-d', strtotime('-' . rand(0, 180) . ' days')); $pdo->prepare("INSERT INTO revenue (member_id, amount, service_category, transaction_date) VALUES (?, ?, ?, ?)")->execute([$member_id, $amount, $service_category, $date]); } } } setup_database(); echo "Database setup complete.";