orchid-orm 1.63.5 → 1.64.1
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/migrations/index.js +36 -34
- package/dist/migrations/index.js.map +1 -1
- package/dist/migrations/index.mjs +36 -34
- package/dist/migrations/index.mjs.map +1 -1
- package/dist/migrations/node-postgres.js +36 -34
- package/dist/migrations/node-postgres.js.map +1 -1
- package/dist/migrations/node-postgres.mjs +36 -34
- package/dist/migrations/node-postgres.mjs.map +1 -1
- package/dist/migrations/postgres-js.js +36 -34
- package/dist/migrations/postgres-js.js.map +1 -1
- package/dist/migrations/postgres-js.mjs +36 -34
- package/dist/migrations/postgres-js.mjs.map +1 -1
- package/package.json +5 -5
|
@@ -196,12 +196,12 @@ const renameSchemaInStructures = (items, from, to) => {
|
|
|
196
196
|
}
|
|
197
197
|
};
|
|
198
198
|
|
|
199
|
-
const processExtensions = (
|
|
199
|
+
const processExtensions = (ast, dbStructure, {
|
|
200
200
|
currentSchema,
|
|
201
201
|
internal: { extensions, generatorIgnore }
|
|
202
202
|
}) => {
|
|
203
203
|
const codeExtensions = extensions?.map((ext) => {
|
|
204
|
-
const [schema, name] = getSchemaAndTableFromName(
|
|
204
|
+
const [schema, name] = getSchemaAndTableFromName(currentSchema, ext.name);
|
|
205
205
|
return { schema, name, version: ext.version };
|
|
206
206
|
});
|
|
207
207
|
for (const dbExt of dbStructure.extensions) {
|
|
@@ -399,7 +399,6 @@ const changeColumns = async (adapter, config, structureToAstCtx, dbStructure, do
|
|
|
399
399
|
dbColumnStructure
|
|
400
400
|
);
|
|
401
401
|
const action = await compareColumns(
|
|
402
|
-
config,
|
|
403
402
|
adapter,
|
|
404
403
|
domainsMap,
|
|
405
404
|
ast,
|
|
@@ -437,13 +436,13 @@ const changeColumns = async (adapter, config, structureToAstCtx, dbStructure, do
|
|
|
437
436
|
}
|
|
438
437
|
}
|
|
439
438
|
};
|
|
440
|
-
const compareColumns = async (
|
|
439
|
+
const compareColumns = async (adapter, domainsMap, ast, currentSchema, compareSql, changeTableData, typeCastsCache, verifying, key, dbName, dbColumn, codeColumn) => {
|
|
441
440
|
if (dbColumn instanceof ArrayColumn && codeColumn instanceof ArrayColumn) {
|
|
442
441
|
dbColumn = dbColumn.data.item;
|
|
443
442
|
codeColumn = codeColumn.data.item;
|
|
444
443
|
}
|
|
445
|
-
const dbType = getColumnDbType(
|
|
446
|
-
const codeType = getColumnDbType(
|
|
444
|
+
const dbType = getColumnDbType(dbColumn, currentSchema);
|
|
445
|
+
const codeType = getColumnDbType(codeColumn, currentSchema);
|
|
447
446
|
if (dbType !== codeType) {
|
|
448
447
|
const typeCasts = await getTypeCasts(adapter, typeCastsCache);
|
|
449
448
|
const dbBaseType = getColumnBaseType(dbColumn, domainsMap, dbType);
|
|
@@ -601,10 +600,10 @@ const changeColumn = (changeTableData, key, dbName, dbColumn, codeColumn) => {
|
|
|
601
600
|
to: { column: simpleCodeColumn }
|
|
602
601
|
};
|
|
603
602
|
};
|
|
604
|
-
const getColumnDbType = (
|
|
603
|
+
const getColumnDbType = (column, currentSchema) => {
|
|
605
604
|
if (column instanceof EnumColumn) {
|
|
606
605
|
const [schema = currentSchema, name] = getSchemaAndTableFromName(
|
|
607
|
-
|
|
606
|
+
currentSchema,
|
|
608
607
|
column.enumName
|
|
609
608
|
);
|
|
610
609
|
return `${schema}.${name}`;
|
|
@@ -632,7 +631,7 @@ const renameColumn = (columns, from, to) => {
|
|
|
632
631
|
}
|
|
633
632
|
};
|
|
634
633
|
|
|
635
|
-
const processDomains = async (
|
|
634
|
+
const processDomains = async (ast, adapter, domainsMap, dbStructure, {
|
|
636
635
|
codeItems: { domains },
|
|
637
636
|
structureToAstCtx,
|
|
638
637
|
currentSchema,
|
|
@@ -642,7 +641,7 @@ const processDomains = async (config, ast, adapter, domainsMap, dbStructure, {
|
|
|
642
641
|
if (domains) {
|
|
643
642
|
for (const { schemaName, name, column } of domains) {
|
|
644
643
|
codeDomains.push(
|
|
645
|
-
makeComparableDomain(
|
|
644
|
+
makeComparableDomain(currentSchema, schemaName, name, column)
|
|
646
645
|
);
|
|
647
646
|
}
|
|
648
647
|
}
|
|
@@ -678,7 +677,6 @@ const processDomains = async (config, ast, adapter, domainsMap, dbStructure, {
|
|
|
678
677
|
}));
|
|
679
678
|
}
|
|
680
679
|
const dbDomain = makeComparableDomain(
|
|
681
|
-
config,
|
|
682
680
|
currentSchema,
|
|
683
681
|
domain.schemaName,
|
|
684
682
|
domain.name,
|
|
@@ -695,7 +693,6 @@ const processDomains = async (config, ast, adapter, domainsMap, dbStructure, {
|
|
|
695
693
|
pushCompareDefault(compare, domain, found);
|
|
696
694
|
pushCompareChecks(compare, domain, found);
|
|
697
695
|
const source = `(VALUES (NULL::${getColumnDbType(
|
|
698
|
-
config,
|
|
699
696
|
dbColumn,
|
|
700
697
|
currentSchema
|
|
701
698
|
)})) t(value)`;
|
|
@@ -749,7 +746,7 @@ const processDomains = async (config, ast, adapter, domainsMap, dbStructure, {
|
|
|
749
746
|
}
|
|
750
747
|
}
|
|
751
748
|
};
|
|
752
|
-
const makeComparableDomain = (
|
|
749
|
+
const makeComparableDomain = (currentSchema, schemaName, name, column) => {
|
|
753
750
|
let arrayDims = 0;
|
|
754
751
|
const isNullable = column.data.isNullable ?? false;
|
|
755
752
|
let inner = column;
|
|
@@ -757,9 +754,9 @@ const makeComparableDomain = (config, currentSchema, schemaName, name, column) =
|
|
|
757
754
|
inner = inner.data.item;
|
|
758
755
|
arrayDims++;
|
|
759
756
|
}
|
|
760
|
-
const fullType = getColumnDbType(
|
|
757
|
+
const fullType = getColumnDbType(inner, currentSchema);
|
|
761
758
|
const [typeSchema = "pg_catalog", type] = getSchemaAndTableFromName(
|
|
762
|
-
|
|
759
|
+
currentSchema,
|
|
763
760
|
fullType
|
|
764
761
|
);
|
|
765
762
|
return {
|
|
@@ -1667,7 +1664,7 @@ const fnOrTableToString = (fnOrTable) => {
|
|
|
1667
1664
|
};
|
|
1668
1665
|
const parseForeignKey = (config, codeConstraint, references, currentSchema) => {
|
|
1669
1666
|
const { fnOrTable, columns, foreignColumns, options } = references;
|
|
1670
|
-
const [schema, table] = getSchemaAndTableFromName(
|
|
1667
|
+
const [schema, table] = getSchemaAndTableFromName(currentSchema, fnOrTable);
|
|
1671
1668
|
return {
|
|
1672
1669
|
references: {
|
|
1673
1670
|
foreignSchema: schema ?? currentSchema,
|
|
@@ -1853,6 +1850,7 @@ const processTables = async (ast, domainsMap, adapter, dbStructure, config, {
|
|
|
1853
1850
|
const compareSql = { values: [], expressions: [] };
|
|
1854
1851
|
const tableExpressions = [];
|
|
1855
1852
|
const { changeTables, changeTableSchemas, dropTables, tableShapes } = collectChangeAndDropTables(
|
|
1853
|
+
adapter,
|
|
1856
1854
|
config,
|
|
1857
1855
|
tables,
|
|
1858
1856
|
dbStructure,
|
|
@@ -1908,19 +1906,19 @@ const collectCreateTables = (tables, dbStructure, currentSchema) => {
|
|
|
1908
1906
|
return acc;
|
|
1909
1907
|
}, []);
|
|
1910
1908
|
};
|
|
1911
|
-
const collectChangeAndDropTables = (config, tables, dbStructure, currentSchema, createTables, generatorIgnore) => {
|
|
1909
|
+
const collectChangeAndDropTables = (adapter, config, tables, dbStructure, currentSchema, createTables, generatorIgnore) => {
|
|
1912
1910
|
const changeTables = [];
|
|
1913
1911
|
const changeTableSchemas = [];
|
|
1914
1912
|
const dropTables = [];
|
|
1915
1913
|
const tableShapes = {};
|
|
1916
1914
|
const ignoreTables = generatorIgnore?.tables?.map((name) => {
|
|
1917
1915
|
const [schema = currentSchema, table] = getSchemaAndTableFromName(
|
|
1918
|
-
|
|
1916
|
+
currentSchema,
|
|
1919
1917
|
name
|
|
1920
1918
|
);
|
|
1921
1919
|
return { schema, table };
|
|
1922
1920
|
});
|
|
1923
|
-
const { schema: migrationsSchema = "public", table: migrationsTable } = getMigrationsSchemaAndTable(config);
|
|
1921
|
+
const { schema: migrationsSchema = "public", table: migrationsTable } = getMigrationsSchemaAndTable(adapter, config);
|
|
1924
1922
|
for (const dbTable of dbStructure.tables) {
|
|
1925
1923
|
if (dbTable.name === migrationsTable && dbTable.schemaName === migrationsSchema || generatorIgnore?.schemas?.includes(dbTable.schemaName) || ignoreTables?.some(
|
|
1926
1924
|
({ schema, table }) => table === dbTable.name && schema === dbTable.schemaName
|
|
@@ -2178,10 +2176,9 @@ const composeMigration = async (adapter, config, ast, dbStructure, params) => {
|
|
|
2178
2176
|
const { structureToAstCtx, currentSchema } = params;
|
|
2179
2177
|
const domainsMap = makeDomainsMap(structureToAstCtx, dbStructure);
|
|
2180
2178
|
await processSchemas(ast, dbStructure, params);
|
|
2181
|
-
processExtensions(
|
|
2179
|
+
processExtensions(ast, dbStructure, params);
|
|
2182
2180
|
const pendingDbTypes = new PendingDbTypes();
|
|
2183
2181
|
await processDomains(
|
|
2184
|
-
config,
|
|
2185
2182
|
ast,
|
|
2186
2183
|
adapter,
|
|
2187
2184
|
domainsMap,
|
|
@@ -2207,7 +2204,7 @@ const verifyMigration = async (adapter, config, migrationCode, generateMigration
|
|
|
2207
2204
|
const migrationFn = new Function("change", migrationCode);
|
|
2208
2205
|
let code;
|
|
2209
2206
|
try {
|
|
2210
|
-
await adapter.transaction(
|
|
2207
|
+
await adapter.transaction(async (trx) => {
|
|
2211
2208
|
const changeFns = [];
|
|
2212
2209
|
migrationFn((changeCb) => {
|
|
2213
2210
|
changeFns.push(changeCb);
|
|
@@ -2324,7 +2321,7 @@ const report = (ast, config, currentSchema) => {
|
|
|
2324
2321
|
const column = change.item;
|
|
2325
2322
|
const { primaryKey, indexes, excludes, foreignKeys, checks } = column.data;
|
|
2326
2323
|
inner.push(
|
|
2327
|
-
`${change.type === "add" ? green("+ add column") : red("- drop column")} ${key} ${column.data.alias ?? getColumnDbType(
|
|
2324
|
+
`${change.type === "add" ? green("+ add column") : red("- drop column")} ${key} ${column.data.alias ?? getColumnDbType(column, currentSchema)}${column.data.isNullable ? " nullable" : ""}${primaryKey ? " primary key" : ""}${foreignKeys ? ` references ${foreignKeys.map((fk) => {
|
|
2328
2325
|
return `${fnOrTableToString(
|
|
2329
2326
|
fk.fnOrTable
|
|
2330
2327
|
)}(${fk.foreignColumns.join(", ")})`;
|
|
@@ -2385,7 +2382,7 @@ const report = (ast, config, currentSchema) => {
|
|
|
2385
2382
|
for (const { references } of a.drop.constraints) {
|
|
2386
2383
|
if (!references) continue;
|
|
2387
2384
|
const [schema, name] = getSchemaAndTableFromName(
|
|
2388
|
-
|
|
2385
|
+
currentSchema,
|
|
2389
2386
|
references.fnOrTable
|
|
2390
2387
|
);
|
|
2391
2388
|
inner.push(
|
|
@@ -2541,6 +2538,10 @@ const report = (ast, config, currentSchema) => {
|
|
|
2541
2538
|
);
|
|
2542
2539
|
break;
|
|
2543
2540
|
}
|
|
2541
|
+
case "role":
|
|
2542
|
+
case "changeRole": {
|
|
2543
|
+
break;
|
|
2544
|
+
}
|
|
2544
2545
|
default:
|
|
2545
2546
|
exhaustive(a);
|
|
2546
2547
|
}
|
|
@@ -2576,11 +2577,11 @@ const generate = async (adapters, config, args, afterPull) => {
|
|
|
2576
2577
|
afterPull
|
|
2577
2578
|
);
|
|
2578
2579
|
const [adapter] = adapters;
|
|
2579
|
-
const
|
|
2580
|
+
const adapterSchema = adapter.getSchema();
|
|
2581
|
+
const currentSchema = (typeof adapterSchema === "function" ? adapterSchema() : adapterSchema) ?? "public";
|
|
2580
2582
|
const db = await getDbFromConfig(config, dbPath);
|
|
2581
2583
|
const { columnTypes, internal } = db.$qb;
|
|
2582
2584
|
const codeItems = await getActualItems(
|
|
2583
|
-
config,
|
|
2584
2585
|
db,
|
|
2585
2586
|
currentSchema,
|
|
2586
2587
|
internal,
|
|
@@ -2737,7 +2738,7 @@ const compareDbStructures = (a, b, i, path2) => {
|
|
|
2737
2738
|
throw new Error(`${path2} in the db 0 does not match db ${i}`);
|
|
2738
2739
|
}
|
|
2739
2740
|
};
|
|
2740
|
-
const getActualItems = async (
|
|
2741
|
+
const getActualItems = async (db, currentSchema, internal, columnTypes) => {
|
|
2741
2742
|
const tableNames = /* @__PURE__ */ new Set();
|
|
2742
2743
|
const habtmTables = /* @__PURE__ */ new Map();
|
|
2743
2744
|
const codeItems = {
|
|
@@ -2780,7 +2781,7 @@ const getActualItems = async (config, db, currentSchema, internal, columnTypes)
|
|
|
2780
2781
|
delete table.shape[key2];
|
|
2781
2782
|
} else if (column instanceof DomainColumn) {
|
|
2782
2783
|
const [schemaName = currentSchema, name2] = getSchemaAndTableFromName(
|
|
2783
|
-
|
|
2784
|
+
currentSchema,
|
|
2784
2785
|
column.dataType
|
|
2785
2786
|
);
|
|
2786
2787
|
domains.set(column.dataType, {
|
|
@@ -2791,21 +2792,21 @@ const getActualItems = async (config, db, currentSchema, internal, columnTypes)
|
|
|
2791
2792
|
} else {
|
|
2792
2793
|
const en = column.dataType === "enum" ? column : column instanceof ArrayColumn && column.data.item.dataType === "enum" ? column.data.item : void 0;
|
|
2793
2794
|
if (en) {
|
|
2794
|
-
processEnumColumn(
|
|
2795
|
+
processEnumColumn(en, currentSchema, codeItems);
|
|
2795
2796
|
}
|
|
2796
2797
|
}
|
|
2797
2798
|
}
|
|
2798
2799
|
}
|
|
2799
2800
|
if (internal.extensions) {
|
|
2800
2801
|
for (const extension of internal.extensions) {
|
|
2801
|
-
const [schema] = getSchemaAndTableFromName(
|
|
2802
|
+
const [schema] = getSchemaAndTableFromName(currentSchema, extension.name);
|
|
2802
2803
|
if (schema) codeItems.schemas.add(schema);
|
|
2803
2804
|
}
|
|
2804
2805
|
}
|
|
2805
2806
|
if (internal.domains) {
|
|
2806
2807
|
for (const key in internal.domains) {
|
|
2807
2808
|
const [schemaName = currentSchema, name] = getSchemaAndTableFromName(
|
|
2808
|
-
|
|
2809
|
+
currentSchema,
|
|
2809
2810
|
key
|
|
2810
2811
|
);
|
|
2811
2812
|
const column = internal.domains[key](columnTypes);
|
|
@@ -2822,9 +2823,9 @@ const getActualItems = async (config, db, currentSchema, internal, columnTypes)
|
|
|
2822
2823
|
}
|
|
2823
2824
|
return codeItems;
|
|
2824
2825
|
};
|
|
2825
|
-
const processEnumColumn = (
|
|
2826
|
+
const processEnumColumn = (column, currentSchema, codeItems) => {
|
|
2826
2827
|
const { enumName, options } = column;
|
|
2827
|
-
const [schema, name] = getSchemaAndTableFromName(
|
|
2828
|
+
const [schema, name] = getSchemaAndTableFromName(currentSchema, enumName);
|
|
2828
2829
|
const enumSchema = schema ?? currentSchema;
|
|
2829
2830
|
codeItems.enums.set(`${enumSchema}.${name}`, {
|
|
2830
2831
|
schema: enumSchema,
|
|
@@ -3168,7 +3169,8 @@ const pull = async (adapters, config) => {
|
|
|
3168
3169
|
const baseTablePath = config.baseTable.getFilePath();
|
|
3169
3170
|
const baseTableExportedAs = config.baseTable.exportAs;
|
|
3170
3171
|
const [adapter] = adapters;
|
|
3171
|
-
const
|
|
3172
|
+
const adapterSchema = adapter.getSchema();
|
|
3173
|
+
const currentSchema = (typeof adapterSchema === "function" ? adapterSchema() : adapterSchema) ?? "public";
|
|
3172
3174
|
const ctx = makeStructureToAstCtx(config, currentSchema);
|
|
3173
3175
|
const asts = await structureToAst(ctx, adapter, config);
|
|
3174
3176
|
const { tableInfos, fkeys } = getTableInfosAndFKeys(asts, config);
|