@stacksjs/database 0.70.93 → 0.70.95

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.
@@ -43,6 +43,13 @@ export declare function resetDatabase(): Promise<Result<string, Error>>;
43
43
  */
44
44
  export declare function previewPendingMigrations(options?: GenerateMigrationsOptions): Promise<MigrationOperation[]>;
45
45
  export declare function generateMigrations(options?: GenerateMigrationsOptions): Promise<Result<string, Error>>;
46
+ /**
47
+ * Group generated SQL by the migration filename style the runner already
48
+ * uses for hand-written files: `create-<table>-table`,
49
+ * `alter-<table>-<col>`, `create-<index>-index-in-<table>`, or
50
+ * `drop-<table>-table`. Anything we can't match falls back to `auto-misc`.
51
+ */
52
+ export declare function groupGeneratedStatements(sqlStatements: string[]): GeneratedGroup[];
46
53
  /**
47
54
  * Generate fresh migrations (full regeneration, ignoring previous state)
48
55
  */
@@ -63,6 +70,10 @@ export declare interface GenerateMigrationsOptions {
63
70
  applyRenames?: boolean
64
71
  fromDb?: boolean
65
72
  }
73
+ declare interface GeneratedGroup {
74
+ label: string
75
+ statements: string[]
76
+ }
66
77
  /**
67
78
  * Migration result type for compatibility
68
79
  */
@@ -535,12 +535,15 @@ ${readFileSync(join(migrationsDir, f), "utf8")}`;
535
535
  }
536
536
  return written;
537
537
  }
538
- function groupGeneratedStatements(sqlStatements) {
538
+ export function groupGeneratedStatements(sqlStatements) {
539
539
  const groups = new Map, push = (label, stmt) => {
540
540
  const list = groups.get(label) ?? [];
541
541
  list.push(stmt);
542
542
  groups.set(label, list);
543
- };
543
+ }, createdTables = new Set(sqlStatements.flatMap((raw) => {
544
+ const match = raw.trim().match(/^\s*CREATE\s+TABLE\s+(?:IF\s+NOT\s+EXISTS\s+)?["`]?(\w+)["`]?/i);
545
+ return match?.[1] ? [match[1]] : [];
546
+ }));
544
547
  for (const raw of sqlStatements) {
545
548
  const stmt = raw.trim();
546
549
  if (!stmt)
@@ -557,7 +560,7 @@ function groupGeneratedStatements(sqlStatements) {
557
560
  }
558
561
  const idx = stmt.match(/^\s*CREATE\s+(?:UNIQUE\s+)?INDEX\s+(?:IF\s+NOT\s+EXISTS\s+)?["`]?(\w+)["`]?\s+ON\s+["`]?(\w+)["`]?/i);
559
562
  if (idx) {
560
- push(`create-${idx[1]}-index-in-${idx[2]}`, stmt);
563
+ push(createdTables.has(idx[2]) ? `create-${idx[2]}-table` : `create-${idx[1]}-index-in-${idx[2]}`, stmt);
561
564
  continue;
562
565
  }
563
566
  const drop = stmt.match(/^\s*DROP\s+TABLE\s+(?:IF\s+EXISTS\s+)?["`]?(\w+)["`]?/i);
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@stacksjs/database",
3
3
  "type": "module",
4
4
  "sideEffects": false,
5
- "version": "0.70.93",
5
+ "version": "0.70.95",
6
6
  "description": "The Stacks database integration.",
7
7
  "author": "Chris Breuer",
8
8
  "contributors": [
@@ -55,18 +55,18 @@
55
55
  "prepublishOnly": "bun run build"
56
56
  },
57
57
  "dependencies": {
58
- "bun-query-builder": "^0.1.50"
58
+ "bun-query-builder": "^0.1.52"
59
59
  },
60
60
  "devDependencies": {
61
- "@stacksjs/cli": "0.70.93",
62
- "@stacksjs/config": "0.70.93",
63
- "@stacksjs/logging": "0.70.93",
64
- "@stacksjs/router": "0.70.93",
61
+ "@stacksjs/cli": "0.70.95",
62
+ "@stacksjs/config": "0.70.95",
63
+ "@stacksjs/logging": "0.70.95",
64
+ "@stacksjs/router": "0.70.95",
65
65
  "better-dx": "^0.2.16",
66
- "@stacksjs/path": "0.70.93",
67
- "@stacksjs/query-builder": "0.70.93",
68
- "@stacksjs/storage": "0.70.93",
69
- "@stacksjs/strings": "0.70.93",
70
- "@stacksjs/utils": "0.70.93"
66
+ "@stacksjs/path": "0.70.95",
67
+ "@stacksjs/query-builder": "0.70.95",
68
+ "@stacksjs/storage": "0.70.95",
69
+ "@stacksjs/strings": "0.70.95",
70
+ "@stacksjs/utils": "0.70.95"
71
71
  }
72
72
  }