mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
40 lines
972 B
TypeScript
40 lines
972 B
TypeScript
import fs from 'node:fs/promises';
|
|
import path from 'node:path';
|
|
|
|
import { DittoDB } from '@/db/DittoDB.ts';
|
|
import { FileMigrationProvider, Migrator } from '@/deps.ts';
|
|
|
|
const db = await DittoDB.getInstance();
|
|
|
|
const migrator = new Migrator({
|
|
db,
|
|
provider: new FileMigrationProvider({
|
|
fs,
|
|
path,
|
|
migrationFolder: new URL(import.meta.resolve('./db/migrations')).pathname,
|
|
}),
|
|
});
|
|
|
|
/** Migrate the database to the latest version. */
|
|
async function migrate() {
|
|
console.info('Running migrations...');
|
|
const results = await migrator.migrateToLatest();
|
|
|
|
if (results.error) {
|
|
console.error(results.error);
|
|
Deno.exit(1);
|
|
} else {
|
|
if (!results.results?.length) {
|
|
console.info('Everything up-to-date.');
|
|
} else {
|
|
console.info('Migrations finished!');
|
|
for (const { migrationName, status } of results.results!) {
|
|
console.info(` - ${migrationName}: ${status}`);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
await migrate();
|
|
|
|
export { db };
|