aiiinotate 0.8.4 → 0.8.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli/migrate.js +14 -8
- package/package.json +1 -1
package/cli/migrate.js
CHANGED
|
@@ -15,9 +15,6 @@ import { execSync } from "node:child_process"
|
|
|
15
15
|
|
|
16
16
|
import { Command, Option, Argument } from "commander";
|
|
17
17
|
|
|
18
|
-
import loadMongoClient from "#cli/utils/mongoClient.js";
|
|
19
|
-
|
|
20
|
-
|
|
21
18
|
/** @typedef {"make"|"apply"|"revert"|"revert-all"} MigrateOpType */
|
|
22
19
|
const allowedMigrateOp = ["make", "apply", "revert", "revert-all"];
|
|
23
20
|
|
|
@@ -109,17 +106,26 @@ async function action(command, migrationOp, options) {
|
|
|
109
106
|
|
|
110
107
|
function makeMigrateCommand() {
|
|
111
108
|
const migrationOpArg =
|
|
112
|
-
new Argument("<migration-op>", "name of migration operation")
|
|
109
|
+
new Argument("<migration-op>", "name of migration operation")
|
|
110
|
+
.choices(allowedMigrateOp);
|
|
113
111
|
|
|
114
112
|
const migrationNameOpt =
|
|
115
|
-
new Option("-n, --migration-name <name>", "name of migration (for 'make' argument)")
|
|
116
|
-
.makeOptionMandatory();
|
|
113
|
+
new Option("-n, --migration-name <name>", "name of migration (for 'make' argument)");
|
|
117
114
|
|
|
118
|
-
|
|
115
|
+
const command = new Command("migrate");
|
|
116
|
+
return command
|
|
119
117
|
.description("run database migrations")
|
|
120
118
|
.addArgument(migrationOpArg)
|
|
121
119
|
.addOption(migrationNameOpt)
|
|
122
|
-
.action((migrationOp, options, command) =>
|
|
120
|
+
.action((migrationOp, options, command) => {
|
|
121
|
+
if (
|
|
122
|
+
migrationOp == "make"
|
|
123
|
+
&& (options.migrationName === undefined || options.migrationName === "")
|
|
124
|
+
) {
|
|
125
|
+
command.error("migration operation \"apply\" requires option \"-n, --migration-name <name>\"", { exitCode: 1 });
|
|
126
|
+
}
|
|
127
|
+
action(command, migrationOp, options)
|
|
128
|
+
})
|
|
123
129
|
}
|
|
124
130
|
|
|
125
131
|
export default makeMigrateCommand;
|