@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.
Files changed (33) hide show
  1. package/dist/common/IColumnSchema.d.ts +2 -0
  2. package/dist/common/IColumnSchema.d.ts.map +1 -1
  3. package/dist/drivers/base/BaseDriver.d.ts +1 -1
  4. package/dist/drivers/base/BaseDriver.d.ts.map +1 -1
  5. package/dist/drivers/postgres/PostgreSqlDriver.js +6 -5
  6. package/dist/drivers/postgres/PostgreSqlDriver.js.map +1 -1
  7. package/dist/drivers/sql-server/SqlServerDriver.d.ts +1 -1
  8. package/dist/drivers/sql-server/SqlServerDriver.d.ts.map +1 -1
  9. package/dist/drivers/sql-server/SqlServerDriver.js +5 -4
  10. package/dist/drivers/sql-server/SqlServerDriver.js.map +1 -1
  11. package/dist/migrations/ExistingSchema.d.ts +9 -0
  12. package/dist/migrations/ExistingSchema.d.ts.map +1 -0
  13. package/dist/migrations/ExistingSchema.js +31 -0
  14. package/dist/migrations/ExistingSchema.js.map +1 -0
  15. package/dist/migrations/Migrations.d.ts.map +1 -1
  16. package/dist/migrations/Migrations.js +5 -5
  17. package/dist/migrations/Migrations.js.map +1 -1
  18. package/dist/migrations/postgres/PostgresAutomaticMigrations.d.ts.map +1 -1
  19. package/dist/migrations/postgres/PostgresAutomaticMigrations.js +6 -1
  20. package/dist/migrations/postgres/PostgresAutomaticMigrations.js.map +1 -1
  21. package/dist/migrations/sql-server/SqlServerAutomaticMigrations.d.ts.map +1 -1
  22. package/dist/migrations/sql-server/SqlServerAutomaticMigrations.js +6 -1
  23. package/dist/migrations/sql-server/SqlServerAutomaticMigrations.js.map +1 -1
  24. package/dist/tsconfig.tsbuildinfo +1 -1
  25. package/package.json +1 -1
  26. package/src/common/IColumnSchema.ts +2 -0
  27. package/src/drivers/base/BaseDriver.ts +1 -1
  28. package/src/drivers/postgres/PostgreSqlDriver.ts +6 -5
  29. package/src/drivers/sql-server/SqlServerDriver.ts +5 -4
  30. package/src/migrations/ExistingSchema.ts +39 -0
  31. package/src/migrations/Migrations.ts +11 -9
  32. package/src/migrations/postgres/PostgresAutomaticMigrations.ts +8 -1
  33. 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
- for (const { isInverseRelation , foreignKeyConstraint, relatedTypeClass } of type.relations) {
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
- if (createIndexForForeignKeys) {
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 = await driver.getColumnSchema(type.schema || "public", type.name);
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 driver.getColumnSchema(type.schema || "dbo", type.name);
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;