38 lines
1.6 KiB
PHP
38 lines
1.6 KiB
PHP
<?php
|
|
require_once __DIR__ . '/../config.php';
|
|
|
|
try {
|
|
$pdo = db();
|
|
|
|
// Create events table
|
|
$pdo->exec("CREATE TABLE IF NOT EXISTS events (
|
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
title VARCHAR(255) NOT NULL,
|
|
description TEXT,
|
|
event_date DATETIME NOT NULL,
|
|
location VARCHAR(255),
|
|
price DECIMAL(10, 2) DEFAULT 0.00,
|
|
status ENUM('pending', 'accepted', 'rejected') NOT NULL DEFAULT 'pending',
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
);");
|
|
|
|
// Check if table is empty before seeding
|
|
$stmt = $pdo->query("SELECT COUNT(*) FROM events");
|
|
if ($stmt->fetchColumn() == 0) {
|
|
// Seed data
|
|
$pdo->exec("INSERT INTO events (title, event_date, location, status, price) VALUES
|
|
('Community Tech Conference 2026', '2026-03-15 09:00:00', 'City Convention Center', 'accepted', 49.99),
|
|
('Local Music Festival', '2026-04-22 18:00:00', 'Downtown Park', 'accepted', 25.00),
|
|
('Art & Design Expo', '2026-05-10 11:00:00', 'Grand Exhibition Hall', 'pending', 15.00),
|
|
('Startup Pitch Night', '2026-05-20 19:00:00', 'Innovation Hub', 'accepted', 0.00),
|
|
('Health & Wellness Retreat', '2026-06-05 10:00:00', 'Serenity Resort', 'rejected', 350.00);
|
|
");
|
|
echo "Database table 'events' created and seeded successfully." . PHP_EOL;
|
|
} else {
|
|
echo "Database table 'events' already exists and contains data. Seeding skipped." . PHP_EOL;
|
|
}
|
|
|
|
} catch (PDOException $e) {
|
|
die("Database migration failed: " . $e->getMessage());
|
|
}
|