@mikro-orm/mssql 6.3.8-dev.2 → 6.3.8-dev.3
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/MsSqlSchemaHelper.d.ts +4 -4
- package/MsSqlSchemaHelper.js +15 -14
- package/package.json +3 -3
package/MsSqlSchemaHelper.d.ts
CHANGED
|
@@ -12,13 +12,13 @@ export declare class MsSqlSchemaHelper extends SchemaHelper {
|
|
|
12
12
|
getListTablesSQL(): string;
|
|
13
13
|
getNamespaces(connection: AbstractSqlConnection): Promise<string[]>;
|
|
14
14
|
normalizeDefaultValue(defaultValue: string, length: number, defaultValues?: Dictionary<string[]>, stripQuotes?: boolean): string | number;
|
|
15
|
-
getAllColumns(connection: AbstractSqlConnection,
|
|
16
|
-
getAllIndexes(connection: AbstractSqlConnection,
|
|
15
|
+
getAllColumns(connection: AbstractSqlConnection, tablesBySchemas: Map<string | undefined, Table[]>): Promise<Dictionary<Column[]>>;
|
|
16
|
+
getAllIndexes(connection: AbstractSqlConnection, tablesBySchemas: Map<string | undefined, Table[]>): Promise<Dictionary<IndexDef[]>>;
|
|
17
17
|
mapForeignKeys(fks: any[], tableName: string, schemaName?: string): Dictionary;
|
|
18
|
-
getAllForeignKeys(connection: AbstractSqlConnection,
|
|
18
|
+
getAllForeignKeys(connection: AbstractSqlConnection, tablesBySchemas: Map<string | undefined, Table[]>): Promise<Dictionary<Dictionary<ForeignKey>>>;
|
|
19
19
|
getEnumDefinitions(connection: AbstractSqlConnection, checks: CheckDef[], tableName?: string, schemaName?: string): Promise<Dictionary<string[]>>;
|
|
20
20
|
private getChecksSQL;
|
|
21
|
-
getAllChecks(connection: AbstractSqlConnection,
|
|
21
|
+
getAllChecks(connection: AbstractSqlConnection, tablesBySchemas: Map<string | undefined, Table[]>): Promise<Dictionary<CheckDef[]>>;
|
|
22
22
|
loadInformationSchema(schema: DatabaseSchema, connection: AbstractSqlConnection, tables: Table[]): Promise<void>;
|
|
23
23
|
getPreAlterTable(tableDiff: TableDifference, safe: boolean): string;
|
|
24
24
|
getPostAlterTable(tableDiff: TableDifference, safe: boolean): string;
|
package/MsSqlSchemaHelper.js
CHANGED
|
@@ -47,7 +47,7 @@ class MsSqlSchemaHelper extends knex_1.SchemaHelper {
|
|
|
47
47
|
}
|
|
48
48
|
return super.normalizeDefaultValue(defaultValue, length, MsSqlSchemaHelper.DEFAULT_VALUES);
|
|
49
49
|
}
|
|
50
|
-
async getAllColumns(connection,
|
|
50
|
+
async getAllColumns(connection, tablesBySchemas) {
|
|
51
51
|
const sql = `select table_name as table_name,
|
|
52
52
|
table_schema as schema_name,
|
|
53
53
|
column_name as column_name,
|
|
@@ -66,7 +66,7 @@ class MsSqlSchemaHelper extends knex_1.SchemaHelper {
|
|
|
66
66
|
inner join sys.columns sc on sc.name = ic.column_name and sc.object_id = object_id(ic.table_schema + '.' + ic.table_name)
|
|
67
67
|
left join sys.computed_columns cmp on cmp.name = ic.column_name and cmp.object_id = object_id(ic.table_schema + '.' + ic.table_name)
|
|
68
68
|
left join sys.extended_properties t4 on t4.major_id = object_id(ic.table_schema + '.' + ic.table_name) and t4.name = 'MS_Description' and t4.minor_id = sc.column_id
|
|
69
|
-
where table_name in (${tables.map(t => this.platform.quoteValue(t.table_name))})
|
|
69
|
+
where (${[...tablesBySchemas.entries()].map(([schema, tables]) => `(ic.table_name in (${tables.map(t => this.platform.quoteValue(t.table_name)).join(',')}) and ic.table_schema = '${schema}')`).join(' OR ')})
|
|
70
70
|
order by ordinal_position`;
|
|
71
71
|
const allColumns = await connection.execute(sql);
|
|
72
72
|
const str = (val) => val != null ? '' + val : val;
|
|
@@ -112,7 +112,7 @@ class MsSqlSchemaHelper extends knex_1.SchemaHelper {
|
|
|
112
112
|
}
|
|
113
113
|
return ret;
|
|
114
114
|
}
|
|
115
|
-
async getAllIndexes(connection,
|
|
115
|
+
async getAllIndexes(connection, tablesBySchemas) {
|
|
116
116
|
const sql = `select t.name as table_name,
|
|
117
117
|
ind.name as index_name,
|
|
118
118
|
is_unique as is_unique,
|
|
@@ -125,7 +125,7 @@ class MsSqlSchemaHelper extends knex_1.SchemaHelper {
|
|
|
125
125
|
inner join sys.columns col on ic.object_id = col.object_id and ic.column_id = col.column_id
|
|
126
126
|
inner join sys.tables t on ind.object_id = t.object_id
|
|
127
127
|
where
|
|
128
|
-
t.name in (${tables.map(t => this.platform.quoteValue(t.table_name)).join(', ')})
|
|
128
|
+
(${[...tablesBySchemas.entries()].map(([schema, tables]) => `(t.name in (${tables.map(t => this.platform.quoteValue(t.table_name)).join(',')}) and schema_name(t.schema_id) = '${schema}')`).join(' OR ')})
|
|
129
129
|
order by t.name, ind.name, ind.index_id`;
|
|
130
130
|
const allIndexes = await connection.execute(sql);
|
|
131
131
|
const ret = {};
|
|
@@ -158,7 +158,7 @@ class MsSqlSchemaHelper extends knex_1.SchemaHelper {
|
|
|
158
158
|
}
|
|
159
159
|
return ret;
|
|
160
160
|
}
|
|
161
|
-
async getAllForeignKeys(connection,
|
|
161
|
+
async getAllForeignKeys(connection, tablesBySchemas) {
|
|
162
162
|
const sql = `select ccu.constraint_name, ccu.table_name, ccu.table_schema schema_name, ccu.column_name,
|
|
163
163
|
kcu.constraint_schema referenced_schema_name,
|
|
164
164
|
kcu.column_name referenced_column_name,
|
|
@@ -168,7 +168,7 @@ class MsSqlSchemaHelper extends knex_1.SchemaHelper {
|
|
|
168
168
|
from information_schema.constraint_column_usage ccu
|
|
169
169
|
inner join information_schema.referential_constraints rc on ccu.constraint_name = rc.constraint_name and rc.constraint_schema = ccu.constraint_schema
|
|
170
170
|
inner join information_schema.key_column_usage kcu on kcu.constraint_name = rc.unique_constraint_name and rc.unique_constraint_schema = kcu.constraint_schema
|
|
171
|
-
where (${
|
|
171
|
+
where (${[...tablesBySchemas.entries()].map(([schema, tables]) => `(ccu.table_name in (${tables.map(t => this.platform.quoteValue(t.table_name)).join(',')}) and ccu.table_schema = '${schema}')`).join(' or ')})
|
|
172
172
|
order by kcu.table_schema, kcu.table_name, kcu.ordinal_position, kcu.constraint_name`;
|
|
173
173
|
const allFks = await connection.execute(sql);
|
|
174
174
|
const ret = {};
|
|
@@ -204,7 +204,7 @@ class MsSqlSchemaHelper extends knex_1.SchemaHelper {
|
|
|
204
204
|
found.reverse().forEach(index => checks.splice(index, 1));
|
|
205
205
|
return enums;
|
|
206
206
|
}
|
|
207
|
-
getChecksSQL(
|
|
207
|
+
getChecksSQL(tablesBySchemas) {
|
|
208
208
|
return `select con.name as name,
|
|
209
209
|
schema_name(t.schema_id) schema_name,
|
|
210
210
|
t.name table_name,
|
|
@@ -213,11 +213,11 @@ class MsSqlSchemaHelper extends knex_1.SchemaHelper {
|
|
|
213
213
|
from sys.check_constraints con
|
|
214
214
|
left outer join sys.objects t on con.parent_object_id = t.object_id
|
|
215
215
|
left outer join sys.all_columns col on con.parent_column_id = col.column_id and con.parent_object_id = col.object_id
|
|
216
|
-
where (${
|
|
216
|
+
where (${[...tablesBySchemas.entries()].map(([schema, tables]) => `t.name in (${tables.map(t => this.platform.quoteValue(t.table_name)).join(',')}) and schema_name(t.schema_id) = '${schema}'`).join(' or ')})
|
|
217
217
|
order by con.name`;
|
|
218
218
|
}
|
|
219
|
-
async getAllChecks(connection,
|
|
220
|
-
const sql = this.getChecksSQL(
|
|
219
|
+
async getAllChecks(connection, tablesBySchemas) {
|
|
220
|
+
const sql = this.getChecksSQL(tablesBySchemas);
|
|
221
221
|
const allChecks = await connection.execute(sql);
|
|
222
222
|
const ret = {};
|
|
223
223
|
for (const check of allChecks) {
|
|
@@ -236,10 +236,11 @@ class MsSqlSchemaHelper extends knex_1.SchemaHelper {
|
|
|
236
236
|
if (tables.length === 0) {
|
|
237
237
|
return;
|
|
238
238
|
}
|
|
239
|
-
const
|
|
240
|
-
const
|
|
241
|
-
const
|
|
242
|
-
const
|
|
239
|
+
const tablesBySchema = this.getTablesGroupedBySchemas(tables);
|
|
240
|
+
const columns = await this.getAllColumns(connection, tablesBySchema);
|
|
241
|
+
const indexes = await this.getAllIndexes(connection, tablesBySchema);
|
|
242
|
+
const checks = await this.getAllChecks(connection, tablesBySchema);
|
|
243
|
+
const fks = await this.getAllForeignKeys(connection, tablesBySchema);
|
|
243
244
|
for (const t of tables) {
|
|
244
245
|
const key = this.getTableKey(t);
|
|
245
246
|
const table = schema.addTable(t.table_name, t.schema_name, t.table_comment);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/mssql",
|
|
3
|
-
"version": "6.3.8-dev.
|
|
3
|
+
"version": "6.3.8-dev.3",
|
|
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
|
"main": "index.js",
|
|
6
6
|
"module": "index.mjs",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"access": "public"
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@mikro-orm/knex": "6.3.8-dev.
|
|
61
|
+
"@mikro-orm/knex": "6.3.8-dev.3",
|
|
62
62
|
"tedious": "19.0.0",
|
|
63
63
|
"tsqlstring": "1.0.1"
|
|
64
64
|
},
|
|
@@ -66,6 +66,6 @@
|
|
|
66
66
|
"@mikro-orm/core": "^6.3.7"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
|
-
"@mikro-orm/core": "6.3.8-dev.
|
|
69
|
+
"@mikro-orm/core": "6.3.8-dev.3"
|
|
70
70
|
}
|
|
71
71
|
}
|