mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2024-11-21 21:09:22 +00:00
Ready to implement migration
This commit is contained in:
parent
a3f0b86fea
commit
26ff8dfdff
@ -2,6 +2,7 @@ import { ConfigurationHelper } from "./helpers/ConfigHelper";
|
||||
import { DatabaseHelper } from "./helpers/DatabaseHelper";
|
||||
import { startServer } from "./server";
|
||||
import { showHelp } from "./help";
|
||||
import { startMigration } from "./migration";
|
||||
|
||||
/**
|
||||
* Main project script
|
||||
@ -32,6 +33,10 @@ async function init() {
|
||||
await startServer();
|
||||
break;
|
||||
|
||||
case "migration":
|
||||
await startMigration(process.argv.slice(4));
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
51
src/migration.ts
Normal file
51
src/migration.ts
Normal file
@ -0,0 +1,51 @@
|
||||
/**
|
||||
* Migration assistant
|
||||
*
|
||||
* @author Pierre Hubert
|
||||
*/
|
||||
|
||||
import { MigrationsList } from "./migrations/MigrationsList";
|
||||
import { createInterface } from "readline";
|
||||
|
||||
|
||||
function fatal(msg : string) {
|
||||
console.error("Fatal error: " + msg);
|
||||
process.exit(-1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Start a new migration
|
||||
*
|
||||
* @param args Arguments passed to the command line
|
||||
*/
|
||||
export async function startMigration(args: String[]) {
|
||||
if(args.length < 1)
|
||||
fatal("Missing migration ID!");
|
||||
|
||||
const migrationID = args[0];
|
||||
const migration = MigrationsList.find((m) => m.id == migrationID);
|
||||
|
||||
if(!migration)
|
||||
fatal("Could not find requested migration: "+migrationID+" !");
|
||||
|
||||
// Ask user confirmation before continuing
|
||||
const rl = createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout
|
||||
});
|
||||
|
||||
const response = await new Promise((res, _rej) => rl.question(
|
||||
"Do you want to start this migration: " + migration.id + " ? (y/n) ",
|
||||
(ans) => res(ans)
|
||||
));
|
||||
|
||||
rl.close();
|
||||
|
||||
if(response !== "y")
|
||||
fatal("Operation aborted.");
|
||||
|
||||
// Do the migration
|
||||
await migration.func();
|
||||
|
||||
process.exit(0);
|
||||
}
|
20
src/migrations/MigrationsList.ts
Normal file
20
src/migrations/MigrationsList.ts
Normal file
@ -0,0 +1,20 @@
|
||||
/**
|
||||
* List of currently available migrations
|
||||
*
|
||||
* @author Pierre Hubert
|
||||
*/
|
||||
|
||||
interface Migration {
|
||||
id: string,
|
||||
func: () => Promise<void>
|
||||
}
|
||||
|
||||
export const MigrationsList : Migration[] = [
|
||||
|
||||
// Account image migration (files -> database, May 2020)
|
||||
{
|
||||
id: "account_image_2020",
|
||||
func: undefined
|
||||
}
|
||||
|
||||
]
|
Loading…
Reference in New Issue
Block a user