mirror of
https://github.com/wassname/talk.git
synced 2026-06-30 01:58:00 +08:00
c045f52daa
* feat: added migration framework * chore: added premod user status migration * feat: enhanced error handling of migrations * fix: added missing argument from abstract method * fix: another templating blunder * fix: removed debug code * feat: enhanced migration tracking * fix: remove skipping migrations * feat: moved indexing to migration system * fix: linting
53 lines
1.1 KiB
TypeScript
53 lines
1.1 KiB
TypeScript
#!/usr/bin/env ts-node
|
|
|
|
/**
|
|
* This script can be invoked via:
|
|
*
|
|
* npm run migration:create <migration name>
|
|
*
|
|
* To create new database migrations.
|
|
*/
|
|
|
|
// tslint:disable: no-console
|
|
|
|
import fs from "fs-extra";
|
|
import lodash from "lodash";
|
|
import path from "path";
|
|
|
|
const templateFilePath = path.resolve(
|
|
path.join(
|
|
__dirname,
|
|
"../../src/core/server/services/migrate/migration_sample.ts"
|
|
)
|
|
);
|
|
|
|
const argv = process.argv.slice(2);
|
|
if (argv.length !== 1) {
|
|
console.error("usage: npm run migration:create <migration name>");
|
|
process.exit(1);
|
|
}
|
|
|
|
// Get the name of the new migration.
|
|
const name = lodash.snakeCase(argv[0]);
|
|
|
|
// Get the version of the new migration.
|
|
const version = Date.now();
|
|
|
|
// Get the filePath of the new migration.
|
|
const filePath = path.resolve(
|
|
path.join(
|
|
__dirname,
|
|
`../../src/core/server/services/migrate/migrations/${version}_${name}.ts`
|
|
)
|
|
);
|
|
|
|
if (fs.existsSync(filePath)) {
|
|
console.error(`migration already exists at: ${filePath}`);
|
|
process.exit(1);
|
|
}
|
|
|
|
// Write the template out to the file.
|
|
fs.copyFileSync(templateFilePath, filePath);
|
|
|
|
console.log(`created new migration at: ${filePath}`);
|