@mikro-orm/mssql 7.1.0-dev.21 → 7.1.0-dev.23

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.
@@ -30,6 +30,7 @@ export declare class MsSqlSchemaHelper extends SchemaHelper {
30
30
  /** Generates SQL to drop an MSSQL trigger. */
31
31
  dropTrigger(table: DatabaseTable, trigger: SqlTriggerDef): string;
32
32
  private getSchemaQualifiedName;
33
+ getDatabaseCollation(connection: AbstractSqlConnection, ctx?: Transaction): Promise<string | undefined>;
33
34
  getAllTriggers(connection: AbstractSqlConnection, tablesBySchemas: Map<string | undefined, Table[]>): Promise<Dictionary<SqlTriggerDef[]>>;
34
35
  loadInformationSchema(schema: DatabaseSchema, connection: AbstractSqlConnection, tables: Table[], schemas?: string[], ctx?: Transaction): Promise<void>;
35
36
  getPreAlterTable(tableDiff: TableDifference, safe: boolean): string[];
@@ -114,7 +114,8 @@ export class MsSqlSchemaHelper extends SchemaHelper {
114
114
  numeric_scale as numeric_scale,
115
115
  datetime_precision as datetime_precision,
116
116
  character_maximum_length as character_maximum_length,
117
- columnproperty(sc.object_id, column_name, 'IsIdentity') is_identity
117
+ columnproperty(sc.object_id, column_name, 'IsIdentity') is_identity,
118
+ nullif(ic.collation_name, convert(nvarchar(128), databasepropertyex(db_name(), 'Collation'))) as collation_name
118
119
  from information_schema.columns ic
119
120
  inner join sys.columns sc on sc.name = ic.column_name and sc.object_id = object_id(ic.table_schema + '.' + ic.table_name)
120
121
  left join sys.computed_columns cmp on cmp.name = ic.column_name and cmp.object_id = object_id(ic.table_schema + '.' + ic.table_name)
@@ -166,6 +167,7 @@ export class MsSqlSchemaHelper extends SchemaHelper {
166
167
  precision: col.numeric_precision,
167
168
  scale: col.numeric_scale,
168
169
  comment: col.column_comment,
170
+ collation: col.collation_name ?? undefined,
169
171
  generated,
170
172
  });
171
173
  }
@@ -358,6 +360,10 @@ export class MsSqlSchemaHelper extends SchemaHelper {
358
360
  }
359
361
  return this.quote(name);
360
362
  }
363
+ async getDatabaseCollation(connection, ctx) {
364
+ const [row] = await connection.execute(`select convert(nvarchar(128), databasepropertyex(db_name(), 'Collation')) as collation`, [], 'all', ctx);
365
+ return row?.collation;
366
+ }
361
367
  async getAllTriggers(connection, tablesBySchemas) {
362
368
  const conditions = [];
363
369
  for (const [schema, tables] of tablesBySchemas) {
@@ -419,9 +425,11 @@ export class MsSqlSchemaHelper extends SchemaHelper {
419
425
  const checks = await this.getAllChecks(connection, tablesBySchema, ctx);
420
426
  const fks = await this.getAllForeignKeys(connection, tablesBySchema, ctx);
421
427
  const triggers = await this.getAllTriggers(connection, tablesBySchema);
428
+ const dbCollation = await this.getDatabaseCollation(connection, ctx);
422
429
  for (const t of tables) {
423
430
  const key = this.getTableKey(t);
424
431
  const table = schema.addTable(t.table_name, t.schema_name, t.table_comment);
432
+ table.collation = dbCollation;
425
433
  const pks = await this.getPrimaryKeys(connection, indexes[key], table.name, table.schema);
426
434
  const enums = this.getEnumDefinitions(checks[key] ?? []);
427
435
  table.init(columns[key], indexes[key], checks[key], pks, fks[key], enums);
@@ -543,7 +551,11 @@ export class MsSqlSchemaHelper extends SchemaHelper {
543
551
  else {
544
552
  col.push(columnType);
545
553
  }
546
- Utils.runIfNotEmpty(() => col.push('identity(1,1)'), column.autoincrement);
554
+ Utils.runIfNotEmpty(() => col.push(this.getCollateSQL(column.collation)), column.collation);
555
+ // `IDENTITY(1,1)` is rejected inside `ALTER COLUMN`, so it must only be emitted when the
556
+ // change actually involves the identity attribute or is a fresh column (no `changedProperties`).
557
+ Utils.runIfNotEmpty(() => col.push('identity(1,1)'), column.autoincrement &&
558
+ (!changedProperties || changedProperties.has('autoincrement') || changedProperties.has('type')));
547
559
  Utils.runIfNotEmpty(() => col.push('null'), column.nullable);
548
560
  Utils.runIfNotEmpty(() => col.push('not null'), !column.nullable && !column.generated);
549
561
  if (column.autoincrement &&
@@ -565,7 +577,7 @@ export class MsSqlSchemaHelper extends SchemaHelper {
565
577
  const [constraint] = this.getDropDefaultsSQL(table.name, [column], table.schema);
566
578
  parts.push(constraint);
567
579
  }
568
- if (changedProperties.has('type') || changedProperties.has('nullable')) {
580
+ if (changedProperties.has('type') || changedProperties.has('nullable') || changedProperties.has('collation')) {
569
581
  const col = this.createTableColumn(column, table, changedProperties);
570
582
  parts.push(`alter table ${table.getQuotedName()} alter column ${col}`);
571
583
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/mssql",
3
- "version": "7.1.0-dev.21",
3
+ "version": "7.1.0-dev.23",
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",
@@ -47,17 +47,17 @@
47
47
  "copy": "node ../../scripts/copy.mjs"
48
48
  },
49
49
  "dependencies": {
50
- "@mikro-orm/sql": "7.1.0-dev.21",
50
+ "@mikro-orm/sql": "7.1.0-dev.23",
51
51
  "kysely": "0.28.16",
52
52
  "tarn": "3.0.2",
53
53
  "tedious": "19.2.1",
54
54
  "tsqlstring": "1.0.1"
55
55
  },
56
56
  "devDependencies": {
57
- "@mikro-orm/core": "^7.0.12"
57
+ "@mikro-orm/core": "^7.0.13"
58
58
  },
59
59
  "peerDependencies": {
60
- "@mikro-orm/core": "7.1.0-dev.21"
60
+ "@mikro-orm/core": "7.1.0-dev.23"
61
61
  },
62
62
  "engines": {
63
63
  "node": ">= 22.17.0"