@entity-access/entity-access 1.0.491 → 1.0.492
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/dist/common/CIMap.d.ts +16 -0
- package/dist/common/CIMap.d.ts.map +1 -0
- package/dist/common/CIMap.js +43 -0
- package/dist/common/CIMap.js.map +1 -0
- package/dist/common/IColumnSchema.d.ts +9 -0
- package/dist/common/IColumnSchema.d.ts.map +1 -1
- package/dist/drivers/base/BaseDriver.d.ts +0 -2
- package/dist/drivers/base/BaseDriver.d.ts.map +1 -1
- package/dist/drivers/base/BaseDriver.js.map +1 -1
- package/dist/drivers/base/ExistingSchema.d.ts +14 -0
- package/dist/drivers/base/ExistingSchema.d.ts.map +1 -0
- package/dist/drivers/base/ExistingSchema.js +34 -0
- package/dist/drivers/base/ExistingSchema.js.map +1 -0
- package/dist/drivers/postgres/PostgreSqlDriver.d.ts.map +1 -1
- package/dist/drivers/postgres/PostgreSqlDriver.js +0 -31
- package/dist/drivers/postgres/PostgreSqlDriver.js.map +1 -1
- package/dist/drivers/sql-server/SqlServerDriver.d.ts +0 -2
- package/dist/drivers/sql-server/SqlServerDriver.d.ts.map +1 -1
- package/dist/drivers/sql-server/SqlServerDriver.js +0 -41
- package/dist/drivers/sql-server/SqlServerDriver.js.map +1 -1
- package/dist/migrations/Migrations.d.ts +9 -2
- package/dist/migrations/Migrations.d.ts.map +1 -1
- package/dist/migrations/Migrations.js +49 -1
- package/dist/migrations/Migrations.js.map +1 -1
- package/dist/migrations/postgres/PostgresAutomaticMigrations.d.ts +2 -4
- package/dist/migrations/postgres/PostgresAutomaticMigrations.d.ts.map +1 -1
- package/dist/migrations/postgres/PostgresAutomaticMigrations.js +15 -39
- package/dist/migrations/postgres/PostgresAutomaticMigrations.js.map +1 -1
- package/dist/migrations/postgres/PostgresMigrations.d.ts +3 -0
- package/dist/migrations/postgres/PostgresMigrations.d.ts.map +1 -1
- package/dist/migrations/postgres/PostgresMigrations.js +68 -0
- package/dist/migrations/postgres/PostgresMigrations.js.map +1 -1
- package/dist/migrations/sql-server/SqlServerAutomaticMigrations.d.ts +2 -4
- package/dist/migrations/sql-server/SqlServerAutomaticMigrations.d.ts.map +1 -1
- package/dist/migrations/sql-server/SqlServerAutomaticMigrations.js +22 -45
- package/dist/migrations/sql-server/SqlServerAutomaticMigrations.js.map +1 -1
- package/dist/migrations/sql-server/SqlServerMigrations.d.ts +5 -0
- package/dist/migrations/sql-server/SqlServerMigrations.d.ts.map +1 -1
- package/dist/migrations/sql-server/SqlServerMigrations.js +77 -0
- package/dist/migrations/sql-server/SqlServerMigrations.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/common/CIMap.ts +50 -0
- package/src/common/IColumnSchema.ts +12 -0
- package/src/drivers/base/BaseDriver.ts +1 -3
- package/src/drivers/base/ExistingSchema.ts +60 -0
- package/src/drivers/postgres/PostgreSqlDriver.ts +1 -32
- package/src/drivers/sql-server/SqlServerDriver.ts +1 -42
- package/src/migrations/Migrations.ts +76 -5
- package/src/migrations/postgres/PostgresAutomaticMigrations.ts +22 -54
- package/src/migrations/postgres/PostgresMigrations.ts +78 -0
- package/src/migrations/sql-server/SqlServerAutomaticMigrations.ts +27 -58
- package/src/migrations/sql-server/SqlServerMigrations.ts +86 -0
- package/dist/migrations/ExistingSchema.d.ts +0 -9
- package/dist/migrations/ExistingSchema.d.ts.map +0 -1
- package/dist/migrations/ExistingSchema.js +0 -31
- package/dist/migrations/ExistingSchema.js.map +0 -1
- package/src/migrations/ExistingSchema.ts +0 -39
|
@@ -1,8 +1,94 @@
|
|
|
1
|
+
import CIMap from "../../common/CIMap.js";
|
|
1
2
|
import { IColumn } from "../../decorators/IColumn.js";
|
|
3
|
+
import ExistingSchema from "../../drivers/base/ExistingSchema.js";
|
|
4
|
+
import EntityType from "../../entity-query/EntityType.js";
|
|
2
5
|
import Migrations from "../Migrations.js";
|
|
3
6
|
|
|
4
7
|
export default abstract class SqlServerMigrations extends Migrations {
|
|
5
8
|
|
|
9
|
+
protected schemaCache = new CIMap<ExistingSchema>();
|
|
10
|
+
|
|
11
|
+
async getExistingSchema(type: EntityType) {
|
|
12
|
+
|
|
13
|
+
const schema = type.schema || "dbo";
|
|
14
|
+
|
|
15
|
+
let text = `
|
|
16
|
+
SELECT
|
|
17
|
+
COLUMN_NAME as [name],
|
|
18
|
+
CASE DATA_TYPE
|
|
19
|
+
WHEN 'bit' THEN 'Boolean'
|
|
20
|
+
WHEN 'int' Then 'Int'
|
|
21
|
+
WHEN 'bigint' THEN 'BigInt'
|
|
22
|
+
WHEN 'date' then 'DateTime'
|
|
23
|
+
WHEN 'datetime' then 'DateTime'
|
|
24
|
+
WHEN 'datetime2' then 'DateTime'
|
|
25
|
+
WHEN 'real' then 'Float'
|
|
26
|
+
WHEN 'double' then 'Double'
|
|
27
|
+
WHEN 'decimal' then 'Decimal'
|
|
28
|
+
WHEN 'identity' then 'UUID'
|
|
29
|
+
WHEN 'varbinary' then 'ByteArray'
|
|
30
|
+
WHEN 'geometry' then 'Geometry'
|
|
31
|
+
ELSE 'Char'
|
|
32
|
+
END as [dataType],
|
|
33
|
+
CASE WHEN IS_NULLABLE = 'YES' THEN 1 ELSE 0 END as [nullable],
|
|
34
|
+
CHARACTER_MAXIMUM_LENGTH as [length],
|
|
35
|
+
CASE
|
|
36
|
+
WHEN COLUMN_DEFAULT = 'getutcdate()' then '() => Sql.date.now()'
|
|
37
|
+
WHEN COLUMN_DEFAULT = '(getutcdate())' then '() => Sql.date.now()'
|
|
38
|
+
WHEN COLUMN_DEFAULT = '(newid())' then '() => Sql.crypto.randomUUID()'
|
|
39
|
+
WHEN (COLUMN_DEFAULT = '(0)' OR COLUMN_DEFAULT = '((0))')
|
|
40
|
+
AND DATA_TYPE = 'bit' THEN '() => false'
|
|
41
|
+
WHEN (COLUMN_DEFAULT = '(1)' OR COLUMN_DEFAULT = '((1))')
|
|
42
|
+
AND DATA_TYPE = 'bit' THEN '() => true'
|
|
43
|
+
WHEN COLUMN_DEFAULT is NULL THEN ''
|
|
44
|
+
ELSE '() => ' + COLUMN_DEFAULT
|
|
45
|
+
END as [default],
|
|
46
|
+
ColumnProperty(OBJECT_ID(TABLE_SCHEMA+'.'+TABLE_NAME),COLUMN_NAME,'IsComputed') as [computed],
|
|
47
|
+
TABLE_NAME as [ownerName],
|
|
48
|
+
'table' as [ownerType]
|
|
49
|
+
FROM INFORMATION_SCHEMA.COLUMNS
|
|
50
|
+
WHERE TABLE_SCHEMA = $1
|
|
51
|
+
`;
|
|
52
|
+
let r = await this.executeQuery({ text, values: [schema] });
|
|
53
|
+
const columns = r.rows ?? [];
|
|
54
|
+
|
|
55
|
+
text = `
|
|
56
|
+
SELECT
|
|
57
|
+
ind.name as [name]
|
|
58
|
+
FROM
|
|
59
|
+
sys.indexes ind
|
|
60
|
+
INNER JOIN
|
|
61
|
+
sys.tables t ON ind.object_id = t.object_id
|
|
62
|
+
INNER JOIN
|
|
63
|
+
sys.schemas s ON t.schema_id = s.schema_id
|
|
64
|
+
WHERE
|
|
65
|
+
s.name = $1`;
|
|
66
|
+
r = await this.executeQuery({ text, values: [schema] });
|
|
67
|
+
const indexes = r.rows ?? [];
|
|
68
|
+
|
|
69
|
+
text = `
|
|
70
|
+
SELECT
|
|
71
|
+
CONSTRAINT_NAME as [name]
|
|
72
|
+
FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS
|
|
73
|
+
WHERE
|
|
74
|
+
CONSTRAINT_TYPE <> 'Foreign Key'
|
|
75
|
+
AND TABLE_SCHEMA=$1`;
|
|
76
|
+
r = await this.executeQuery({ text, values: [schema] });
|
|
77
|
+
const constraints = r.rows ?? [];
|
|
78
|
+
|
|
79
|
+
text = `
|
|
80
|
+
SELECT
|
|
81
|
+
CONSTRAINT_NAME as [name]
|
|
82
|
+
FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS
|
|
83
|
+
WHERE
|
|
84
|
+
CONSTRAINT_TYPE = 'Foreign Key'
|
|
85
|
+
AND TABLE_SCHEMA=$1`;
|
|
86
|
+
r = await this.executeQuery({ text, values: [schema] });
|
|
87
|
+
const foreignKeys = r.rows ?? [];
|
|
88
|
+
|
|
89
|
+
return new ExistingSchema(true, { columns, indexes, constraints, foreignKeys });
|
|
90
|
+
}
|
|
91
|
+
|
|
6
92
|
protected getColumnDefinition(iterator: IColumn) {
|
|
7
93
|
if (iterator.dataType === "Decimal") {
|
|
8
94
|
if (iterator.precision && iterator.scale) {
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import IColumnSchema from "../common/IColumnSchema.js";
|
|
2
|
-
import type { BaseConnection } from "../drivers/base/BaseDriver.js";
|
|
3
|
-
export default class ExistingSchema {
|
|
4
|
-
static getSchema(connection: BaseConnection, schema: string, table: string, caseInsensitive?: boolean): Promise<IColumnSchema[]>;
|
|
5
|
-
private static cache;
|
|
6
|
-
tables: Map<string, IColumnSchema[]>;
|
|
7
|
-
constructor(columns: IColumnSchema[], caseInsensitive?: boolean);
|
|
8
|
-
}
|
|
9
|
-
//# sourceMappingURL=ExistingSchema.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ExistingSchema.d.ts","sourceRoot":"","sources":["../../src/migrations/ExistingSchema.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,MAAM,4BAA4B,CAAC;AACvD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAEpE,MAAM,CAAC,OAAO,OAAO,cAAc;WAGX,SAAS,CAAC,UAAU,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,eAAe,UAAQ;IAahH,OAAO,CAAC,MAAM,CAAC,KAAK,CAAqC;IAElD,MAAM,+BAAqC;gBAEtC,OAAO,EAAE,aAAa,EAAE,EAAE,eAAe,UAAQ;CAehE"}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
export default class ExistingSchema {
|
|
2
|
-
static async getSchema(connection, schema, table, caseInsensitive = false) {
|
|
3
|
-
let s = this.cache.get(schema);
|
|
4
|
-
if (!s) {
|
|
5
|
-
const columns = await connection.getColumnSchema(schema);
|
|
6
|
-
s = new ExistingSchema(columns, caseInsensitive);
|
|
7
|
-
this.cache.set(schema, s);
|
|
8
|
-
}
|
|
9
|
-
if (caseInsensitive) {
|
|
10
|
-
table = table.toLowerCase();
|
|
11
|
-
}
|
|
12
|
-
return s.tables.get(table) ?? [];
|
|
13
|
-
}
|
|
14
|
-
static cache = new Map();
|
|
15
|
-
tables = new Map();
|
|
16
|
-
constructor(columns, caseInsensitive = false) {
|
|
17
|
-
for (const c of columns) {
|
|
18
|
-
let tableName = c.ownerName;
|
|
19
|
-
if (caseInsensitive) {
|
|
20
|
-
tableName = tableName.toLowerCase();
|
|
21
|
-
}
|
|
22
|
-
let table = this.tables.get(tableName);
|
|
23
|
-
if (!table) {
|
|
24
|
-
table = [];
|
|
25
|
-
this.tables.set(tableName, table);
|
|
26
|
-
}
|
|
27
|
-
table.push(c);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
//# sourceMappingURL=ExistingSchema.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ExistingSchema.js","sourceRoot":"","sources":["../../src/migrations/ExistingSchema.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,OAAO,OAAO,cAAc;IAGxB,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,UAA0B,EAAE,MAAc,EAAE,KAAa,EAAE,eAAe,GAAG,KAAK;QAC5G,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAC/B,IAAI,CAAC,CAAC,EAAE,CAAC;YACL,MAAM,OAAO,GAAG,MAAM,UAAU,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;YACzD,CAAC,GAAG,IAAI,cAAc,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC;YACjD,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;QAC9B,CAAC;QACD,IAAI,eAAe,EAAE,CAAC;YAClB,KAAK,GAAG,KAAK,CAAC,WAAW,EAAE,CAAC;QAChC,CAAC;QACD,OAAO,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;IACrC,CAAC;IAEO,MAAM,CAAC,KAAK,GAAG,IAAI,GAAG,EAA0B,CAAC;IAElD,MAAM,GAAG,IAAI,GAAG,EAA0B,CAAC;IAElD,YAAY,OAAwB,EAAE,eAAe,GAAG,KAAK;QACzD,KAAK,MAAM,CAAC,IAAI,OAAO,EAAE,CAAC;YACtB,IAAI,SAAS,GAAG,CAAC,CAAC,SAAS,CAAC;YAC5B,IAAI,eAAe,EAAE,CAAC;gBAClB,SAAS,GAAG,SAAS,CAAC,WAAW,EAAE,CAAC;YACxC,CAAC;YACD,IAAI,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;YACvC,IAAI,CAAC,KAAK,EAAE,CAAC;gBACT,KAAK,GAAG,EAAE,CAAC;gBACX,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;YACtC,CAAC;YACD,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;IACL,CAAC"}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import IColumnSchema from "../common/IColumnSchema.js";
|
|
2
|
-
import type { BaseConnection } from "../drivers/base/BaseDriver.js";
|
|
3
|
-
|
|
4
|
-
export default class ExistingSchema {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
public static async getSchema(connection: BaseConnection, schema: string, table: string, caseInsensitive = false) {
|
|
8
|
-
let s = this.cache.get(schema);
|
|
9
|
-
if (!s) {
|
|
10
|
-
const columns = await connection.getColumnSchema(schema);
|
|
11
|
-
s = new ExistingSchema(columns, caseInsensitive);
|
|
12
|
-
this.cache.set(schema, s);
|
|
13
|
-
}
|
|
14
|
-
if (caseInsensitive) {
|
|
15
|
-
table = table.toLowerCase();
|
|
16
|
-
}
|
|
17
|
-
return s.tables.get(table) ?? [];
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
private static cache = new Map<string, ExistingSchema>();
|
|
21
|
-
|
|
22
|
-
public tables = new Map<string,IColumnSchema[]>();
|
|
23
|
-
|
|
24
|
-
constructor(columns: IColumnSchema[], caseInsensitive = false) {
|
|
25
|
-
for (const c of columns) {
|
|
26
|
-
let tableName = c.ownerName;
|
|
27
|
-
if (caseInsensitive) {
|
|
28
|
-
tableName = tableName.toLowerCase();
|
|
29
|
-
}
|
|
30
|
-
let table = this.tables.get(tableName);
|
|
31
|
-
if (!table) {
|
|
32
|
-
table = [];
|
|
33
|
-
this.tables.set(tableName, table);
|
|
34
|
-
}
|
|
35
|
-
table.push(c);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
}
|