RealBlocks / server /src /database /migrations /001_initial.ts
incognitolm's picture
Initial
ce2d6ca verified
Raw
History Blame Contribute Delete
1.53 kB
import { getDatabase } from '../index';
export function runMigration(): void {
const db = getDatabase();
db.exec(`
CREATE TABLE IF NOT EXISTS users (
id TEXT PRIMARY KEY,
email TEXT UNIQUE NOT NULL,
username TEXT UNIQUE NOT NULL,
password_hash TEXT NOT NULL,
verified INTEGER DEFAULT 0,
verification_token TEXT,
reset_token TEXT,
reset_token_expires INTEGER,
created_at INTEGER NOT NULL,
updated_at INTEGER NOT NULL
);
CREATE TABLE IF NOT EXISTS projects (
id TEXT PRIMARY KEY,
user_id TEXT NOT NULL,
name TEXT NOT NULL,
framework TEXT NOT NULL,
description TEXT,
encrypted_data TEXT NOT NULL,
encryption_iv TEXT NOT NULL,
created_at INTEGER NOT NULL,
updated_at INTEGER NOT NULL,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS sessions (
id TEXT PRIMARY KEY,
user_id TEXT NOT NULL,
token TEXT UNIQUE NOT NULL,
expires_at INTEGER NOT NULL,
created_at INTEGER NOT NULL,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
);
CREATE INDEX IF NOT EXISTS idx_projects_user_id ON projects(user_id);
CREATE INDEX IF NOT EXISTS idx_sessions_token ON sessions(token);
CREATE INDEX IF NOT EXISTS idx_sessions_user_id ON sessions(user_id);
`);
console.log('Migration 001_initial completed successfully');
}
if (require.main === module) {
runMigration();
process.exit(0);
}