orchid-orm 1.50.4 → 1.51.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.
- package/dist/index.d.ts +10 -22
- package/dist/index.js +18 -15
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +18 -15
- package/dist/index.mjs.map +1 -1
- package/dist/migrations.js +8 -6
- package/dist/migrations.js.map +1 -1
- package/dist/migrations.mjs +9 -7
- package/dist/migrations.mjs.map +1 -1
- package/package.json +5 -5
package/dist/migrations.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { promptSelect, colors, getSchemaAndTableFromName, getDbTableColumnsChecks, dbColumnToAst, instantiateDbColumn, concatSchemaAndName, encodeColumnDefault, getIndexName, getExcludeName, getConstraintName, tableToAst, getDbStructureTableData, makeDomainsMap, astToMigration, createMigrationInterface, introspectDbSchema, exhaustive, pluralize, makeStructureToAstCtx, makeFileVersion, writeMigrationFile, migrate, structureToAst, saveMigratedVersion, rakeDbCommands } from 'rake-db';
|
|
2
2
|
export * from 'rake-db';
|
|
3
|
-
import { toSnakeCase, deepCompare, emptyArray, toArray, addCode, codeToString,
|
|
3
|
+
import { toSnakeCase, deepCompare, emptyArray, toArray, toCamelCase, addCode, codeToString, toPascalCase, getImportPath, singleQuote, quoteObjectKey, pathToLog } from 'orchid-core';
|
|
4
4
|
import { EnumColumn, ArrayColumn, getColumnBaseType, RawSQL, VirtualColumn, DomainColumn, UnknownColumn, defaultSchemaConfig, columnsShapeToCode, pushTableDataCode, Adapter } from 'pqb';
|
|
5
5
|
import path from 'node:path';
|
|
6
6
|
import { pathToFileURL } from 'url';
|
|
@@ -2275,7 +2275,8 @@ const report = (ast, config, currentSchema) => {
|
|
|
2275
2275
|
}).join(", ")}` : ""}${indexes?.length ? indexes.length === 1 ? ", has index" : `, has ${indexes.length} indexes` : ""}${excludes?.length ? excludes.length === 1 ? ", has exclude" : `, has ${excludes.length} excludes` : ""}${checks?.length ? `, checks ${checks.map((check) => check.sql.toSQL({ values: [] })).join(", ")}` : ""}`
|
|
2276
2276
|
);
|
|
2277
2277
|
} else if (change.type === "change") {
|
|
2278
|
-
|
|
2278
|
+
let name = change.from.column?.data.name ?? key;
|
|
2279
|
+
if (config.snakeCase) name = toCamelCase(name);
|
|
2279
2280
|
const changes2 = [];
|
|
2280
2281
|
inner.push(`${yellow("~ change column")} ${name}:`, changes2);
|
|
2281
2282
|
changes2.push(`${yellow("from")}: `);
|
|
@@ -2290,7 +2291,7 @@ const report = (ast, config, currentSchema) => {
|
|
|
2290
2291
|
}
|
|
2291
2292
|
} else if (change.type === "rename") {
|
|
2292
2293
|
inner.push(
|
|
2293
|
-
`${yellow("~ rename column")} ${key} ${yellow("=>")} ${change.name}`
|
|
2294
|
+
`${yellow("~ rename column")} ${config.snakeCase ? toCamelCase(key) : key} ${yellow("=>")} ${change.name}`
|
|
2294
2295
|
);
|
|
2295
2296
|
} else {
|
|
2296
2297
|
exhaustive(change.type);
|
|
@@ -2513,7 +2514,7 @@ const generate = async (options, config, args, afterPull) => {
|
|
|
2513
2514
|
const [adapter] = adapters;
|
|
2514
2515
|
const currentSchema = adapter.schema ?? "public";
|
|
2515
2516
|
const db = await getDbFromConfig(config, dbPath);
|
|
2516
|
-
const { columnTypes, internal } = db.$
|
|
2517
|
+
const { columnTypes, internal } = db.$qb;
|
|
2517
2518
|
const codeItems = await getActualItems(
|
|
2518
2519
|
db,
|
|
2519
2520
|
currentSchema,
|
|
@@ -2598,7 +2599,7 @@ const getDbFromConfig = async (config, dbPath) => {
|
|
|
2598
2599
|
pathToFileURL(path.resolve(config.basePath, dbPath)).toString()
|
|
2599
2600
|
);
|
|
2600
2601
|
const db = module[config.dbExportedAs ?? "db"];
|
|
2601
|
-
if (!db?.$
|
|
2602
|
+
if (!db?.$qb) {
|
|
2602
2603
|
throw new Error(
|
|
2603
2604
|
`Unable to import OrchidORM instance as ${config.dbExportedAs ?? "db"} from ${config.dbPath}`
|
|
2604
2605
|
);
|
|
@@ -2943,7 +2944,7 @@ const appCodeGenUpdateDbFile = async (dbPath, tables, extensions, domains, curre
|
|
|
2943
2944
|
if (extensions.length) {
|
|
2944
2945
|
code += `
|
|
2945
2946
|
extensions: [${extensions.map(
|
|
2946
|
-
(ext) => ext.version ? `{ ${quoteObjectKey(ext.name)}: '${ext.version}' }` : singleQuote(ext.name)
|
|
2947
|
+
(ext) => ext.version ? `{ ${quoteObjectKey(ext.name, false)}: '${ext.version}' }` : singleQuote(ext.name)
|
|
2947
2948
|
).join(", ")}],`;
|
|
2948
2949
|
}
|
|
2949
2950
|
if (domains.length) {
|
|
@@ -2951,7 +2952,8 @@ const appCodeGenUpdateDbFile = async (dbPath, tables, extensions, domains, curre
|
|
|
2951
2952
|
domains: {
|
|
2952
2953
|
${domains.sort((a, b) => a.name > b.name ? 1 : -1).map(
|
|
2953
2954
|
(ast) => `${quoteObjectKey(
|
|
2954
|
-
ast.schema ? `${ast.schema}.${ast.name}` : ast.name
|
|
2955
|
+
ast.schema ? `${ast.schema}.${ast.name}` : ast.name,
|
|
2956
|
+
false
|
|
2955
2957
|
)}: (t) => ${ast.baseType.toCode(
|
|
2956
2958
|
{ t: "t", table: ast.name, currentSchema },
|
|
2957
2959
|
ast.baseType.data.name ?? ""
|