Migrations script
This commit is contained in:
14
src/scripts/migrate.js
Normal file
14
src/scripts/migrate.js
Normal file
@@ -0,0 +1,14 @@
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
var yargs_1 = require("yargs");
|
||||
var _ = yargs_1["default"]
|
||||
.scriptName("migrate")
|
||||
.command("new [name]", "create a new migration", function (args) {
|
||||
args.positional("name", {
|
||||
type: "string",
|
||||
describe: "name of the migration"
|
||||
});
|
||||
}, function (argv) {
|
||||
console.log("hi", argv.name);
|
||||
})
|
||||
.help().argv;
|
||||
31
src/scripts/migrate.ts
Normal file
31
src/scripts/migrate.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import fs from "fs";
|
||||
import { DateTime } from "luxon";
|
||||
import path from "path";
|
||||
import yargs from "yargs";
|
||||
|
||||
const _ = yargs
|
||||
.scriptName("migrate")
|
||||
.command(
|
||||
"new [name]",
|
||||
"create a new migration",
|
||||
args => {
|
||||
args.positional("name", {
|
||||
type: "string",
|
||||
describe: "name of the migration"
|
||||
});
|
||||
},
|
||||
argv => {
|
||||
const now = DateTime.utc().toFormat("yyyyMMddHHmmss");
|
||||
const dirName = path.join(
|
||||
"sql",
|
||||
"migrations",
|
||||
"patches",
|
||||
`${now}-${argv.name}`
|
||||
);
|
||||
fs.mkdirSync(dirName);
|
||||
fs.closeSync(fs.openSync(path.join(dirName, "up.sql"), "w"));
|
||||
fs.closeSync(fs.openSync(path.join(dirName, "down.sql"), "w"));
|
||||
console.log(`Created ${dirName}`); // tslint:disable-line:no-console
|
||||
}
|
||||
)
|
||||
.help().argv;
|
||||
Reference in New Issue
Block a user