@sebspark/spanner-migrate 0.1.0 → 0.1.1

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/README.md CHANGED
@@ -1,3 +1,104 @@
1
- # `@sebspark/spanner-migrate`
1
+ # @sebspark/spanner-migrate
2
2
 
3
- Migration tool for Spanner DB
3
+ `spanner-migrate` is a CLI tool for managing schema migrations for Google Cloud Spanner. It simplifies schema evolution by allowing you to create, apply, rollback, and track migrations.
4
+
5
+ ---
6
+
7
+ ## Installation
8
+
9
+ Install `@sebspark/spanner-migrate` as a global package:
10
+
11
+ ```zsh
12
+ yarn add -D @sebspark/spanner-migrate
13
+ ```
14
+
15
+ ---
16
+
17
+ ## CLI Usage
18
+
19
+ Run `spanner-migrate` from your project root. If no command is provided, the help message is displayed.
20
+
21
+ ```zsh
22
+ spanner-migrate [command] [options]
23
+ ```
24
+
25
+ ### Commands
26
+
27
+ #### `init`
28
+ Initialize a Spanner migration configuration file (`.spanner-migrate.config.json`).
29
+
30
+ **Usage:**
31
+
32
+ ```zsh
33
+ spanner-migrate init
34
+ ```
35
+
36
+ **Prompts:**
37
+ - `Enter the path for your migrations`: Directory for migration files (default: `./migrations`).
38
+ - `Enter Spanner instance name`: The name of the Spanner instance.
39
+ - `Enter Spanner database name`: The name of the Spanner database.
40
+ - `Enter Google Cloud project name`: (Optional) The Google Cloud project name.
41
+
42
+ ---
43
+
44
+ #### `create <description>`
45
+ Create a new migration file.
46
+
47
+ **Usage:**
48
+
49
+ ```zsh
50
+ spanner-migrate create add users table
51
+ ```
52
+
53
+ #### `up`
54
+ Apply pending migrations
55
+
56
+ **Usage:**
57
+
58
+ ```zsh
59
+ spanner-migrate up
60
+ ```
61
+
62
+ If you don't want to apply all pending migrations, use the `--max` or `-m` flag
63
+
64
+ ```zsh
65
+ spanner migrate up --max 1
66
+ ```
67
+
68
+ #### `down`
69
+ Rollback one migration
70
+
71
+ **Usage:**
72
+
73
+ ```zsh
74
+ spanner-migrate down
75
+ ```
76
+
77
+ #### `status`
78
+ Check migration status
79
+
80
+ **Usage:**
81
+
82
+ ```zsh
83
+ spanner-migrate status
84
+ ```
85
+ Displays an overview of applied and peding migrations
86
+
87
+ ```text
88
+ Migrations
89
+
90
+ Applied
91
+ --------------------------------------------------------------------------------
92
+ 20250122080434866_add_users_table
93
+ 20250122080444982_add_index_on_users
94
+
95
+ New
96
+ --------------------------------------------------------------------------------
97
+ 20250122080444982_add_index_on_users
98
+ ```
99
+
100
+ ---
101
+
102
+ ## License
103
+
104
+ [Apache-2.0](LICENSE)
package/dist/cli.js CHANGED
@@ -26,6 +26,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
26
  // src/cli.ts
27
27
  var import_promises2 = __toESM(require("fs/promises"));
28
28
  var import_node_path2 = require("path");
29
+ var import_input = __toESM(require("@inquirer/input"));
29
30
  var import_yargs = __toESM(require("yargs"));
30
31
  var import_helpers = require("yargs/helpers");
31
32
 
@@ -314,36 +315,34 @@ async function loadConfig() {
314
315
  process.exit(1);
315
316
  }
316
317
  }
