@entity-access/entity-access 1.0.489 → 1.0.491
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/IColumnSchema.d.ts +2 -0
- package/dist/common/IColumnSchema.d.ts.map +1 -1
- package/dist/drivers/base/BaseDriver.d.ts +1 -1
- package/dist/drivers/base/BaseDriver.d.ts.map +1 -1
- package/dist/drivers/postgres/PostgreSqlDriver.js +6 -5
- package/dist/drivers/postgres/PostgreSqlDriver.js.map +1 -1
- package/dist/drivers/sql-server/SqlServerDriver.d.ts +1 -1
- package/dist/drivers/sql-server/SqlServerDriver.d.ts.map +1 -1
- package/dist/drivers/sql-server/SqlServerDriver.js +5 -4
- package/dist/drivers/sql-server/SqlServerDriver.js.map +1 -1
- package/dist/migrations/ExistingSchema.d.ts +9 -0
- package/dist/migrations/ExistingSchema.d.ts.map +1 -0
- package/dist/migrations/ExistingSchema.js +31 -0
- package/dist/migrations/ExistingSchema.js.map +1 -0
- package/dist/migrations/Migrations.d.ts.map +1 -1
- package/dist/migrations/Migrations.js +5 -5
- 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 -1
- package/dist/migrations/postgres/PostgresAutomaticMigrations.js.map +1 -1
- package/dist/migrations/sql-server/SqlServerAutomaticMigrations.d.ts.map +1 -1
- package/dist/migrations/sql-server/SqlServerAutomaticMigrations.js +6 -1
- package/dist/migrations/sql-server/SqlServerAutomaticMigrations.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/common/IColumnSchema.ts +2 -0
- package/src/drivers/base/BaseDriver.ts +1 -1
- package/src/drivers/postgres/PostgreSqlDriver.ts +6 -5
- package/src/drivers/sql-server/SqlServerDriver.ts +5 -4
- package/src/migrations/ExistingSchema.ts +39 -0
- package/src/migrations/Migrations.ts +11 -9
- package/src/migrations/postgres/PostgresAutomaticMigrations.ts +8 -1
- package/src/migrations/sql-server/SqlServerAutomaticMigrations.ts +8 -1
|
@@ -9,6 +9,7 @@ import type { BaseConnection, IQuery, IQueryResult } from "../drivers/base/BaseD
|
|
|
9
9
|
import type EntityType from "../entity-query/EntityType.js";
|
|
10
10
|
import type EntityContext from "../model/EntityContext.js";
|
|
11
11
|
import type EntityQuery from "../model/EntityQuery.js";
|
|
12
|
+
import ExistingSchema from "./ExistingSchema.js";
|
|
12
13
|
|
|
13
14
|
export default abstract class Migrations {
|
|
14
15
|
|
|
@@ -90,20 +91,21 @@ export default abstract class Migrations {
|
|
|
90
91
|
await this.migrateIndexInternal(context, index, type);
|
|
91
92
|
}
|
|
92
93
|
|
|
93
|
-
|
|
94
|
+
if (createIndexForForeignKeys) {
|
|
95
|
+
postMigration.push(() =>
|
|
96
|
+
this.createIndexForForeignKeys(context, type, type.nonKeys.filter((x) =>
|
|
97
|
+
x.fkRelation
|
|
98
|
+
&& (!x.key || type.keys.indexOf(x) !== 0)
|
|
99
|
+
&& !x.fkRelation?.doNotCreateIndex))
|
|
100
|
+
);
|
|
101
|
+
}
|
|
94
102
|
|
|
95
|
-
|
|
96
|
-
postMigration.push(() =>
|
|
97
|
-
this.createIndexForForeignKeys(context, type, type.nonKeys.filter((x) =>
|
|
98
|
-
x.fkRelation
|
|
99
|
-
&& (!x.key || type.keys.indexOf(x) !== 0)
|
|
100
|
-
&& !x.fkRelation?.doNotCreateIndex))
|
|
101
|
-
);
|
|
102
|
-
}
|
|
103
|
+
for (const { isInverseRelation , foreignKeyConstraint, relatedTypeClass } of type.relations) {
|
|
103
104
|
|
|
104
105
|
if (isInverseRelation) {
|
|
105
106
|
continue;
|
|
106
107
|
}
|
|
108
|
+
|
|
107
109
|
if (!foreignKeyConstraint) {
|
|
108
110
|
continue;
|
|
109
111
|
}
|
|
@@ -6,6 +6,7 @@ import { IIndex } from "../../decorators/IIndex.js";
|
|
|
6
6
|
import { BaseConnection, BaseDriver } from "../../drivers/base/BaseDriver.js";
|
|
7
7
|
import EntityType from "../../entity-query/EntityType.js";
|
|
8
8
|
import type EntityContext from "../../model/EntityContext.js";
|
|
9
|
+
import ExistingSchema from "../ExistingSchema.js";
|
|
9
10
|
import PostgresMigrations from "./PostgresMigrations.js";
|
|
10
11
|
|
|
11
12
|
export default class PostgresAutomaticMigrations extends PostgresMigrations {
|
|
@@ -58,7 +59,7 @@ export default class PostgresAutomaticMigrations extends PostgresMigrations {
|
|
|
58
59
|
nonKeyColumns.sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
|
|
59
60
|
}
|
|
60
61
|
|
|
61
|
-
const columns =
|
|
62
|
+
const columns = await ExistingSchema.getSchema(driver, type.schema || "public", type.name, true);
|
|
62
63
|
|
|
63
64
|
const columnSet = new Set(columns.map((x) => x.name));
|
|
64
65
|
|
|
@@ -89,6 +90,12 @@ export default class PostgresAutomaticMigrations extends PostgresMigrations {
|
|
|
89
90
|
|
|
90
91
|
async createTable(driver: BaseConnection, type: EntityType, keys: IColumn[]) {
|
|
91
92
|
|
|
93
|
+
const columns = await ExistingSchema.getSchema(driver, type.schema || "public", type.name, true);
|
|
94
|
+
|
|
95
|
+
if (columns.length) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
|
|
92
99
|
const name = type.schema
|
|
93
100
|
? type.schema + "." + type.name
|
|
94
101
|
: type.name;
|
|
@@ -7,6 +7,7 @@ import { BaseConnection } from "../../drivers/base/BaseDriver.js";
|
|
|
7
7
|
import { SqlServerLiteral } from "../../drivers/sql-server/SqlServerLiteral.js";
|
|
8
8
|
import EntityType from "../../entity-query/EntityType.js";
|
|
9
9
|
import type EntityContext from "../../model/EntityContext.js";
|
|
10
|
+
import ExistingSchema from "../ExistingSchema.js";
|
|
10
11
|
import SqlServerMigrations from "./SqlServerMigrations.js";
|
|
11
12
|
|
|
12
13
|
export default class SqlServerAutomaticMigrations extends SqlServerMigrations {
|
|
@@ -61,7 +62,7 @@ export default class SqlServerAutomaticMigrations extends SqlServerMigrations {
|
|
|
61
62
|
nonKeyColumns.sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
|
|
62
63
|
}
|
|
63
64
|
|
|
64
|
-
const columns = await
|
|
65
|
+
const columns = await ExistingSchema.getSchema(driver, type.schema || "dbo", type.name);
|
|
65
66
|
|
|
66
67
|
const columnSet = new Set(columns.map((x) => x.name.toLowerCase()));
|
|
67
68
|
|
|
@@ -97,6 +98,12 @@ export default class SqlServerAutomaticMigrations extends SqlServerMigrations {
|
|
|
97
98
|
|
|
98
99
|
async createTable(driver: BaseConnection, type: EntityType, keys: IColumn[]) {
|
|
99
100
|
|
|
101
|
+
const columns = await ExistingSchema.getSchema(driver, type.schema || "public", type.name);
|
|
102
|
+
|
|
103
|
+
if (columns.length) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
|
|
100
107
|
const name = type.schema
|
|
101
108
|
? type.schema + "." + type.name
|
|
102
109
|
: type.name;
|