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.
21 lines
845 B
JavaScript
21 lines
845 B
JavaScript
const migrationConfig = require("./migration-config");
|
|
const {globSync} = require('glob');
|
|
|
|
migrationConfig.getAppliedMigrations(migrationConfig.migrationTarget).then((res) => {
|
|
const appliedMigrations = res;
|
|
const availableMigrations = globSync("*", {cwd: process.cwd()+"/migrations"}).sort((a, b) => {
|
|
a.localeCompare(b);
|
|
});
|
|
|
|
const unAppliedMigrations = availableMigrations.filter((migration) => {
|
|
return appliedMigrations.indexOf(migration) === -1;
|
|
});
|
|
|
|
(async () => {
|
|
for ( migration of unAppliedMigrations ) {
|
|
var migrationImport = require(`${process.cwd()}/migrations/${migration}`);
|
|
await migrationImport.up(migrationConfig.migrationTarget);
|
|
await migrationConfig.addAppliedMigration(migrationConfig.migrationTarget, migration);
|
|
}
|
|
})();
|
|
});
|