mirror of
https://github.com/mudabbir-ahmad/peworkshop.git
synced 2026-10-07 19:50:20 +00:00
34 lines
834 B
JavaScript
34 lines
834 B
JavaScript
import { run } from "./db.js";
|
|
|
|
async function initializeDatabase() {
|
|
try {
|
|
// Create users table
|
|
await run(`
|
|
CREATE TABLE IF NOT EXISTS users (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
username TEXT UNIQUE NOT NULL,
|
|
password TEXT NOT NULL,
|
|
role TEXT DEFAULT 'user',
|
|
team_id INTEGER,
|
|
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
)
|
|
`);
|
|
|
|
// Create teams table
|
|
await run(`
|
|
CREATE TABLE IF NOT EXISTS teams (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
name TEXT NOT NULL,
|
|
code TEXT UNIQUE NOT NULL,
|
|
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
)
|
|
`);
|
|
|
|
console.log("Database initialized successfully");
|
|
} catch (error) {
|
|
console.error("Database initialization error:", error);
|
|
}
|
|
}
|
|
|
|
initializeDatabase();
|