brainz-aggregator/migration-config.js
Andrew Pietila 8f178392f9 Initial Commit
Added: app.js basic express http listener.
Added: migrate-tool, to automatically apply migrations, including a base migration to create a database table to track migrations.
2024-01-21 18:52:24 -06:00

25 lines
No EOL
1,006 B
JavaScript

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);
});
}
}