@mikro-orm/sql 7.1.4-dev.0 → 7.1.4-dev.10
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/AbstractSqlDriver.js
CHANGED
|
@@ -494,7 +494,7 @@ export class AbstractSqlDriver extends DatabaseDriver {
|
|
|
494
494
|
if (prop.fieldNames.every(name => typeof root[`${relationAlias}__${name}`] === 'undefined')) {
|
|
495
495
|
return;
|
|
496
496
|
}
|
|
497
|
-
if (prop.polymorphic) {
|
|
497
|
+
if (prop.polymorphic && prop.kind !== ReferenceKind.EMBEDDED) {
|
|
498
498
|
const discriminatorAlias = `${relationAlias}__${prop.fieldNames[0]}`;
|
|
499
499
|
const discriminatorValue = root[discriminatorAlias];
|
|
500
500
|
const pkFieldNames = prop.fieldNames.slice(1);
|
|
@@ -486,10 +486,13 @@ export class PostgreSqlSchemaHelper extends SchemaHelper {
|
|
|
486
486
|
seen.add(dedupeKey);
|
|
487
487
|
ret[key] ??= [];
|
|
488
488
|
// CHECK: unwrap the `CHECK ((<predicate>))` shell and drop pg-added `::type` casts so the
|
|
489
|
-
// inner predicate matches the user's metadata.
|
|
490
|
-
//
|
|
489
|
+
// inner predicate matches the user's metadata. Bare boolean bodies (e.g. a top-level CASE)
|
|
490
|
+
// are emitted as the single-paren `CHECK (<predicate>)` form, which we unwrap too. EXCLUDE
|
|
491
|
+
// bodies are kept verbatim — the user's `@Check` expression is the full body (see
|
|
492
|
+
// SchemaHelper.createCheck).
|
|
491
493
|
const m = /^check \(\((.*)\)\)$/is.exec(check.expression);
|
|
492
|
-
const
|
|
494
|
+
const single = m ? null : /^check \((.*)\)$/is.exec(check.expression);
|
|
495
|
+
const def = m ? m[1].replace(/\((.*?)\)::\w+/g, '$1') : single ? single[1] : check.expression;
|
|
493
496
|
ret[key].push({
|
|
494
497
|
name: check.name,
|
|
495
498
|
columnName: check.column_name,
|
|
@@ -765,11 +768,11 @@ export class PostgreSqlSchemaHelper extends SchemaHelper {
|
|
|
765
768
|
}
|
|
766
769
|
async getNativeEnumDefinitions(connection, schemas, ctx) {
|
|
767
770
|
const uniqueSchemas = Utils.unique(schemas);
|
|
768
|
-
const res = await connection.execute(`select t.typname as enum_name, n.nspname as schema_name, array_agg(e.enumlabel order by e.enumsortorder) as enum_value
|
|
771
|
+
const res = await connection.execute(`select t.typname as enum_name, n.nspname as schema_name, array_remove(array_agg(e.enumlabel order by e.enumsortorder), null) as enum_value
|
|
769
772
|
from pg_type t
|
|
770
|
-
join pg_enum e on t.oid = e.enumtypid
|
|
773
|
+
left join pg_enum e on t.oid = e.enumtypid
|
|
771
774
|
join pg_catalog.pg_namespace n on n.oid = t.typnamespace
|
|
772
|
-
where n.nspname in (${Array(uniqueSchemas.length).fill('?').join(', ')})
|
|
775
|
+
where t.typtype = 'e' and n.nspname in (${Array(uniqueSchemas.length).fill('?').join(', ')})
|
|
773
776
|
group by t.typname, n.nspname`, uniqueSchemas, 'all', ctx);
|
|
774
777
|
return res.reduce((o, row) => {
|
|
775
778
|
let name = row.enum_name;
|
|
@@ -825,7 +828,9 @@ export class PostgreSqlSchemaHelper extends SchemaHelper {
|
|
|
825
828
|
// `CHECK ((("enumTest")::text = ANY ((ARRAY['a'::character varying, 'b'::character varying, 'c'::character varying])::text[])))`
|
|
826
829
|
// `CHECK ((type = 'a'::text))`
|
|
827
830
|
const m1 = item.definition?.match(/check \(\(\("?(\w+)"?\)::/i) || item.definition?.match(/check \(\("?(\w+)"? = /i);
|
|
828
|
-
|
|
831
|
+
// the single-value form must compare against a quoted literal (`= 'a'::text`); anything else
|
|
832
|
+
// (e.g. a JSON `->>` extraction like `name = data->>'name'`) is not an enum constraint
|
|
833
|
+
const m2 = item.definition?.match(/\(array\[(.*)]\)/i) || item.definition?.match(/ = ('(?:[^']|'')*'::[\w ]+)\)/i);
|
|
829
834
|
if (item.columnName && m1 && m2) {
|
|
830
835
|
/* v8 ignore next */
|
|
831
836
|
const parts = m2[1].match(/('(?:[^']|'')*'::\w[\w ]*)/g) ?? m2[1].split(',');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/sql",
|
|
3
|
-
"version": "7.1.4-dev.
|
|
3
|
+
"version": "7.1.4-dev.10",
|
|
4
4
|
"description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"data-mapper",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"@mikro-orm/core": "^7.1.3"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@mikro-orm/core": "7.1.4-dev.
|
|
56
|
+
"@mikro-orm/core": "7.1.4-dev.10"
|
|
57
57
|
},
|
|
58
58
|
"engines": {
|
|
59
59
|
"node": ">= 22.17.0"
|
package/plugin/transformer.js
CHANGED
|
@@ -323,7 +323,7 @@ export class MikroTransformer extends OperationNodeTransformer {
|
|
|
323
323
|
}
|
|
324
324
|
const newColumns = [...node.columns];
|
|
325
325
|
for (const prop of missingProps) {
|
|
326
|
-
newColumns.push(ColumnNode.create(prop.
|
|
326
|
+
newColumns.push(ColumnNode.create(prop.fieldNames[0]));
|
|
327
327
|
}
|
|
328
328
|
const newRows = node.values.values.map(row => {
|
|
329
329
|
const valuesToAdd = missingProps.map(prop => {
|
|
@@ -366,7 +366,7 @@ export class MikroTransformer extends OperationNodeTransformer {
|
|
|
366
366
|
const newUpdates = [...node.updates];
|
|
367
367
|
for (const prop of missingProps) {
|
|
368
368
|
const val = prop.onUpdate(undefined, this.#em);
|
|
369
|
-
newUpdates.push(ColumnUpdateNode.create(ColumnNode.create(prop.
|
|
369
|
+
newUpdates.push(ColumnUpdateNode.create(ColumnNode.create(prop.fieldNames[0]), ValueNode.create(val)));
|
|
370
370
|
}
|
|
371
371
|
return {
|
|
372
372
|
...node,
|