db: improve output of migrations, exit on failure
This commit is contained in:
parent
cdffe42cfd
commit
4708839fd6
24
src/db.ts
24
src/db.ts
|
@ -63,8 +63,26 @@ const migrator = new Migrator({
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log('Running migrations...');
|
/** Migrate the database to the latest version. */
|
||||||
const results = await migrator.migrateToLatest();
|
async function migrate() {
|
||||||
console.log('Migrations finished:', results);
|
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 };
|
export { db, type DittoDB, type EventRow, type TagRow, type UserRow };
|
||||||
|
|
Loading…
Reference in New Issue