orchid-orm 1.72.8 → 1.72.9
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/dist/index.d.ts +13 -0
- package/dist/index.js +25 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +25 -10
- package/dist/index.mjs.map +1 -1
- package/dist/migrations/index.js +44 -4
- package/dist/migrations/index.js.map +1 -1
- package/dist/migrations/index.mjs +45 -5
- package/dist/migrations/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/migrations/index.js
CHANGED
|
@@ -28,6 +28,14 @@ let node_fs_promises = require("node:fs/promises");
|
|
|
28
28
|
node_fs_promises = __toESM(node_fs_promises);
|
|
29
29
|
let typescript = require("typescript");
|
|
30
30
|
typescript = __toESM(typescript);
|
|
31
|
+
const viewDataToSql = (viewData, viewName) => {
|
|
32
|
+
return (0, pqb_internal.sqlToRawSql)(viewDataToQuerySql(viewData, viewName));
|
|
33
|
+
};
|
|
34
|
+
const viewDataToQuerySql = (viewData, viewName) => {
|
|
35
|
+
if (viewData.query) return (0, pqb_internal.queryToSql)(viewData.query);
|
|
36
|
+
if (viewData.sql !== void 0) return (0, pqb_internal.rawSqlToSql)(viewData.sql);
|
|
37
|
+
throw new Error(`Either sql or query is required for view ${viewName}`);
|
|
38
|
+
};
|
|
31
39
|
const compareSqlExpressions = async (expressions, adapter) => {
|
|
32
40
|
if (!expressions.length) return;
|
|
33
41
|
let id = 1;
|
|
@@ -1748,6 +1756,7 @@ const processTables = async (ast, domainsMap, adapter, dbStructure, config, { st
|
|
|
1748
1756
|
};
|
|
1749
1757
|
const collectCreateTables = (tables, dbStructure, currentSchema) => {
|
|
1750
1758
|
return tables.reduce((acc, codeTable) => {
|
|
1759
|
+
if (codeTable.internal.generatorIgnored) return acc;
|
|
1751
1760
|
const tableSchema = codeTable.q.schema ?? currentSchema;
|
|
1752
1761
|
if (!dbStructure.tables.some((t) => t.name === codeTable.table && t.schemaName === tableSchema)) acc.push(codeTable);
|
|
1753
1762
|
return acc;
|
|
@@ -1767,7 +1776,7 @@ const collectChangeAndDropTables = (adapter, config, tables, dbStructure, curren
|
|
|
1767
1776
|
});
|
|
1768
1777
|
const { schema: migrationsSchema = "public", table: migrationsTable } = (0, rake_db.getMigrationsSchemaAndTable)(adapter, config);
|
|
1769
1778
|
for (const dbTable of dbStructure.tables) {
|
|
1770
|
-
if (dbTable.name === migrationsTable && dbTable.schemaName === migrationsSchema || generatorIgnore?.schemas?.includes(dbTable.schemaName) || ignoreTables?.some(({ schema, table }) => table === dbTable.name && schema === dbTable.schemaName)) continue;
|
|
1779
|
+
if (dbTable.name === migrationsTable && dbTable.schemaName === migrationsSchema || generatorIgnore?.schemas?.includes(dbTable.schemaName) || ignoreTables?.some(({ schema, table }) => table === dbTable.name && schema === dbTable.schemaName) || isDefinitionIgnoredDbTable(tables, dbTable, currentSchema)) continue;
|
|
1771
1780
|
const codeTable = tables.find((t) => t.table === dbTable.name && (t.q.schema ?? currentSchema) === dbTable.schemaName);
|
|
1772
1781
|
if (codeTable) {
|
|
1773
1782
|
addChangeTable(dbStructure, changeTables, tableShapes, currentSchema, dbTable, codeTable);
|
|
@@ -1792,6 +1801,15 @@ const collectChangeAndDropTables = (adapter, config, tables, dbStructure, curren
|
|
|
1792
1801
|
tableShapes
|
|
1793
1802
|
};
|
|
1794
1803
|
};
|
|
1804
|
+
const isDefinitionIgnoredDbTable = (tables, dbTable, currentSchema) => {
|
|
1805
|
+
let hasIgnoredSameName = false;
|
|
1806
|
+
for (const codeTable of tables) {
|
|
1807
|
+
if (codeTable.table !== dbTable.name) continue;
|
|
1808
|
+
if ((codeTable.q.schema ?? currentSchema) === dbTable.schemaName) return !!codeTable.internal.generatorIgnored;
|
|
1809
|
+
if (codeTable.internal.generatorIgnored) hasIgnoredSameName = true;
|
|
1810
|
+
}
|
|
1811
|
+
return hasIgnoredSameName;
|
|
1812
|
+
};
|
|
1795
1813
|
const applyChangeTableSchemas = (changeTableSchemas, currentSchema, ast) => {
|
|
1796
1814
|
for (const { codeTable, dbTable } of changeTableSchemas) {
|
|
1797
1815
|
const fromSchema = dbTable.schemaName;
|
|
@@ -2576,7 +2594,7 @@ const pushRecreateView$1 = (ast, from, to) => {
|
|
|
2576
2594
|
};
|
|
2577
2595
|
const codeViewToAst$1 = (view, currentSchema, action) => {
|
|
2578
2596
|
const schema = view.q.schema ?? currentSchema;
|
|
2579
|
-
const sql =
|
|
2597
|
+
const sql = viewDataToSql(view.viewData, view.name);
|
|
2580
2598
|
return {
|
|
2581
2599
|
type: "view",
|
|
2582
2600
|
action,
|
|
@@ -2714,7 +2732,7 @@ const pushRecreateView = (ast, from, to) => {
|
|
|
2714
2732
|
};
|
|
2715
2733
|
const codeViewToAst = (view, currentSchema, action) => {
|
|
2716
2734
|
const schema = view.q.schema ?? currentSchema;
|
|
2717
|
-
const sql =
|
|
2735
|
+
const sql = viewDataToSql(view.viewData, view.name);
|
|
2718
2736
|
return {
|
|
2719
2737
|
type: "materializedView",
|
|
2720
2738
|
action,
|
|
@@ -3159,6 +3177,7 @@ const generate = async (adapters, config, args, afterPull) => {
|
|
|
3159
3177
|
const adapterSchema = adapter.getSchema();
|
|
3160
3178
|
const currentSchema = (typeof adapterSchema === "function" ? adapterSchema() : adapterSchema) ?? "public";
|
|
3161
3179
|
const codeItems = await getActualItems(db, currentSchema, internal, columnTypes);
|
|
3180
|
+
const generatorIgnore = getGeneratorIgnoreWithDefinitionIgnoredTableLikes(internal.generatorIgnore, codeItems.tables, codeItems.views);
|
|
3162
3181
|
const effectiveGrants = getEffectiveGrants(internal.grants, codeItems);
|
|
3163
3182
|
const generateMigrationParams = {
|
|
3164
3183
|
structureToAstCtx: (0, rake_db.makeStructureToAstCtx)(config, currentSchema),
|
|
@@ -3166,6 +3185,7 @@ const generate = async (adapters, config, args, afterPull) => {
|
|
|
3166
3185
|
currentSchema,
|
|
3167
3186
|
internal: {
|
|
3168
3187
|
...internal,
|
|
3188
|
+
generatorIgnore,
|
|
3169
3189
|
grants: effectiveGrants
|
|
3170
3190
|
}
|
|
3171
3191
|
};
|
|
@@ -3288,6 +3308,26 @@ const getEffectiveGrants = (grants, codeItems) => {
|
|
|
3288
3308
|
}
|
|
3289
3309
|
return effectiveGrants.length ? effectiveGrants : void 0;
|
|
3290
3310
|
};
|
|
3311
|
+
const getGeneratorIgnoreWithDefinitionIgnoredTableLikes = (generatorIgnore, tables, views) => {
|
|
3312
|
+
const ignoredTables = new Set(generatorIgnore?.tables);
|
|
3313
|
+
const ignoredViews = new Set(generatorIgnore?.views);
|
|
3314
|
+
let hasDefinitionIgnoredTableLikes = false;
|
|
3315
|
+
for (const table of tables) {
|
|
3316
|
+
if (!table.internal.generatorIgnored) continue;
|
|
3317
|
+
hasDefinitionIgnoredTableLikes = true;
|
|
3318
|
+
ignoredTables.add(table.q.schema ? `${table.q.schema}.${table.table}` : table.table);
|
|
3319
|
+
}
|
|
3320
|
+
for (const view of views) {
|
|
3321
|
+
if (!view.internal.generatorIgnored) continue;
|
|
3322
|
+
hasDefinitionIgnoredTableLikes = true;
|
|
3323
|
+
ignoredViews.add(view.q.schema ? `${view.q.schema}.${view.name}` : view.name);
|
|
3324
|
+
}
|
|
3325
|
+
return hasDefinitionIgnoredTableLikes ? {
|
|
3326
|
+
...generatorIgnore,
|
|
3327
|
+
tables: [...ignoredTables],
|
|
3328
|
+
views: [...ignoredViews]
|
|
3329
|
+
} : generatorIgnore;
|
|
3330
|
+
};
|
|
3291
3331
|
const compareDbStructures = (a, b, i, path) => {
|
|
3292
3332
|
let err;
|
|
3293
3333
|
if (typeof a !== typeof b) err = true;
|
|
@@ -3330,7 +3370,7 @@ const getActualItems = async (db, currentSchema, internal, columnTypes) => {
|
|
|
3330
3370
|
},
|
|
3331
3371
|
q: { schema: (0, pqb_internal.getQuerySchema)(table) }
|
|
3332
3372
|
});
|
|
3333
|
-
for (const key in table.relations) {
|
|
3373
|
+
if (!table.internal.generatorIgnored) for (const key in table.relations) {
|
|
3334
3374
|
const column = table.shape[key];
|
|
3335
3375
|
if (column && "joinTable" in column) processHasAndBelongsToManyColumn(column, habtmTables, codeItems);
|
|
3336
3376
|
}
|