21 lines
667 B
TypeScript
21 lines
667 B
TypeScript
import db from './database';
|
|
|
|
/**
|
|
* Creates all required tables if they do not already exist.
|
|
* Safe to call on every startup — uses IF NOT EXISTS throughout.
|
|
*/
|
|
export function initDatabase(): void {
|
|
db.exec(`
|
|
CREATE TABLE IF NOT EXISTS projects (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
name TEXT NOT NULL,
|
|
description TEXT NOT NULL DEFAULT '',
|
|
project_json TEXT NOT NULL DEFAULT '{}',
|
|
created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')),
|
|
updated_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now'))
|
|
);
|
|
`);
|
|
|
|
console.log('Database initialised');
|
|
}
|