tina4-nodejs 3.13.119 → 3.13.121

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.
@@ -8,53 +8,48 @@
8
8
  * Creates both:
9
9
  * migrations/YYYYMMDDHHMMSS_description.sql (up migration)
10
10
  * migrations/YYYYMMDDHHMMSS_description.down.sql (rollback)
11
+ *
12
+ * 3.13.121 (ADR-0063): this is a thin delegation to `generate migration` so a
13
+ * scaffolded migration has ONE shape and ONE envelope regardless of whether
14
+ * the developer typed `tina4 migrate:create` or `tina4 generate migration`.
15
+ * The two file paths emitted here (`_desc.sql` + `_desc.down.sql`) and the
16
+ * schema-awareness on `create_X` names are unchanged; the delegation adds the
17
+ * ADR-0063 `generate_v1_1` envelope, `--json` / `--dry-run` support, and the
18
+ * `edit_hints[]` / `next[]` machinery for free. `--no-test` preserves the
19
+ * pre-3.13.121 UX (just a migration, no co-emitted test).
11
20
  */
12
- import { existsSync, mkdirSync, readdirSync, writeFileSync } from "node:fs";
13
- import { join, resolve } from "node:path";
21
+ import { generate } from "./generate.js";
22
+
23
+ export async function createMigration(args: string[] = []): Promise<void> {
24
+ // Split flags from the description so `tina4 migrate:create "add users"
25
+ // --json --dry-run` reaches the same envelope machinery as its
26
+ // `tina4 generate migration` twin (see test/migrateCreateEnvelopeParity.test.ts).
27
+ const positionals: string[] = [];
28
+ const flags: string[] = [];
29
+ for (const arg of args) {
30
+ if (arg.startsWith("--")) flags.push(arg);
31
+ else positionals.push(arg);
32
+ }
33
+ const description = positionals.join(" ").trim();
14
34
 
15
- export async function createMigration(description?: string): Promise<void> {
16
35
  if (!description) {
17
36
  console.error(" Usage: tina4 migrate:create <description>");
18
37
  console.error(' Example: tina4 migrate:create "create users table"');
19
38
  process.exit(1);
20
39
  }
21
40
 
22
- const dir = resolve("migrations");
23
-
24
- // Ensure migrations/ exists
25
- if (!existsSync(dir)) {
26
- mkdirSync(dir, { recursive: true });
27
- }
28
-
29
- // Sanitise description for filename
30
- const safeName = description
41
+ // Sanitise the description into a filename-safe slug BEFORE delegation.
42
+ // Preserves migrate:create's pre-3.13.121 UX: `migrate:create "add users"`
43
+ // still yields `${ts}_add_users.sql` (space -> underscore, lowercased),
44
+ // never a filename with a bare space. `generate migration` takes its name
45
+ // verbatim by design; migrate:create is the human-friendly front door.
46
+ const safeDescription = description
31
47
  .toLowerCase()
32
48
  .replace(/[^a-z0-9]+/g, "_")
33
49
  .replace(/^_|_$/g, "");
34
50
 
35
- // Use YYYYMMDDHHMMSS timestamp prefix
36
- const now = new Date();
37
- const timestamp = [
38
- now.getFullYear(),
39
- String(now.getMonth() + 1).padStart(2, "0"),
40
- String(now.getDate()).padStart(2, "0"),
41
- String(now.getHours()).padStart(2, "0"),
42
- String(now.getMinutes()).padStart(2, "0"),
43
- String(now.getSeconds()).padStart(2, "0"),
44
- ].join("");
45
-
46
- const upFileName = `${timestamp}_${safeName}.sql`;
47
- const downFileName = `${timestamp}_${safeName}.down.sql`;
48
- const upPath = join(dir, upFileName);
49
- const downPath = join(dir, downFileName);
50
-
51
- const upTemplate = `-- Migration: ${description}\n-- Created: ${now.toISOString()}\n\n`;
52
- const downTemplate = `-- Rollback: ${description}\n-- Created: ${now.toISOString()}\n\n`;
53
-
54
- writeFileSync(upPath, upTemplate, "utf-8");
55
- writeFileSync(downPath, downTemplate, "utf-8");
56
-
57
- console.log(` Created migration: ${upFileName}`);
58
- console.log(` Created rollback: ${downFileName}`);
59
- console.log(` Path: ${dir}`);
51
+ // Delegate to `generate migration` with --no-test so migrate:create stays
52
+ // "just a migration, no test" — its pre-3.13.121 semantics — while getting
53
+ // the ADR-0063 envelope, edit_hints[], next[] and --json/--dry-run for free.
54
+ await generate("migration", safeDescription, ["--no-test", ...flags]);
60
55
  }