From f9bcbb1f9c1cf51624fc75fbfac55319dfded310 Mon Sep 17 00:00:00 2001 From: Leopoldadmin Date: Mon, 22 Jun 2026 05:37:32 +0000 Subject: [PATCH] feat(database): add migrations.ts with migration framework --- backend/src/database/migrations.ts | 48 ++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 backend/src/database/migrations.ts diff --git a/backend/src/database/migrations.ts b/backend/src/database/migrations.ts new file mode 100644 index 0000000..1ec6695 --- /dev/null +++ b/backend/src/database/migrations.ts @@ -0,0 +1,48 @@ +import { readFileSync } from 'fs'; +import { join } from 'path'; + +export type Migration = { + version: number; + name: string; + up: string; // SQL script for migration +}; + +export class MigrationManager { + private migrations: Migration[] = []; + + constructor() { + this.loadMigrations(); + } + + private loadMigrations() { + // In a real implementation, this would load migration files from a directory + // For now, we'll just create a single migration for the initial schema + + const schemaPath = join(__dirname, 'schema.sql'); + const schemaSql = readFileSync(schemaPath, 'utf8'); + + const initialMigration: Migration = { + version: 1, + name: 'initial_schema', + up: schemaSql + }; + + this.migrations.push(initialMigration); + } + + public getMigrations(): Migration[] { + return this.migrations; + } + + public getMigrationByVersion(version: number): Migration | undefined { + return this.migrations.find(m => m.version === version); + } + + public getLatestVersion(): number { + if (this.migrations.length === 0) return 0; + return Math.max(...this.migrations.map(m => m.version)); + } +} + +// Export a singleton instance +export const migrationManager = new MigrationManager(); \ No newline at end of file