@stacksjs/actions 0.70.256 → 0.70.257

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.
@@ -523,13 +523,15 @@ Set AWS_ACCOUNT_ID in your .env file or ensure valid AWS credentials are configu
523
523
  if (isVerbose)
524
524
  log.debug(`Migration error: ${migrationError.stack}`);
525
525
  }
526
- const frameworkTablesSpinner = spinner("Ensuring framework tables (auth, notifications, RBAC)...");
526
+ const frameworkTablesSpinner = spinner("Ensuring framework tables (auth, notifications, RBAC, traits)...");
527
527
  frameworkTablesSpinner.start();
528
528
  try {
529
- const { migrateAuthTables, migrateNotificationTables, migrateRbacTables } = await import("@stacksjs/database"), failures = [], steps = [
529
+ const { ensureUtcDatetimeColumns, migrateAuthTables, migrateNotificationTables, migrateRbacTables, migrateTraitTables } = await import("@stacksjs/database"), failures = [], steps = [
530
530
  ["auth", migrateAuthTables],
531
531
  ["notification", migrateNotificationTables],
532
- ["RBAC", migrateRbacTables]
532
+ ["RBAC", migrateRbacTables],
533
+ ["trait", migrateTraitTables],
534
+ ["utc-datetime", ensureUtcDatetimeColumns]
533
535
  ];
534
536
  for (const [name, migrateTables] of steps) {
535
537
  const result = await migrateTables({ verbose: isVerbose });
@@ -540,7 +542,7 @@ Set AWS_ACCOUNT_ID in your .env file or ensure valid AWS credentials are configu
540
542
  frameworkTablesSpinner.stop();
541
543
  console.log(`\u26A0 Some framework tables could not be migrated: ${failures.join("; ")}`);
542
544
  } else
543
- frameworkTablesSpinner.succeed("Framework tables ensured (auth, notifications, RBAC)");
545
+ frameworkTablesSpinner.succeed("Framework tables ensured (auth, notifications, RBAC, traits)");
544
546
  } catch (frameworkTablesError) {
545
547
  frameworkTablesSpinner.stop();
546
548
  console.log(`\u26A0 Framework table migrations skipped: ${frameworkTablesError.message}`);
@@ -1,6 +1,7 @@
1
1
  import { generateProjectImages } from './images';
2
2
  import type { GeneratorOptions } from '@stacksjs/types';
3
3
  export type { GenerateImagesActionOptions } from './images';
4
+ export type { GenerateVSchemaOptions, GenerateVSchemaResult } from './vschema';
4
5
  // import { files } from '@stacksjs/storage'
5
6
  export declare function invoke(options?: GeneratorOptions): Promise<void>;
6
7
  export declare function generate(options: GeneratorOptions): Promise<void>;
@@ -45,3 +46,5 @@ export declare function generateSeeder(): Promise<void>;
45
46
  export declare function generateCoreSymlink(): Promise<void>;
46
47
  export declare function generateOpenApiSpec(): Promise<void>;
47
48
  export { generateProjectImages } from './images';
49
+ // Vitess keyspace VSchema, derived from the model relationship graph.
50
+ export { generateVSchema } from './vschema';
@@ -10,6 +10,7 @@ import { runAction } from "../helpers";
10
10
  import { generateVsCodeCustomData as genVsCodeCustomData } from "../helpers/vscode-custom-data";
11
11
  import { generateProjectImages } from "./images";
12
12
  export { generateProjectImages } from "./images";
13
+ export { generateVSchema } from "./vschema";
13
14
  export async function invoke(options) {
14
15
  if (options?.types)
15
16
  await generateTypes(options);
@@ -0,0 +1,9 @@
1
+ import { path } from '@stacksjs/path';
2
+ import type { VSchema } from '@stacksjs/database';
3
+ export declare function generateVSchema(options?: GenerateVSchemaOptions): Promise<GenerateVSchemaResult>;
4
+ export declare interface GenerateVSchemaOptions {
5
+ dryRun?: boolean
6
+ out?: string
7
+ }
8
+ export type GenerateVSchemaResult = | { ok: false, error: string }
9
+ | { ok: true, vschema: VSchema, report: string, path: string, tableCount: number }
@@ -0,0 +1,47 @@
1
+ import { dirname } from "node:path";
2
+ import { deriveVSchema, formatShardingReport, resolveModelSources, toShardableModel } from "@stacksjs/database";
3
+ import { log } from "@stacksjs/logging";
4
+ import { path } from "@stacksjs/path";
5
+ import { fs } from "@stacksjs/storage";
6
+ function tableNameFor(definition, fileName) {
7
+ if (definition?.table)
8
+ return definition.table;
9
+ const snake = (definition?.name ?? fileName).replace(/([a-z0-9])([A-Z])/g, "$1_$2").toLowerCase();
10
+ if (/(?:s|x|z|ch|sh)$/.test(snake))
11
+ return `${snake}es`;
12
+ if (/[^aeiou]y$/.test(snake))
13
+ return `${snake.slice(0, -1)}ies`;
14
+ return `${snake}s`;
15
+ }
16
+ export async function generateVSchema(options = {}) {
17
+ const sources = resolveModelSources();
18
+ if (!sources || sources.models.length === 0)
19
+ return { ok: !1, error: "No models found. A VSchema is derived from your models, so there is nothing to generate." };
20
+ const models = [], failed = [];
21
+ for (const source of sources.models)
22
+ try {
23
+ const definition = (await import(source.file)).default;
24
+ if (!definition)
25
+ continue;
26
+ models.push(toShardableModel(definition, tableNameFor(definition, source.name)));
27
+ } catch (error) {
28
+ failed.push(`${source.name}: ${error.message}`);
29
+ }
30
+ for (const failure of failed)
31
+ log.warn(`[generate:vschema] skipped ${failure}`);
32
+ if (models.length === 0)
33
+ return { ok: !1, error: "Every model failed to load; nothing to derive a VSchema from." };
34
+ const { vschema, decisions } = deriveVSchema(models), report = formatShardingReport(decisions), outPath = path.projectPath(options.out ?? "database/vschema.json");
35
+ if (!options.dryRun) {
36
+ fs.mkdirSync(dirname(outPath), { recursive: !0 });
37
+ await Bun.write(outPath, `${JSON.stringify(vschema, null, 2)}
38
+ `);
39
+ }
40
+ return {
41
+ ok: !0,
42
+ vschema,
43
+ report,
44
+ path: outPath,
45
+ tableCount: Object.keys(vschema.tables).length
46
+ };
47
+ }
@@ -1,5 +1,5 @@
1
1
  import process from "node:process";
2
- import { generateMigrations, migrateAuthTables, migrateNotificationTables, migrateRbacTables, resetDatabase, runDatabaseMigration } from "@stacksjs/database";
2
+ import { ensureUtcDatetimeColumns, generateMigrations, migrateAuthTables, migrateNotificationTables, migrateRbacTables, migrateTraitTables, resetDatabase, runDatabaseMigration } from "@stacksjs/database";
3
3
  import { log } from "@stacksjs/logging";
4
4
  const resetResult = await resetDatabase();
5
5
  if (resetResult?.isErr) {
@@ -22,6 +22,12 @@ if (!notifResult.success)
22
22
  const rbacResult = await migrateRbacTables();
23
23
  if (!rbacResult.success)
24
24
  log.error(`Failed to migrate RBAC tables: ${rbacResult.error}`);
25
+ const traitResult = await migrateTraitTables();
26
+ if (!traitResult.success)
27
+ log.error(`Failed to migrate polymorphic trait tables: ${traitResult.error}`);
28
+ const datetimeResult = await ensureUtcDatetimeColumns();
29
+ if (!datetimeResult.success)
30
+ log.error(`Failed to convert TIMESTAMP columns to DATETIME: ${datetimeResult.error}`);
25
31
  if (migrateResult.isErr) {
26
32
  log.error("runDatabaseMigration failed");
27
33
  log.error(migrateResult.error);
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@stacksjs/actions",
3
3
  "type": "module",
4
4
  "sideEffects": false,
5
- "version": "0.70.256",
5
+ "version": "0.70.257",
6
6
  "description": "The Stacks actions.",
7
7
  "author": "Chris Breuer",
8
8
  "contributors": [
@@ -59,33 +59,33 @@
59
59
  "prepublishOnly": "bun run build"
60
60
  },
61
61
  "dependencies": {
62
- "@stacksjs/config": "0.70.256",
62
+ "@stacksjs/config": "0.70.257",
63
63
  "@stacksjs/bumpx": "^0.2.6",
64
64
  "@stacksjs/bunpress": "^0.1.18",
65
65
  "@stacksjs/logsmith": "^0.2.3",
66
- "@stacksjs/registry": "0.70.256",
66
+ "@stacksjs/registry": "0.70.257",
67
67
  "@stacksjs/stx": "^0.2.148",
68
68
  "@stacksjs/ts-cloud": "^0.7.92",
69
69
  "@stacksjs/ts-md": "^0.1.1"
70
70
  },
71
71
  "devDependencies": {
72
- "@stacksjs/api": "0.70.256",
73
- "@stacksjs/cli": "0.70.256",
74
- "@stacksjs/database": "0.70.256",
72
+ "@stacksjs/api": "0.70.257",
73
+ "@stacksjs/cli": "0.70.257",
74
+ "@stacksjs/database": "0.70.257",
75
75
  "@stacksjs/tlsx": "^0.13.2",
76
76
  "better-dx": "^0.2.17",
77
- "@stacksjs/dns": "0.70.256",
78
- "@stacksjs/enums": "0.70.256",
79
- "@stacksjs/env": "0.70.256",
80
- "@stacksjs/error-handling": "0.70.256",
81
- "@stacksjs/image": "0.70.256",
82
- "@stacksjs/logging": "0.70.256",
83
- "@stacksjs/path": "0.70.256",
84
- "@stacksjs/security": "0.70.256",
85
- "@stacksjs/storage": "0.70.256",
86
- "@stacksjs/strings": "0.70.256",
87
- "@stacksjs/utils": "0.70.256",
88
- "@stacksjs/validation": "0.70.256"
77
+ "@stacksjs/dns": "0.70.257",
78
+ "@stacksjs/enums": "0.70.257",
79
+ "@stacksjs/env": "0.70.257",
80
+ "@stacksjs/error-handling": "0.70.257",
81
+ "@stacksjs/image": "0.70.257",
82
+ "@stacksjs/logging": "0.70.257",
83
+ "@stacksjs/path": "0.70.257",
84
+ "@stacksjs/security": "0.70.257",
85
+ "@stacksjs/storage": "0.70.257",
86
+ "@stacksjs/strings": "0.70.257",
87
+ "@stacksjs/utils": "0.70.257",
88
+ "@stacksjs/validation": "0.70.257"
89
89
  },
90
90
  "peerDependencies": {
91
91
  "pickier": "^0.1.35"