Skip to content

Commit 881febb

Browse files
committed
spatial check fixed for sql server
1 parent 20b5e1e commit 881febb

4 files changed

Lines changed: 49 additions & 15 deletions

File tree

package-lock.json

Lines changed: 7 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/migrations/Migrations.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,17 @@ export default abstract class Migrations {
9090
await this.enableGeoSpatialTypes();
9191
}
9292

93+
// for (const index of type.indexes) {
94+
// for (const column of index.columns) {
95+
// const c = type.getProperty(column.name);
96+
// if (c.field) {
97+
// column.name = c.field.columnName;
98+
// } else {
99+
// debugger;
100+
// }
101+
// }
102+
// }
103+
93104
const schema = await this.getSchema(type);
94105

95106
await this.migrateTable(context, type);
@@ -217,12 +228,14 @@ export default abstract class Migrations {
217228
}
218229

219230

220-
for (const column of index.columns) {
221-
const c = type.getProperty(column.name);
222-
if (c.field) {
223-
column.name = c.field.columnName;
224-
}
225-
}
231+
// for (const column of index.columns) {
232+
// const c = type.getProperty(column.name);
233+
// if (c.field) {
234+
// column.name = c.field.columnName;
235+
// } else {
236+
// debugger;
237+
// }
238+
// }
226239

227240
if (index.include) {
228241
index.include = index.include.map((c) => type.getProperty(c).field.columnName);

src/migrations/sql-server/SqlServerAutomaticMigrations.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export default class SqlServerAutomaticMigrations extends SqlServerMigrations {
3232
: "";
3333
const indexDef: IIndex = {
3434
name: `IX_${type.name}_${iterator.name}`,
35-
columns: [{ name: iterator.quotedColumnName, descending: iterator.indexOrder !== "ascending"}],
35+
columns: [{ name: iterator.columnName, descending: iterator.indexOrder !== "ascending"}],
3636
filter
3737
};
3838
await this.migrateIndexInternal(context, indexDef, type);
@@ -123,20 +123,25 @@ export default class SqlServerAutomaticMigrations extends SqlServerMigrations {
123123
: type.name;
124124
const indexName = index.name;
125125
const columns = [];
126-
let spatial = true;
126+
let spatial = false;
127127
let nonSpatial = false;
128128
for (const column of index.columns) {
129129
const columnName = column.name;
130130
const c = type.getColumn(column.name);
131131
const isColumnSpatial = isSpatialType(c.dataType);
132-
spatial &&= isColumnSpatial;
133-
nonSpatial ||= !isColumnSpatial;
132+
if (isColumnSpatial) {
133+
spatial ||= true;
134+
} else {
135+
nonSpatial ||= true;
136+
}
134137
columns.push(`${columnName} ${ isSpatialType(c.dataType) ? "" : (column.descending ? "DESC" : "ASC")}`);
135138
}
136139

137-
if (nonSpatial && spatial) {
138-
console.warn(`SQL SERVER DOEST NOT SUPPORT SPATIAL AND OTHER DATATYPE INDEX so ${name} index is not created`);
139-
return;
140+
if (spatial) {
141+
if (nonSpatial) {
142+
console.warn(`SQL SERVER DOEST NOT SUPPORT SPATIAL AND OTHER DATATYPE INDEX so ${name} index is not created`);
143+
return;
144+
}
140145
}
141146

142147
const indexType = spatial ? " SPATIAL " : "";

src/model/EntityModel.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,17 @@ const getOrCreateModel = (map: Map<any, EntityType>, type: IClassOf<any>, compil
4444
if (t.keys.length > 1) {
4545
t.keys.sort((a, b) => a.order - b.order);
4646
}
47+
48+
for(const index of t.indexes) {
49+
for (const column of index.columns) {
50+
const c = t.getProperty(column.name);
51+
if (c.field) {
52+
column.name = c.field.columnName;
53+
} else {
54+
debugger;
55+
}
56+
}
57+
}
4758
for (const iterator of original.relations) {
4859
if (!iterator.relatedTypeClass) {
4960
iterator.relatedTypeClass = iterator.relatedTypeClassFactory();

0 commit comments

Comments
 (0)