@entity-access/entity-access 1.1.6 → 1.1.8
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/.github/workflows/node.yml +1 -1
- package/dist/compiler/postgres/PostgreSqlMethodTransformer.js +2 -2
- package/dist/compiler/postgres/PostgreSqlMethodTransformer.js.map +1 -1
- package/dist/decorators/IIndex.d.ts +2 -0
- package/dist/decorators/IIndex.d.ts.map +1 -1
- package/dist/decorators/ISqlType.d.ts +2 -6
- package/dist/decorators/ISqlType.d.ts.map +1 -1
- package/dist/decorators/Index.d.ts +1 -1
- package/dist/decorators/Index.d.ts.map +1 -1
- package/dist/decorators/Index.js +2 -1
- package/dist/decorators/Index.js.map +1 -1
- package/dist/migrations/Migrations.d.ts +1 -0
- package/dist/migrations/Migrations.d.ts.map +1 -1
- package/dist/migrations/Migrations.js +12 -0
- package/dist/migrations/Migrations.js.map +1 -1
- package/dist/migrations/postgres/PostgresAutomaticMigrations.d.ts.map +1 -1
- package/dist/migrations/postgres/PostgresAutomaticMigrations.js +6 -2
- package/dist/migrations/postgres/PostgresAutomaticMigrations.js.map +1 -1
- package/dist/migrations/postgres/PostgresMigrations.d.ts +2 -1
- package/dist/migrations/postgres/PostgresMigrations.d.ts.map +1 -1
- package/dist/migrations/postgres/PostgresMigrations.js +5 -4
- package/dist/migrations/postgres/PostgresMigrations.js.map +1 -1
- package/dist/migrations/sql-server/SqlServerAutomaticMigrations.d.ts.map +1 -1
- package/dist/migrations/sql-server/SqlServerAutomaticMigrations.js +3 -2
- package/dist/migrations/sql-server/SqlServerAutomaticMigrations.js.map +1 -1
- package/dist/migrations/sql-server/SqlServerMigrations.d.ts +1 -1
- package/dist/migrations/sql-server/SqlServerMigrations.d.ts.map +1 -1
- package/dist/migrations/sql-server/SqlServerMigrations.js +2 -4
- package/dist/migrations/sql-server/SqlServerMigrations.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/compiler/postgres/PostgreSqlMethodTransformer.ts +2 -2
- package/src/decorators/IIndex.ts +2 -0
- package/src/decorators/ISqlType.ts +2 -7
- package/src/decorators/Index.ts +2 -0
- package/src/migrations/Migrations.ts +15 -0
- package/src/migrations/postgres/PostgresAutomaticMigrations.ts +8 -2
- package/src/migrations/postgres/PostgresMigrations.ts +6 -4
- package/src/migrations/sql-server/SqlServerAutomaticMigrations.ts +5 -2
- package/src/migrations/sql-server/SqlServerMigrations.ts +2 -4
- package/tests/local-unit-tests/docker-compose.yml +1 -1
package/src/decorators/Index.ts
CHANGED
|
@@ -14,6 +14,7 @@ export default function Index<T>(
|
|
|
14
14
|
unique,
|
|
15
15
|
include,
|
|
16
16
|
indexType,
|
|
17
|
+
spatial,
|
|
17
18
|
filter
|
|
18
19
|
}
|
|
19
20
|
: IIndexDef<T>) {
|
|
@@ -27,6 +28,7 @@ export default function Index<T>(
|
|
|
27
28
|
include: include ? include.map(NameParser.parseMember) : void 0,
|
|
28
29
|
dropNames,
|
|
29
30
|
indexType,
|
|
31
|
+
spatial,
|
|
30
32
|
filter,
|
|
31
33
|
columns
|
|
32
34
|
};
|
|
@@ -55,6 +55,8 @@ export default abstract class Migrations {
|
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
+
let hasGeoSpatialTypes = false;
|
|
59
|
+
|
|
58
60
|
for (const s of model.sources.values()) {
|
|
59
61
|
const type = s[modelSymbol] as EntityType;
|
|
60
62
|
|
|
@@ -63,6 +65,11 @@ export default abstract class Migrations {
|
|
|
63
65
|
}
|
|
64
66
|
|
|
65
67
|
for (const column of type.columns) {
|
|
68
|
+
switch(column.dataType) {
|
|
69
|
+
case "Geography":
|
|
70
|
+
hasGeoSpatialTypes = true;
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
66
73
|
if (column.computed && typeof column.computed !== "string") {
|
|
67
74
|
// parse..
|
|
68
75
|
const source = context.query(type.typeClass) as EntityQuery<any>;
|
|
@@ -79,6 +86,10 @@ export default abstract class Migrations {
|
|
|
79
86
|
}
|
|
80
87
|
}
|
|
81
88
|
|
|
89
|
+
if (hasGeoSpatialTypes) {
|
|
90
|
+
await this.enableGeoSpatialTypes();
|
|
91
|
+
}
|
|
92
|
+
|
|
82
93
|
const schema = await this.getSchema(type);
|
|
83
94
|
|
|
84
95
|
await this.migrateTable(context, type);
|
|
@@ -149,6 +160,10 @@ export default abstract class Migrations {
|
|
|
149
160
|
return true;
|
|
150
161
|
}
|
|
151
162
|
|
|
163
|
+
async enableGeoSpatialTypes() {
|
|
164
|
+
// do nothing...
|
|
165
|
+
}
|
|
166
|
+
|
|
152
167
|
async hasVersion(context: EntityContext, name: string, version: string, table: string) {
|
|
153
168
|
const { quote, escapeLiteral } = this.compiler;
|
|
154
169
|
|
|
@@ -124,9 +124,15 @@ export default class PostgresAutomaticMigrations extends PostgresMigrations {
|
|
|
124
124
|
break;
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
|
-
columns.push(`${columnName} ${operatorClass} ${column.descending ? "DESC" : "ASC"}`);
|
|
127
|
+
columns.push(`${columnName} ${operatorClass} ${ index.spatial ? "" : (column.descending ? "DESC" : "ASC")}`);
|
|
128
128
|
}
|
|
129
|
-
let query = `CREATE ${index.unique ? "UNIQUE" : ""} INDEX IF NOT EXISTS ${indexName} ON ${name}
|
|
129
|
+
let query = `CREATE ${index.unique ? "UNIQUE" : ""} INDEX IF NOT EXISTS ${indexName} ON ${name}`;
|
|
130
|
+
|
|
131
|
+
if (index.spatial) {
|
|
132
|
+
query += " USING GIST ";
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
query += ` ( ${columns.join(", ")})`;
|
|
130
136
|
|
|
131
137
|
if (index.include) {
|
|
132
138
|
query += ` INCLUDE (${index.include.join(",")})`;
|
|
@@ -77,6 +77,10 @@ export default abstract class PostgresMigrations extends Migrations {
|
|
|
77
77
|
return new ExistingSchema(false, { columns, foreignKeys, indexes, constraints });
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
+
async enableGeoSpatialTypes(): Promise<void> {
|
|
81
|
+
await this.connection.executeQuery(`CREATE EXTENSION IF NOT EXISTS postgis;`);
|
|
82
|
+
}
|
|
83
|
+
|
|
80
84
|
protected getColumnDefinition(iterator: IColumn) {
|
|
81
85
|
if (iterator.dataType === "Decimal") {
|
|
82
86
|
if (iterator.precision && iterator.scale) {
|
|
@@ -123,10 +127,8 @@ export default abstract class PostgresMigrations extends Migrations {
|
|
|
123
127
|
return "jsonb";
|
|
124
128
|
case "UUID":
|
|
125
129
|
return "uuid";
|
|
126
|
-
case "
|
|
127
|
-
return "
|
|
128
|
-
case "Point":
|
|
129
|
-
return "point";
|
|
130
|
+
case "Geography":
|
|
131
|
+
return "geography";
|
|
130
132
|
}
|
|
131
133
|
const a: never = iterator.dataType;
|
|
132
134
|
throw new Error("Not Defined");
|
|
@@ -124,11 +124,14 @@ export default class SqlServerAutomaticMigrations extends SqlServerMigrations {
|
|
|
124
124
|
const columns = [];
|
|
125
125
|
for (const column of index.columns) {
|
|
126
126
|
const columnName = column.name;
|
|
127
|
-
columns.push(`${columnName} ${column.descending ? "DESC" : "ASC"}`);
|
|
127
|
+
columns.push(`${columnName} ${ index.spatial ? "" : (column.descending ? "DESC" : "ASC")}`);
|
|
128
128
|
}
|
|
129
|
+
|
|
130
|
+
const indexType = index.spatial ? " SPATIAL " : "";
|
|
131
|
+
|
|
129
132
|
let query = `IF NOT EXISTS(SELECT * FROM sys.indexes WHERE name = '${indexName}' AND object_id = OBJECT_ID('${name}'))
|
|
130
133
|
BEGIN
|
|
131
|
-
CREATE ${index.unique ? "UNIQUE" : ""} INDEX ${indexName} ON ${name} ( ${columns.join(", ")})`;
|
|
134
|
+
CREATE ${index.unique ? "UNIQUE" : ""} ${indexType} INDEX ${indexName} ON ${name} ( ${columns.join(", ")})`;
|
|
132
135
|
|
|
133
136
|
if (index.include) {
|
|
134
137
|
query += ` INCLUDE (${index.include.join(",")})`;
|
|
@@ -139,10 +139,8 @@ export default abstract class SqlServerMigrations extends Migrations {
|
|
|
139
139
|
return "jsonb";
|
|
140
140
|
case "UUID":
|
|
141
141
|
return "UniqueIdentifier";
|
|
142
|
-
case "
|
|
143
|
-
return "
|
|
144
|
-
case "Point":
|
|
145
|
-
return "geometry";
|
|
142
|
+
case "Geography":
|
|
143
|
+
return "geography";
|
|
146
144
|
}
|
|
147
145
|
const a: never = iterator.dataType;
|
|
148
146
|
throw new Error("Not Defined");
|