317
- (0, import_yargs.default)((0, import_helpers.hideBin)(process.argv)).scriptName("spanner-migrate").usage("$0 <command> [options]").command(
318
+ (0, import_yargs.default)((0, import_helpers.hideBin)(process.argv)).scriptName("spanner-migrate").usage("$0 <command>").command(
318
319
  "init",
319
320
  "Initialize a .spanner-migrate.config.json file",
320
- (yargs2) => {
321
- yargs2.option("migrationsPath", {
322
- type: "string",
323
- describe: "Path to the migrations folder",
324
- default: "./spanner-migrations"
321
+ async () => {
322
+ const migrationsPath = await (0, import_input.default)({
323
+ message: "Enter the path for your migrations",
324
+ required: true,
325
+ default: "./migrations"
325
326
  });
326
- yargs2.option("instanceName", {
327
- type: "string",
328
- describe: "Spanner instance name",
329
- demandOption: true
327
+ const instanceName = await (0, import_input.default)({
328
+ message: "Enter Spanner instance name",
329
+ required: true
330
330
  });
331
- yargs2.option("databaseName", {
332
- type: "string",
333
- describe: "Spanner database name",
334
- demandOption: true
331
+ const databaseName = await (0, import_input.default)({
332
+ message: "Enter Spanner database name",
333
+ required: true
335
334
  });
336
- yargs2.option("projectName", {
337
- type: "string",
338
- describe: "Google Cloud project name (optional)"
335
+ const projectId = await (0, import_input.default)({
336
+ message: "Enter Google Cloud project name",
337
+ required: false
339
338
  });
340
- },
341
- async (args) => {
342
- await init(args, CONFIG_FILE);
339
+ const config = { instanceName, databaseName, migrationsPath };
340
+ if (projectId) config.projectId = projectId;
341
+ await init(config, CONFIG_FILE);
343
342
  console.log(`Configuration written to ${CONFIG_FILE}`);
344
343
  }
345
344
  ).command(
346
- "create <description>",
345
+ "create <description ...>",
347
346
  "Create a new migration file",
348
347
  (yargs2) => {
349
348
  yargs2.positional("description", {
@@ -354,9 +353,10 @@ async function loadConfig() {
354
353
  },
355
354
  async (args) => {
356
355
  const config = await loadConfig();
357
- await create(config, args.description);
356
+ const fullDescription = args.description.join(" ");
357
+ await create(config, fullDescription);
358
358
  console.log(
359
- `Migration file created: '${(0, import_node_path2.join)(config.migrationsPath, args.description)}'`
359
+ `Migration file created: '${(0, import_node_path2.join)(config.migrationsPath, args.description.join("_"))}.ts'`
360
360
  );
361
361
  }
362
362
  ).command(
@@ -383,4 +383,4 @@ async function loadConfig() {
383
383
  const config = await loadConfig();
384
384
  const migrationStatus = await status(config);
385
385
  console.log(migrationStatus);
386
- }).help().strict().parse();
386
+ }).demandCommand().help().parse();
package/dist/cli.mjs CHANGED
@@ -10,6 +10,7 @@ import {
10
10
  // src/cli.ts
11
11
  import fs from "node:fs/promises";
12
12
  import { join } from "node:path";
13
+ import input from "@inquirer/input";
13
14
  import yargs from "yargs";
14
15
  import { hideBin } from "yargs/helpers";
15
16
  var CONFIG_FILE = "./.spanner-migrate.config.json";
@@ -22,36 +23,34 @@ async function loadConfig() {
22
23
  process.exit(1);
23
24
  }
24
25
  }
25
- yargs(hideBin(process.argv)).scriptName("spanner-migrate").usage("$0 <command> [options]").command(
26
+ yargs(hideBin(process.argv)).scriptName("spanner-migrate").usage("$0 <command>").command(
26
27
  "init",
27
28
  "Initialize a .spanner-migrate.config.json file",
28
- (yargs2) => {
29
- yargs2.option("migrationsPath", {
30
- type: "string",
31
- describe: "Path to the migrations folder",
32
- default: "./spanner-migrations"
29
+ async () => {
30
+ const migrationsPath = await input({
31
+ message: "Enter the path for your migrations",
32
+ required: true,
33
+ default: "./migrations"
33
34
  });
34
- yargs2.option("instanceName", {
35
- type: "string",
36
- describe: "Spanner instance name",
37
- demandOption: true
35
+ const instanceName = await input({
36
+ message: "Enter Spanner instance name",
37
+ required: true
38
38
  });
39
- yargs2.option("databaseName", {
40
- type: "string",
41
- describe: "Spanner database name",
42
- demandOption: true
39
+ const databaseName = await input({
40
+ message: "Enter Spanner database name",
41
+ required: true
43
42
  });
44
- yargs2.option("projectName", {
45
- type: "string",
46
- describe: "Google Cloud project name (optional)"
43
+ const projectId = await input({
44
+ message: "Enter Google Cloud project name",
45
+ required: false
47
46
  });
48
- },
49
- async (args) => {
50
- await init(args, CONFIG_FILE);
47
+ const config = { instanceName, databaseName, migrationsPath };
48
+ if (projectId) config.projectId = projectId;
49
+ await init(config, CONFIG_FILE);
51
50
  console.log(`Configuration written to ${CONFIG_FILE}`);
52
51
  }
53
52
  ).command(
54
- "create <description>",
53
+ "create <description ...>",
55
54
  "Create a new migration file",
56
55
  (yargs2) => {
57
56
  yargs2.positional("description", {
@@ -62,9 +61,10 @@ yargs(hideBin(process.argv)).scriptName("spanner-migrate").usage("$0 <command> [
62
61
  },
63
62
  async (args) => {
64
63
  const config = await loadConfig();
65
- await create(config, args.description);
64
+ const fullDescription = args.description.join(" ");
65
+ await create(config, fullDescription);
66
66
  console.log(
67
- `Migration file created: '${join(config.migrationsPath, args.description)}'`
67
+ `Migration file created: '${join(config.migrationsPath, args.description.join("_"))}.ts'`
68
68
  );
69
69
  }
70
70
  ).command(
@@ -91,4 +91,4 @@ yargs(hideBin(process.argv)).scriptName("spanner-migrate").usage("$0 <command> [
91
91
  const config = await loadConfig();
92
92
  const migrationStatus = await status(config);
93
93
  console.log(migrationStatus);
94
- }).help().strict().parse();
94
+ }).demandCommand().help().parse();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sebspark/spanner-migrate",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "license": "Apache-2.0",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -31,6 +31,7 @@
31
31
  "@google-cloud/spanner": "*"
32
32
  },
33
33
  "dependencies": {
34
+ "@inquirer/input": "4.1.3",
34
35
  "yargs": "17.7.2"
35
36
  }
36
37
  }