db: improve output of migrations, exit on failure

This commit is contained in:
Alex Gleason 2023-09-05 16:04:23 -05:00
parent cdffe42cfd
commit 4708839fd6
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
1 changed files with 21 additions and 3 deletions

View File

@ -63,8 +63,26 @@ const migrator = new Migrator({
}),
});
console.log('Running migrations...');
const results = await migrator.migrateToLatest();
console.log('Migrations finished:', results);
/** Migrate the database to the latest version. */
async function migrate() {
console.log('Running migrations...');
const results = await migrator.migrateToLatest();
if (results.error) {
console.error(results.error);
Deno.exit(1);
} else {
if (!results.results?.length) {
console.log('Everything up-to-date.');
} else {
console.log('Migrations finished!');
for (const { migrationName, status } of results.results) {
console.log(` - ${migrationName}: ${status}`);
}
}
}
}
await migrate();
export { db, type DittoDB, type EventRow, type TagRow, type UserRow };