@gzl10/nexus-backend 0.18.0 → 0.19.0

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.
@@ -0,0 +1,63 @@
1
+ import { ModuleContext, ModuleManifest } from '@gzl10/nexus-sdk';
2
+ import { Knex } from 'knex';
3
+
4
+ /**
5
+ * Create all tables from all modules in FK-dependency order.
6
+ * Collects all entity definitions, sorts by FK references, and creates inline.
7
+ * This ensures cross-module FKs work correctly (including SQLite).
8
+ */
9
+ declare function runAllGeneratedMigrations(ctx: ModuleContext, modules: ModuleManifest[]): Promise<void>;
10
+ /**
11
+ * @deprecated Use runAllGeneratedMigrations instead.
12
+ * Kept for backward compatibility with tests that use it directly.
13
+ */
14
+ declare function runGeneratedMigration(ctx: ModuleContext, module: ModuleManifest): Promise<void>;
15
+
16
+ /**
17
+ * Get the database client type
18
+ * Returns 'sqlite' as default when client type cannot be determined (e.g., in mocks)
19
+ */
20
+ declare function getDbClient(db: Knex): 'postgres' | 'mysql' | 'sqlite';
21
+ /**
22
+ * Format timestamp for database insert/update
23
+ * - PostgreSQL: accepts ISO strings directly
24
+ * - MySQL: requires 'YYYY-MM-DD HH:MM:SS' format
25
+ * - SQLite: accepts ISO strings (stored as TEXT)
26
+ *
27
+ * @param db Knex instance to detect driver
28
+ * @param date Date object (defaults to now)
29
+ * @returns Formatted timestamp string
30
+ */
31
+ declare function formatTimestamp(db: Knex, date?: Date): string;
32
+ /**
33
+ * Get current timestamp formatted for the database
34
+ */
35
+ declare function nowTimestamp(db: Knex): string;
36
+ /**
37
+ * Adds timestamp fields to a table during creation.
38
+ * - PostgreSQL: uses timestamptz (timestamp with time zone)
39
+ * - MySQL: uses standard timestamp
40
+ * - SQLite: uses TEXT with datetime('now') for ISO string consistency
41
+ */
42
+ declare function addTimestamps(table: Knex.CreateTableBuilder, db: Knex): void;
43
+ /**
44
+ * Adds audit fields (created_by, updated_by) to an existing table if missing.
45
+ * Note: SQLite does not support ALTER TABLE ADD COLUMN with a non-constant default.
46
+ */
47
+ declare function addAuditFieldsIfMissing(db: Knex, tableName: string): Promise<void>;
48
+ /**
49
+ * Adds is_default field to config tables.
50
+ * Allows marking which configuration is the default at runtime.
51
+ */
52
+ declare function addConfigDefaultField(db: Knex, tableName: string): Promise<void>;
53
+ /**
54
+ * Adds deleted_at field for soft delete support.
55
+ * Called when entity has softDelete: true.
56
+ */
57
+ declare function addSoftDeleteFieldIfMissing(db: Knex, tableName: string): Promise<void>;
58
+ /**
59
+ * Adds a column if it does not exist
60
+ */
61
+ declare function addColumnIfMissing(db: Knex, tableName: string, columnName: string, columnBuilder: (table: Knex.AlterTableBuilder) => void): Promise<boolean>;
62
+
63
+ export { addAuditFieldsIfMissing, addColumnIfMissing, addConfigDefaultField, addSoftDeleteFieldIfMissing, addTimestamps, formatTimestamp, getDbClient, nowTimestamp, runAllGeneratedMigrations, runGeneratedMigration };