feat(db): add lightweight migration system
Introduce server-migrations.ts with a named-migration runner that tracks applied migrations in a _migrations table. runMigrations(db) is called at startup before routes, so additive schema changes (ALTER TABLE, new settings) are applied once and skipped on subsequent restarts. Update ARCHITECTURE.md: five inline edits + new §4.4 documenting the convention.
This commit is contained in:
@ -8,6 +8,7 @@ import jwt from 'jsonwebtoken';
|
||||
import DatabaseConstructor from 'better-sqlite3';
|
||||
import { ConfidentialClientApplication } from '@azure/msal-node';
|
||||
import db, { uid, addLog, getSetting, setSetting, getAllSettings, getCaddyRoutes, addCaddyRoute, updateCaddyRoute, deleteCaddyRoute, getCaddyRouteById, DB_FILE } from './server-db';
|
||||
import { runMigrations } from './server-migrations';
|
||||
import { Device, LabTemplate, Booking, LogEntry, User, QuickLink } from './src/types';
|
||||
|
||||
const JWT_SECRET = process.env.JWT_SECRET || 'ghostgrid-dev-secret-change-in-production';
|
||||
@ -164,6 +165,8 @@ async function pushCaddyConfig(): Promise<void> {
|
||||
}
|
||||
|
||||
async function startServer() {
|
||||
runMigrations(db);
|
||||
|
||||
const app = express();
|
||||
const PORT = Number(process.env.PORT) || 3000;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user