@mikro-orm/sql 7.1.4-dev.0 → 7.1.4-dev.2

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.
@@ -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. EXCLUDE bodies are kept verbatim — the user's
490
- // `@Check` expression is the full body (see SchemaHelper.createCheck).
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 def = m ? m[1].replace(/\((.*?)\)::\w+/g, '$1') : check.expression;
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
- const m2 = item.definition?.match(/\(array\[(.*)]\)/i) || item.definition?.match(/ = (.*)\)/i);
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.0",
3
+ "version": "7.1.4-dev.2",
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.0"
56
+ "@mikro-orm/core": "7.1.4-dev.2"
57
57
  },
58
58
  "engines": {
59
59
  "node": ">= 22.17.0"