Migrations script

This commit is contained in:
2019-10-22 14:34:19 +02:00
parent 6ab4c1e4d3
commit 890f3e5327
4 changed files with 146 additions and 52 deletions

14
src/scripts/migrate.js Normal file
View 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
View 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;