@mikro-orm/sql 7.1.1-dev.1 → 7.1.1-dev.11

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/sql",
3
- "version": "7.1.1-dev.1",
3
+ "version": "7.1.1-dev.11",
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.0"
54
54
  },
55
55
  "peerDependencies": {
56
- "@mikro-orm/core": "7.1.1-dev.1"
56
+ "@mikro-orm/core": "7.1.1-dev.11"
57
57
  },
58
58
  "engines": {
59
59
  "node": ">= 22.17.0"
@@ -1025,6 +1025,7 @@ export class DatabaseTable {
1025
1025
  };
1026
1026
  const optional = [
1027
1027
  'expression',
1028
+ 'where',
1028
1029
  'type',
1029
1030
  'deferMode',
1030
1031
  'columns',
@@ -977,6 +977,9 @@ export class SchemaComparator {
977
977
  from.default.toString().startsWith('nextval(')) {
978
978
  return to.default == null || to.default.toLowerCase() === 'null';
979
979
  }
980
+ if (to.default == null || to.default.toLowerCase() === 'null') {
981
+ return false;
982
+ }
980
983
  if (to.mappedType instanceof BooleanType) {
981
984
  const defaultValueFrom = !['0', 'false', 'f', 'n', 'no', 'off'].includes('' + from.default);
982
985
  const defaultValueTo = !['0', 'false', 'f', 'n', 'no', 'off'].includes('' + to.default);
@@ -490,10 +490,21 @@ export class SchemaHelper {
490
490
  }
491
491
  alterTableColumn(column, table, changedProperties) {
492
492
  const sql = [];
493
- if (changedProperties.has('default') && column.default == null) {
493
+ const typeChanged = changedProperties.has('type') || changedProperties.has('collation');
494
+ const defaultChanged = changedProperties.has('default');
495
+ // Postgres can't implicitly cast a stored DEFAULT across array element types
496
+ // (e.g. `'{}'::text[]` -> `numeric(3,2)[]`), so drop+re-set it around ALTER TYPE.
497
+ const fromColumn = typeChanged ? table.getColumn(column.name) : undefined;
498
+ const needsArrayDefaultRecast = typeChanged &&
499
+ fromColumn?.default != null &&
500
+ fromColumn.type.endsWith(']') &&
501
+ column.type.endsWith(']') &&
502
+ fromColumn.type !== column.type;
503
+ const recastDefault = needsArrayDefaultRecast && !defaultChanged;
504
+ if ((defaultChanged && column.default == null) || needsArrayDefaultRecast) {
494
505
  sql.push(`alter table ${table.getQuotedName()} alter column ${this.quote(column.name)} drop default`);
495
506
  }
496
- if (changedProperties.has('type') || changedProperties.has('collation')) {
507
+ if (typeChanged) {
497
508
  let type = column.type + (column.generated ? ` generated always as ${column.generated}` : '');
498
509
  if (column.nativeEnumName) {
499
510
  const parts = type.split('.');
@@ -508,7 +519,7 @@ export class SchemaHelper {
508
519
  const collateClause = column.collation ? ` ${this.getCollateSQL(column.collation)}` : '';
509
520
  sql.push(`alter table ${table.getQuotedName()} alter column ${this.quote(column.name)} type ${type + collateClause + this.castColumn(column.name, type)}`);
510
521
  }
511
- if (changedProperties.has('default') && column.default != null) {
522
+ if ((defaultChanged && column.default != null) || recastDefault) {
512
523
  sql.push(`alter table ${table.getQuotedName()} alter column ${this.quote(column.name)} set default ${column.default}`);
513
524
  }
514
525
  if (changedProperties.has('nullable')) {