brainz-aggregator/migration-config.js

25 lines
1,006 B
JavaScript
Raw Normal View History

const sqlite3 = require("better-sqlite3");
module.exports = {
migrationTarget: new sqlite3("./brainz-social.sqlite3"),
getAppliedMigrations: (target) => {
return new Promise((res, rej) => {
var rows = target.prepare("SELECT * FROM brainz_migrations;").all();
res(rows.map((row) => row.name));
}).catch((rej) => {
if ( rej.code === "SQLITE_ERROR" && rej.message === "no such table: brainz_migrations")
return [];
throw new Error("Unhandled SQLITE error", {cause: rej});
})
},
addAppliedMigration: (target, migrationName) => {
return new Promise((res, rej) => {
target.prepare("INSERT INTO brainz_migrations (name) VALUES (?);").run(migrationName);
});
},
removeAppliedMigration: (target, migrationName) => {
return new Promise((res, rej) => {
target.prepare("DELETE FROM brainz_migrations WHERE name = ?;").run(migrationName);
});
}
}