taon-typeorm 18.0.19 → 18.0.20
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/browser/esm2022/lib/typeorm/driver/cordova/CordovaDriver.mjs +1 -1
- package/browser/esm2022/lib/typeorm/driver/cordova/CordovaQueryRunner.mjs +1 -1
- package/browser/esm2022/lib/typeorm/driver/nativescript/NativescriptDriver.mjs +1 -1
- package/browser/esm2022/lib/typeorm/driver/nativescript/NativescriptQueryRunner.mjs +1 -1
- package/browser/esm2022/lib/typeorm/driver/react-native/ReactNativeDriver.mjs +1 -1
- package/browser/esm2022/lib/typeorm/driver/react-native/ReactNativeQueryRunner.mjs +1 -1
- package/browser/esm2022/lib/typeorm/driver/sqljs/SqljsDriver.mjs +1 -1
- package/browser/esm2022/lib/typeorm/driver/sqljs/SqljsQueryRunner.mjs +1 -1
- package/browser/esm2022/lib/typeorm/index.mjs +1 -3
- package/browser/fesm2022/taon-typeorm.mjs.map +1 -1
- package/client/esm2022/lib/typeorm/driver/cordova/CordovaDriver.mjs +1 -1
- package/client/esm2022/lib/typeorm/driver/cordova/CordovaQueryRunner.mjs +1 -1
- package/client/esm2022/lib/typeorm/driver/nativescript/NativescriptDriver.mjs +1 -1
- package/client/esm2022/lib/typeorm/driver/nativescript/NativescriptQueryRunner.mjs +1 -1
- package/client/esm2022/lib/typeorm/driver/react-native/ReactNativeDriver.mjs +1 -1
- package/client/esm2022/lib/typeorm/driver/react-native/ReactNativeQueryRunner.mjs +1 -1
- package/client/esm2022/lib/typeorm/driver/sqljs/SqljsDriver.mjs +1 -1
- package/client/esm2022/lib/typeorm/driver/sqljs/SqljsQueryRunner.mjs +1 -1
- package/client/esm2022/lib/typeorm/index.mjs +1 -3
- package/client/fesm2022/taon-typeorm.mjs.map +1 -1
- package/index.js +15 -2
- package/index.js.map +1 -1
- package/lib/build-info._auto-generated_.js.map +1 -1
- package/lib/index._auto-generated_.d.ts +1 -0
- package/lib/index._auto-generated_.js.map +1 -1
- package/lib/index.js +15 -2
- package/lib/index.js.map +1 -1
- package/lib/typeorm/cache/DbQueryResultCache.js +178 -231
- package/lib/typeorm/cache/DbQueryResultCache.js.map +1 -1
- package/lib/typeorm/cache/QueryResultCache.js.map +1 -1
- package/lib/typeorm/cache/QueryResultCacheFactory.js +11 -11
- package/lib/typeorm/cache/QueryResultCacheFactory.js.map +1 -1
- package/lib/typeorm/cache/QueryResultCacheOptions.js.map +1 -1
- package/lib/typeorm/cache/RedisQueryResultCache.js +121 -149
- package/lib/typeorm/cache/RedisQueryResultCache.js.map +1 -1
- package/lib/typeorm/cli-ts-node-commonjs.js.map +1 -1
- package/lib/typeorm/cli-ts-node-esm.js +7 -5
- package/lib/typeorm/cli-ts-node-esm.js.map +1 -1
- package/lib/typeorm/cli.d.ts +1 -1
- package/lib/typeorm/cli.js +15 -16
- package/lib/typeorm/cli.js.map +1 -1
- package/lib/typeorm/commands/CacheClearCommand.js +37 -65
- package/lib/typeorm/commands/CacheClearCommand.js.map +1 -1
- package/lib/typeorm/commands/CommandUtils.js +57 -112
- package/lib/typeorm/commands/CommandUtils.js.map +1 -1
- package/lib/typeorm/commands/EntityCreateCommand.js +35 -47
- package/lib/typeorm/commands/EntityCreateCommand.js.map +1 -1
- package/lib/typeorm/commands/InitCommand.js +397 -168
- package/lib/typeorm/commands/InitCommand.js.map +1 -1
- package/lib/typeorm/commands/MigrationCreateCommand.js +58 -52
- package/lib/typeorm/commands/MigrationCreateCommand.js.map +1 -1
- package/lib/typeorm/commands/MigrationGenerateCommand.js +141 -138
- package/lib/typeorm/commands/MigrationGenerateCommand.js.map +1 -1
- package/lib/typeorm/commands/MigrationRevertCommand.js +49 -77
- package/lib/typeorm/commands/MigrationRevertCommand.js.map +1 -1
- package/lib/typeorm/commands/MigrationRunCommand.js +52 -82
- package/lib/typeorm/commands/MigrationRunCommand.js.map +1 -1
- package/lib/typeorm/commands/MigrationShowCommand.js +32 -60
- package/lib/typeorm/commands/MigrationShowCommand.js.map +1 -1
- package/lib/typeorm/commands/QueryCommand.js +47 -83
- package/lib/typeorm/commands/QueryCommand.js.map +1 -1
- package/lib/typeorm/commands/SchemaDropCommand.js +33 -61
- package/lib/typeorm/commands/SchemaDropCommand.js.map +1 -1
- package/lib/typeorm/commands/SchemaLogCommand.js +57 -81
- package/lib/typeorm/commands/SchemaLogCommand.js.map +1 -1
- package/lib/typeorm/commands/SchemaSyncCommand.js +33 -61
- package/lib/typeorm/commands/SchemaSyncCommand.js.map +1 -1
- package/lib/typeorm/commands/SubscriberCreateCommand.js +35 -47
- package/lib/typeorm/commands/SubscriberCreateCommand.js.map +1 -1
- package/lib/typeorm/commands/VersionCommand.js +38 -54
- package/lib/typeorm/commands/VersionCommand.js.map +1 -1
- package/lib/typeorm/common/DeepPartial.js.map +1 -1
- package/lib/typeorm/common/EntityTarget.js.map +1 -1
- package/lib/typeorm/common/MixedList.js.map +1 -1
- package/lib/typeorm/common/NonNever.js.map +1 -1
- package/lib/typeorm/common/ObjectLiteral.js.map +1 -1
- package/lib/typeorm/common/ObjectType.js.map +1 -1
- package/lib/typeorm/common/RelationType.js.map +1 -1
- package/lib/typeorm/connection/BaseConnectionOptions.js.map +1 -1
- package/lib/typeorm/connection/Connection.js +3 -9
- package/lib/typeorm/connection/Connection.js.map +1 -1
- package/lib/typeorm/connection/ConnectionManager.js +23 -31
- package/lib/typeorm/connection/ConnectionManager.js.map +1 -1
- package/lib/typeorm/connection/ConnectionMetadataBuilder.js +48 -78
- package/lib/typeorm/connection/ConnectionMetadataBuilder.js.map +1 -1
- package/lib/typeorm/connection/ConnectionOptions.js.map +1 -1
- package/lib/typeorm/connection/ConnectionOptionsReader.js +146 -214
- package/lib/typeorm/connection/ConnectionOptionsReader.js.map +1 -1
- package/lib/typeorm/connection/options-reader/ConnectionOptionsEnvReader.js +50 -58
- package/lib/typeorm/connection/options-reader/ConnectionOptionsEnvReader.js.map +1 -1
- package/lib/typeorm/connection/options-reader/ConnectionOptionsXmlReader.js +45 -58
- package/lib/typeorm/connection/options-reader/ConnectionOptionsXmlReader.js.map +1 -1
- package/lib/typeorm/connection/options-reader/ConnectionOptionsYmlReader.js +14 -23
- package/lib/typeorm/connection/options-reader/ConnectionOptionsYmlReader.js.map +1 -1
- package/lib/typeorm/constants.js.map +1 -1
- package/lib/typeorm/container.js +9 -12
- package/lib/typeorm/container.js.map +1 -1
- package/lib/typeorm/data-source/BaseDataSourceOptions.js.map +1 -1
- package/lib/typeorm/data-source/DataSource.js +320 -478
- package/lib/typeorm/data-source/DataSource.js.map +1 -1
- package/lib/typeorm/data-source/DataSourceOptions.js.map +1 -1
- package/lib/typeorm/data-source/index.js +16 -3
- package/lib/typeorm/data-source/index.js.map +1 -1
- package/lib/typeorm/decorator/Check.js +5 -5
- package/lib/typeorm/decorator/Check.js.map +1 -1
- package/lib/typeorm/decorator/EntityRepository.js +1 -1
- package/lib/typeorm/decorator/EntityRepository.js.map +1 -1
- package/lib/typeorm/decorator/Exclusion.js +5 -5
- package/lib/typeorm/decorator/Exclusion.js.map +1 -1
- package/lib/typeorm/decorator/Generated.js +2 -3
- package/lib/typeorm/decorator/Generated.js.map +1 -1
- package/lib/typeorm/decorator/Index.js +5 -5
- package/lib/typeorm/decorator/Index.js.map +1 -1
- package/lib/typeorm/decorator/Unique.js +8 -8
- package/lib/typeorm/decorator/Unique.js.map +1 -1
- package/lib/typeorm/decorator/columns/Column.js +4 -4
- package/lib/typeorm/decorator/columns/Column.js.map +1 -1
- package/lib/typeorm/decorator/columns/CreateDateColumn.js +1 -1
- package/lib/typeorm/decorator/columns/CreateDateColumn.js.map +1 -1
- package/lib/typeorm/decorator/columns/DeleteDateColumn.js +1 -1
- package/lib/typeorm/decorator/columns/DeleteDateColumn.js.map +1 -1
- package/lib/typeorm/decorator/columns/ObjectIdColumn.js +1 -1
- package/lib/typeorm/decorator/columns/ObjectIdColumn.js.map +1 -1
- package/lib/typeorm/decorator/columns/PrimaryColumn.js +5 -5
- package/lib/typeorm/decorator/columns/PrimaryColumn.js.map +1 -1
- package/lib/typeorm/decorator/columns/PrimaryGeneratedColumn.js +4 -4
- package/lib/typeorm/decorator/columns/PrimaryGeneratedColumn.js.map +1 -1
- package/lib/typeorm/decorator/columns/UpdateDateColumn.js +1 -1
- package/lib/typeorm/decorator/columns/UpdateDateColumn.js.map +1 -1
- package/lib/typeorm/decorator/columns/VersionColumn.js +1 -1
- package/lib/typeorm/decorator/columns/VersionColumn.js.map +1 -1
- package/lib/typeorm/decorator/columns/ViewColumn.js +1 -1
- package/lib/typeorm/decorator/columns/ViewColumn.js.map +1 -1
- package/lib/typeorm/decorator/columns/VirtualColumn.js +5 -5
- package/lib/typeorm/decorator/columns/VirtualColumn.js.map +1 -1
- package/lib/typeorm/decorator/entity/ChildEntity.js +1 -1
- package/lib/typeorm/decorator/entity/ChildEntity.js.map +1 -1
- package/lib/typeorm/decorator/entity/Entity.js +4 -4
- package/lib/typeorm/decorator/entity/Entity.js.map +1 -1
- package/lib/typeorm/decorator/entity/TableInheritance.js +1 -1
- package/lib/typeorm/decorator/entity/TableInheritance.js.map +1 -1
- package/lib/typeorm/decorator/entity-view/ViewEntity.js +4 -4
- package/lib/typeorm/decorator/entity-view/ViewEntity.js.map +1 -1
- package/lib/typeorm/decorator/listeners/AfterInsert.js +2 -2
- package/lib/typeorm/decorator/listeners/AfterInsert.js.map +1 -1
- package/lib/typeorm/decorator/listeners/AfterLoad.js +2 -2
- package/lib/typeorm/decorator/listeners/AfterLoad.js.map +1 -1
- package/lib/typeorm/decorator/listeners/AfterRecover.js +2 -2
- package/lib/typeorm/decorator/listeners/AfterRecover.js.map +1 -1
- package/lib/typeorm/decorator/listeners/AfterRemove.js +2 -2
- package/lib/typeorm/decorator/listeners/AfterRemove.js.map +1 -1
- package/lib/typeorm/decorator/listeners/AfterSoftRemove.js +2 -2
- package/lib/typeorm/decorator/listeners/AfterSoftRemove.js.map +1 -1
- package/lib/typeorm/decorator/listeners/AfterUpdate.js +2 -2
- package/lib/typeorm/decorator/listeners/AfterUpdate.js.map +1 -1
- package/lib/typeorm/decorator/listeners/BeforeInsert.js +2 -2
- package/lib/typeorm/decorator/listeners/BeforeInsert.js.map +1 -1
- package/lib/typeorm/decorator/listeners/BeforeRecover.js +2 -2
- package/lib/typeorm/decorator/listeners/BeforeRecover.js.map +1 -1
- package/lib/typeorm/decorator/listeners/BeforeRemove.js +2 -2
- package/lib/typeorm/decorator/listeners/BeforeRemove.js.map +1 -1
- package/lib/typeorm/decorator/listeners/BeforeSoftRemove.js +2 -2
- package/lib/typeorm/decorator/listeners/BeforeSoftRemove.js.map +1 -1
- package/lib/typeorm/decorator/listeners/BeforeUpdate.js +2 -2
- package/lib/typeorm/decorator/listeners/BeforeUpdate.js.map +1 -1
- package/lib/typeorm/decorator/listeners/EventSubscriber.js +1 -1
- package/lib/typeorm/decorator/listeners/EventSubscriber.js.map +1 -1
- package/lib/typeorm/decorator/options/ColumnCommonOptions.js.map +1 -1
- package/lib/typeorm/decorator/options/ColumnEmbeddedOptions.js.map +1 -1
- package/lib/typeorm/decorator/options/ColumnEnumOptions.js.map +1 -1
- package/lib/typeorm/decorator/options/ColumnHstoreOptions.js.map +1 -1
- package/lib/typeorm/decorator/options/ColumnNumericOptions.js.map +1 -1
- package/lib/typeorm/decorator/options/ColumnOptions.js.map +1 -1
- package/lib/typeorm/decorator/options/ColumnWithLengthOptions.js.map +1 -1
- package/lib/typeorm/decorator/options/ColumnWithWidthOptions.js.map +1 -1
- package/lib/typeorm/decorator/options/EntityOptions.js.map +1 -1
- package/lib/typeorm/decorator/options/IndexOptions.js.map +1 -1
- package/lib/typeorm/decorator/options/JoinColumnOptions.js.map +1 -1
- package/lib/typeorm/decorator/options/JoinTableMultipleColumnsOptions.js.map +1 -1
- package/lib/typeorm/decorator/options/JoinTableOptions.js.map +1 -1
- package/lib/typeorm/decorator/options/PrimaryGeneratedColumnIdentityOptions.js.map +1 -1
- package/lib/typeorm/decorator/options/PrimaryGeneratedColumnNumericOptions.js.map +1 -1
- package/lib/typeorm/decorator/options/PrimaryGeneratedColumnUUIDOptions.js.map +1 -1
- package/lib/typeorm/decorator/options/RelationOptions.js.map +1 -1
- package/lib/typeorm/decorator/options/SpatialColumnOptions.js.map +1 -1
- package/lib/typeorm/decorator/options/TransactionOptions.js.map +1 -1
- package/lib/typeorm/decorator/options/UniqueOptions.js.map +1 -1
- package/lib/typeorm/decorator/options/ValueTransformer.js.map +1 -1
- package/lib/typeorm/decorator/options/ViewColumnOptions.js.map +1 -1
- package/lib/typeorm/decorator/options/ViewEntityOptions.js.map +1 -1
- package/lib/typeorm/decorator/options/VirtualColumnOptions.js.map +1 -1
- package/lib/typeorm/decorator/relations/JoinColumn.js +3 -3
- package/lib/typeorm/decorator/relations/JoinColumn.js.map +1 -1
- package/lib/typeorm/decorator/relations/JoinTable.js +1 -1
- package/lib/typeorm/decorator/relations/JoinTable.js.map +1 -1
- package/lib/typeorm/decorator/relations/ManyToMany.js +5 -5
- package/lib/typeorm/decorator/relations/ManyToMany.js.map +1 -1
- package/lib/typeorm/decorator/relations/ManyToOne.js +5 -5
- package/lib/typeorm/decorator/relations/ManyToOne.js.map +1 -1
- package/lib/typeorm/decorator/relations/OneToMany.js +3 -3
- package/lib/typeorm/decorator/relations/OneToMany.js.map +1 -1
- package/lib/typeorm/decorator/relations/OneToOne.js +5 -5
- package/lib/typeorm/decorator/relations/OneToOne.js.map +1 -1
- package/lib/typeorm/decorator/relations/RelationCount.js +1 -1
- package/lib/typeorm/decorator/relations/RelationCount.js.map +1 -1
- package/lib/typeorm/decorator/relations/RelationId.js +1 -1
- package/lib/typeorm/decorator/relations/RelationId.js.map +1 -1
- package/lib/typeorm/decorator/tree/Tree.js +1 -1
- package/lib/typeorm/decorator/tree/Tree.js.map +1 -1
- package/lib/typeorm/decorator/tree/TreeChildren.js +4 -4
- package/lib/typeorm/decorator/tree/TreeChildren.js.map +1 -1
- package/lib/typeorm/decorator/tree/TreeLevelColumn.js +1 -1
- package/lib/typeorm/decorator/tree/TreeLevelColumn.js.map +1 -1
- package/lib/typeorm/decorator/tree/TreeParent.js +4 -4
- package/lib/typeorm/decorator/tree/TreeParent.js.map +1 -1
- package/lib/typeorm/driver/Driver.js.map +1 -1
- package/lib/typeorm/driver/DriverFactory.js +24 -27
- package/lib/typeorm/driver/DriverFactory.js.map +1 -1
- package/lib/typeorm/driver/DriverUtils.js +78 -126
- package/lib/typeorm/driver/DriverUtils.js.map +1 -1
- package/lib/typeorm/driver/Query.js +6 -5
- package/lib/typeorm/driver/Query.js.map +1 -1
- package/lib/typeorm/driver/SqlInMemory.js +4 -7
- package/lib/typeorm/driver/SqlInMemory.js.map +1 -1
- package/lib/typeorm/driver/aurora-mysql/AuroraMysqlConnection.js +9 -12
- package/lib/typeorm/driver/aurora-mysql/AuroraMysqlConnection.js.map +1 -1
- package/lib/typeorm/driver/aurora-mysql/AuroraMysqlConnectionCredentialsOptions.js.map +1 -1
- package/lib/typeorm/driver/aurora-mysql/AuroraMysqlConnectionOptions.js.map +1 -1
- package/lib/typeorm/driver/aurora-mysql/AuroraMysqlDriver.js +392 -399
- package/lib/typeorm/driver/aurora-mysql/AuroraMysqlDriver.js.map +1 -1
- package/lib/typeorm/driver/aurora-mysql/AuroraMysqlQueryRunner.js +1320 -2084
- package/lib/typeorm/driver/aurora-mysql/AuroraMysqlQueryRunner.js.map +1 -1
- package/lib/typeorm/driver/aurora-postgres/AuroraPostgresConnectionOptions.js.map +1 -1
- package/lib/typeorm/driver/aurora-postgres/AuroraPostgresDriver.js +50 -78
- package/lib/typeorm/driver/aurora-postgres/AuroraPostgresDriver.js.map +1 -1
- package/lib/typeorm/driver/aurora-postgres/AuroraPostgresQueryRunner.js +89 -160
- package/lib/typeorm/driver/aurora-postgres/AuroraPostgresQueryRunner.js.map +1 -1
- package/lib/typeorm/driver/better-sqlite3/BetterSqlite3ConnectionOptions.js.map +1 -1
- package/lib/typeorm/driver/better-sqlite3/BetterSqlite3Driver.js +78 -152
- package/lib/typeorm/driver/better-sqlite3/BetterSqlite3Driver.js.map +1 -1
- package/lib/typeorm/driver/better-sqlite3/BetterSqlite3QueryRunner.js +96 -155
- package/lib/typeorm/driver/better-sqlite3/BetterSqlite3QueryRunner.js.map +1 -1
- package/lib/typeorm/driver/capacitor/CapacitorConnectionOptions.js.map +1 -1
- package/lib/typeorm/driver/capacitor/CapacitorDriver.js +44 -89
- package/lib/typeorm/driver/capacitor/CapacitorDriver.js.map +1 -1
- package/lib/typeorm/driver/capacitor/CapacitorQueryRunner.js +70 -122
- package/lib/typeorm/driver/capacitor/CapacitorQueryRunner.js.map +1 -1
- package/lib/typeorm/driver/cockroachdb/CockroachConnectionCredentialsOptions.js.map +1 -1
- package/lib/typeorm/driver/cockroachdb/CockroachConnectionOptions.js.map +1 -1
- package/lib/typeorm/driver/cockroachdb/CockroachDriver.js +368 -404
- package/lib/typeorm/driver/cockroachdb/CockroachDriver.js.map +1 -1
- package/lib/typeorm/driver/cockroachdb/CockroachQueryRunner.js +1752 -2862
- package/lib/typeorm/driver/cockroachdb/CockroachQueryRunner.js.map +1 -1
- package/lib/typeorm/driver/cordova/CordovaConnectionOptions.js.map +1 -1
- package/lib/typeorm/driver/cordova/CordovaDriver.js +36 -58
- package/lib/typeorm/driver/cordova/CordovaDriver.js.map +1 -1
- package/lib/typeorm/driver/cordova/CordovaQueryRunner.js +86 -164
- package/lib/typeorm/driver/cordova/CordovaQueryRunner.js.map +1 -1
- package/lib/typeorm/driver/expo/ExpoConnectionOptions.js.map +1 -1
- package/lib/typeorm/driver/expo/ExpoDriver.js +34 -44
- package/lib/typeorm/driver/expo/ExpoDriver.js.map +1 -1
- package/lib/typeorm/driver/expo/ExpoQueryRunner.js +114 -204
- package/lib/typeorm/driver/expo/ExpoQueryRunner.js.map +1 -1
- package/lib/typeorm/driver/mongodb/MongoConnectionOptions.js.map +1 -1
- package/lib/typeorm/driver/mongodb/MongoDriver.js +269 -243
- package/lib/typeorm/driver/mongodb/MongoDriver.js.map +1 -1
- package/lib/typeorm/driver/mongodb/MongoQueryRunner.js +357 -793
- package/lib/typeorm/driver/mongodb/MongoQueryRunner.js.map +1 -1
- package/lib/typeorm/driver/mongodb/typings.js.map +1 -1
- package/lib/typeorm/driver/mysql/MysqlConnectionCredentialsOptions.js.map +1 -1
- package/lib/typeorm/driver/mysql/MysqlConnectionOptions.js.map +1 -1
- package/lib/typeorm/driver/mysql/MysqlDriver.js +475 -480
- package/lib/typeorm/driver/mysql/MysqlDriver.js.map +1 -1
- package/lib/typeorm/driver/mysql/MysqlQueryRunner.js +1692 -2466
- package/lib/typeorm/driver/mysql/MysqlQueryRunner.js.map +1 -1
- package/lib/typeorm/driver/nativescript/NativescriptConnectionOptions.js.map +1 -1
- package/lib/typeorm/driver/nativescript/NativescriptDriver.js +46 -50
- package/lib/typeorm/driver/nativescript/NativescriptDriver.js.map +1 -1
- package/lib/typeorm/driver/nativescript/NativescriptQueryRunner.js +62 -101
- package/lib/typeorm/driver/nativescript/NativescriptQueryRunner.js.map +1 -1
- package/lib/typeorm/driver/oracle/OracleConnectionCredentialsOptions.js.map +1 -1
- package/lib/typeorm/driver/oracle/OracleConnectionOptions.js.map +1 -1
- package/lib/typeorm/driver/oracle/OracleDriver.js +345 -377
- package/lib/typeorm/driver/oracle/OracleDriver.js.map +1 -1
- package/lib/typeorm/driver/oracle/OracleQueryRunner.js +1484 -2384
- package/lib/typeorm/driver/oracle/OracleQueryRunner.js.map +1 -1
- package/lib/typeorm/driver/postgres/PostgresConnectionCredentialsOptions.js.map +1 -1
- package/lib/typeorm/driver/postgres/PostgresConnectionOptions.js.map +1 -1
- package/lib/typeorm/driver/postgres/PostgresDriver.js +574 -690
- package/lib/typeorm/driver/postgres/PostgresDriver.js.map +1 -1
- package/lib/typeorm/driver/postgres/PostgresQueryRunner.js +2153 -3379
- package/lib/typeorm/driver/postgres/PostgresQueryRunner.js.map +1 -1
- package/lib/typeorm/driver/react-native/ReactNativeConnectionOptions.js.map +1 -1
- package/lib/typeorm/driver/react-native/ReactNativeDriver.js +34 -44
- package/lib/typeorm/driver/react-native/ReactNativeDriver.js.map +1 -1
- package/lib/typeorm/driver/react-native/ReactNativeQueryRunner.js +60 -94
- package/lib/typeorm/driver/react-native/ReactNativeQueryRunner.js.map +1 -1
- package/lib/typeorm/driver/sap/SapConnectionCredentialsOptions.js.map +1 -1
- package/lib/typeorm/driver/sap/SapConnectionOptions.js.map +1 -1
- package/lib/typeorm/driver/sap/SapDriver.js +310 -305
- package/lib/typeorm/driver/sap/SapDriver.js.map +1 -1
- package/lib/typeorm/driver/sap/SapQueryRunner.js +1635 -2561
- package/lib/typeorm/driver/sap/SapQueryRunner.js.map +1 -1
- package/lib/typeorm/driver/spanner/SpannerConnectionCredentialsOptions.js.map +1 -1
- package/lib/typeorm/driver/spanner/SpannerConnectionOptions.js.map +1 -1
- package/lib/typeorm/driver/spanner/SpannerDriver.js +250 -236
- package/lib/typeorm/driver/spanner/SpannerDriver.js.map +1 -1
- package/lib/typeorm/driver/spanner/SpannerQueryRunner.js +1136 -2168
- package/lib/typeorm/driver/spanner/SpannerQueryRunner.js.map +1 -1
- package/lib/typeorm/driver/sqlite/SqliteConnectionOptions.js.map +1 -1
- package/lib/typeorm/driver/sqlite/SqliteDriver.js +82 -169
- package/lib/typeorm/driver/sqlite/SqliteDriver.js.map +1 -1
- package/lib/typeorm/driver/sqlite/SqliteQueryRunner.js +78 -122
- package/lib/typeorm/driver/sqlite/SqliteQueryRunner.js.map +1 -1
- package/lib/typeorm/driver/sqlite-abstract/AbstractSqliteDriver.js +280 -268
- package/lib/typeorm/driver/sqlite-abstract/AbstractSqliteDriver.js.map +1 -1
- package/lib/typeorm/driver/sqlite-abstract/AbstractSqliteQueryRunner.js +1158 -1990
- package/lib/typeorm/driver/sqlite-abstract/AbstractSqliteQueryRunner.js.map +1 -1
- package/lib/typeorm/driver/sqljs/SqljsConnectionOptions.js.map +1 -1
- package/lib/typeorm/driver/sqljs/SqljsDriver.js +187 -253
- package/lib/typeorm/driver/sqljs/SqljsDriver.js.map +1 -1
- package/lib/typeorm/driver/sqljs/SqljsQueryRunner.js +88 -147
- package/lib/typeorm/driver/sqljs/SqljsQueryRunner.js.map +1 -1
- package/lib/typeorm/driver/sqlserver/MssqlParameter.js +10 -13
- package/lib/typeorm/driver/sqlserver/MssqlParameter.js.map +1 -1
- package/lib/typeorm/driver/sqlserver/SqlServerConnectionCredentialsOptions.js.map +1 -1
- package/lib/typeorm/driver/sqlserver/SqlServerConnectionOptions.js.map +1 -1
- package/lib/typeorm/driver/sqlserver/SqlServerDriver.js +352 -372
- package/lib/typeorm/driver/sqlserver/SqlServerDriver.js.map +1 -1
- package/lib/typeorm/driver/sqlserver/SqlServerQueryRunner.js +1979 -3068
- package/lib/typeorm/driver/sqlserver/SqlServerQueryRunner.js.map +1 -1
- package/lib/typeorm/driver/sqlserver/authentication/AzureActiveDirectoryAccessTokenAuthentication.js.map +1 -1
- package/lib/typeorm/driver/sqlserver/authentication/AzureActiveDirectoryMsiAppServiceAuthentication.js.map +1 -1
- package/lib/typeorm/driver/sqlserver/authentication/AzureActiveDirectoryMsiVmAuthentication.js.map +1 -1
- package/lib/typeorm/driver/sqlserver/authentication/AzureActiveDirectoryPasswordAuthentication.js.map +1 -1
- package/lib/typeorm/driver/sqlserver/authentication/AzureActiveDirectoryServicePrincipalSecret.js.map +1 -1
- package/lib/typeorm/driver/sqlserver/authentication/DefaultAuthentication.js.map +1 -1
- package/lib/typeorm/driver/sqlserver/authentication/NtlmAuthentication.js.map +1 -1
- package/lib/typeorm/driver/types/ColumnTypes.js.map +1 -1
- package/lib/typeorm/driver/types/CteCapabilities.js.map +1 -1
- package/lib/typeorm/driver/types/DataTypeDefaults.js.map +1 -1
- package/lib/typeorm/driver/types/DatabaseType.js.map +1 -1
- package/lib/typeorm/driver/types/IsolationLevel.js.map +1 -1
- package/lib/typeorm/driver/types/MappedColumnTypes.js.map +1 -1
- package/lib/typeorm/driver/types/MetadataTableType.js.map +1 -1
- package/lib/typeorm/driver/types/ReplicationMode.js.map +1 -1
- package/lib/typeorm/driver/types/UpsertType.js.map +1 -1
- package/lib/typeorm/entity-manager/EntityManager.js +351 -469
- package/lib/typeorm/entity-manager/EntityManager.js.map +1 -1
- package/lib/typeorm/entity-manager/EntityManagerFactory.js +7 -10
- package/lib/typeorm/entity-manager/EntityManagerFactory.js.map +1 -1
- package/lib/typeorm/entity-manager/MongoEntityManager.js +371 -487
- package/lib/typeorm/entity-manager/MongoEntityManager.js.map +1 -1
- package/lib/typeorm/entity-manager/SqljsEntityManager.js +16 -37
- package/lib/typeorm/entity-manager/SqljsEntityManager.js.map +1 -1
- package/lib/typeorm/entity-schema/EntitySchema.js +5 -5
- package/lib/typeorm/entity-schema/EntitySchema.js.map +1 -1
- package/lib/typeorm/entity-schema/EntitySchemaCheckOptions.js.map +1 -1
- package/lib/typeorm/entity-schema/EntitySchemaColumnOptions.js.map +1 -1
- package/lib/typeorm/entity-schema/EntitySchemaEmbeddedColumnOptions.js +17 -5
- package/lib/typeorm/entity-schema/EntitySchemaEmbeddedColumnOptions.js.map +1 -1
- package/lib/typeorm/entity-schema/EntitySchemaEmbeddedError.js +11 -14
- package/lib/typeorm/entity-schema/EntitySchemaEmbeddedError.js.map +1 -1
- package/lib/typeorm/entity-schema/EntitySchemaExclusionOptions.js.map +1 -1
- package/lib/typeorm/entity-schema/EntitySchemaIndexOptions.js.map +1 -1
- package/lib/typeorm/entity-schema/EntitySchemaOptions.js +82 -5
- package/lib/typeorm/entity-schema/EntitySchemaOptions.js.map +1 -1
- package/lib/typeorm/entity-schema/EntitySchemaRelationIdOptions.js.map +1 -1
- package/lib/typeorm/entity-schema/EntitySchemaRelationOptions.js.map +1 -1
- package/lib/typeorm/entity-schema/EntitySchemaTransformer.js +51 -68
- package/lib/typeorm/entity-schema/EntitySchemaTransformer.js.map +1 -1
- package/lib/typeorm/entity-schema/EntitySchemaUniqueOptions.js.map +1 -1
- package/lib/typeorm/error/AlreadyHasActiveConnectionError.js +6 -9
- package/lib/typeorm/error/AlreadyHasActiveConnectionError.js.map +1 -1
- package/lib/typeorm/error/CannotAttachTreeChildrenEntityError.js +6 -9
- package/lib/typeorm/error/CannotAttachTreeChildrenEntityError.js.map +1 -1
- package/lib/typeorm/error/CannotConnectAlreadyConnectedError.js +5 -8
- package/lib/typeorm/error/CannotConnectAlreadyConnectedError.js.map +1 -1
- package/lib/typeorm/error/CannotCreateEntityIdMapError.js +7 -11
- package/lib/typeorm/error/CannotCreateEntityIdMapError.js.map +1 -1
- package/lib/typeorm/error/CannotDetermineEntityError.js +6 -9
- package/lib/typeorm/error/CannotDetermineEntityError.js.map +1 -1
- package/lib/typeorm/error/CannotExecuteNotConnectedError.js +5 -8
- package/lib/typeorm/error/CannotExecuteNotConnectedError.js.map +1 -1
- package/lib/typeorm/error/CannotGetEntityManagerNotConnectedError.js +5 -8
- package/lib/typeorm/error/CannotGetEntityManagerNotConnectedError.js.map +1 -1
- package/lib/typeorm/error/CannotReflectMethodParameterTypeError.js +7 -10
- package/lib/typeorm/error/CannotReflectMethodParameterTypeError.js.map +1 -1
- package/lib/typeorm/error/CircularRelationsError.js +6 -9
- package/lib/typeorm/error/CircularRelationsError.js.map +1 -1
- package/lib/typeorm/error/ColumnTypeUndefinedError.js +8 -11
- package/lib/typeorm/error/ColumnTypeUndefinedError.js.map +1 -1
- package/lib/typeorm/error/ConnectionIsNotSetError.js +5 -8
- package/lib/typeorm/error/ConnectionIsNotSetError.js.map +1 -1
- package/lib/typeorm/error/ConnectionNotFoundError.js +5 -8
- package/lib/typeorm/error/ConnectionNotFoundError.js.map +1 -1
- package/lib/typeorm/error/CustomRepositoryCannotInheritRepositoryError.js +7 -10
- package/lib/typeorm/error/CustomRepositoryCannotInheritRepositoryError.js.map +1 -1
- package/lib/typeorm/error/CustomRepositoryDoesNotHaveEntityError.js +7 -10
- package/lib/typeorm/error/CustomRepositoryDoesNotHaveEntityError.js.map +1 -1
- package/lib/typeorm/error/CustomRepositoryNotFoundError.js +7 -10
- package/lib/typeorm/error/CustomRepositoryNotFoundError.js.map +1 -1
- package/lib/typeorm/error/DataTypeNotSupportedError.js +7 -11
- package/lib/typeorm/error/DataTypeNotSupportedError.js.map +1 -1
- package/lib/typeorm/error/DriverOptionNotSetError.js +6 -9
- package/lib/typeorm/error/DriverOptionNotSetError.js.map +1 -1
- package/lib/typeorm/error/DriverPackageNotInstalledError.js +6 -9
- package/lib/typeorm/error/DriverPackageNotInstalledError.js.map +1 -1
- package/lib/typeorm/error/EntityMetadataNotFoundError.js +10 -14
- package/lib/typeorm/error/EntityMetadataNotFoundError.js.map +1 -1
- package/lib/typeorm/error/EntityNotFoundError.js +13 -17
- package/lib/typeorm/error/EntityNotFoundError.js.map +1 -1
- package/lib/typeorm/error/EntityPropertyNotFoundError.js +7 -11
- package/lib/typeorm/error/EntityPropertyNotFoundError.js.map +1 -1
- package/lib/typeorm/error/FindRelationsNotFoundError.js +9 -13
- package/lib/typeorm/error/FindRelationsNotFoundError.js.map +1 -1
- package/lib/typeorm/error/ForbiddenTransactionModeOverrideError.js +6 -9
- package/lib/typeorm/error/ForbiddenTransactionModeOverrideError.js.map +1 -1
- package/lib/typeorm/error/InitializedRelationError.js +7 -10
- package/lib/typeorm/error/InitializedRelationError.js.map +1 -1
- package/lib/typeorm/error/InsertValuesMissingError.js +6 -9
- package/lib/typeorm/error/InsertValuesMissingError.js.map +1 -1
- package/lib/typeorm/error/LimitOnUpdateNotSupportedError.js +5 -8
- package/lib/typeorm/error/LimitOnUpdateNotSupportedError.js.map +1 -1
- package/lib/typeorm/error/LockNotSupportedOnGivenDriverError.js +5 -8
- package/lib/typeorm/error/LockNotSupportedOnGivenDriverError.js.map +1 -1
- package/lib/typeorm/error/MetadataAlreadyExistsError.js +6 -9
- package/lib/typeorm/error/MetadataAlreadyExistsError.js.map +1 -1
- package/lib/typeorm/error/MetadataWithSuchNameAlreadyExistsError.js +6 -9
- package/lib/typeorm/error/MetadataWithSuchNameAlreadyExistsError.js.map +1 -1
- package/lib/typeorm/error/MissingDeleteDateColumnError.js +5 -8
- package/lib/typeorm/error/MissingDeleteDateColumnError.js.map +1 -1
- package/lib/typeorm/error/MissingDriverError.js +6 -10
- package/lib/typeorm/error/MissingDriverError.js.map +1 -1
- package/lib/typeorm/error/MissingJoinColumnError.js +12 -16
- package/lib/typeorm/error/MissingJoinColumnError.js.map +1 -1
- package/lib/typeorm/error/MissingJoinTableError.js +12 -16
- package/lib/typeorm/error/MissingJoinTableError.js.map +1 -1
- package/lib/typeorm/error/MissingPrimaryColumnError.js +6 -9
- package/lib/typeorm/error/MissingPrimaryColumnError.js.map +1 -1
- package/lib/typeorm/error/MustBeEntityError.js +5 -8
- package/lib/typeorm/error/MustBeEntityError.js.map +1 -1
- package/lib/typeorm/error/NamingStrategyNotFoundError.js +9 -13
- package/lib/typeorm/error/NamingStrategyNotFoundError.js.map +1 -1
- package/lib/typeorm/error/NestedSetMultipleRootError.js +5 -8
- package/lib/typeorm/error/NestedSetMultipleRootError.js.map +1 -1
- package/lib/typeorm/error/NoConnectionForRepositoryError.js +6 -9
- package/lib/typeorm/error/NoConnectionForRepositoryError.js.map +1 -1
- package/lib/typeorm/error/NoConnectionOptionError.js +6 -9
- package/lib/typeorm/error/NoConnectionOptionError.js.map +1 -1
- package/lib/typeorm/error/NoNeedToReleaseEntityManagerError.js +7 -10
- package/lib/typeorm/error/NoNeedToReleaseEntityManagerError.js.map +1 -1
- package/lib/typeorm/error/NoVersionOrUpdateDateColumnError.js +5 -8
- package/lib/typeorm/error/NoVersionOrUpdateDateColumnError.js.map +1 -1
- package/lib/typeorm/error/OffsetWithoutLimitNotSupportedError.js +7 -10
- package/lib/typeorm/error/OffsetWithoutLimitNotSupportedError.js.map +1 -1
- package/lib/typeorm/error/OptimisticLockCanNotBeUsedError.js +5 -8
- package/lib/typeorm/error/OptimisticLockCanNotBeUsedError.js.map +1 -1
- package/lib/typeorm/error/OptimisticLockVersionMismatchError.js +5 -8
- package/lib/typeorm/error/OptimisticLockVersionMismatchError.js.map +1 -1
- package/lib/typeorm/error/PersistedEntityNotFoundError.js +5 -8
- package/lib/typeorm/error/PersistedEntityNotFoundError.js.map +1 -1
- package/lib/typeorm/error/PessimisticLockTransactionRequiredError.js +5 -8
- package/lib/typeorm/error/PessimisticLockTransactionRequiredError.js.map +1 -1
- package/lib/typeorm/error/PrimaryColumnCannotBeNullableError.js +6 -9
- package/lib/typeorm/error/PrimaryColumnCannotBeNullableError.js.map +1 -1
- package/lib/typeorm/error/QueryFailedError.js +18 -17
- package/lib/typeorm/error/QueryFailedError.js.map +1 -1
- package/lib/typeorm/error/QueryRunnerAlreadyReleasedError.js +5 -8
- package/lib/typeorm/error/QueryRunnerAlreadyReleasedError.js.map +1 -1
- package/lib/typeorm/error/QueryRunnerProviderAlreadyReleasedError.js +6 -9
- package/lib/typeorm/error/QueryRunnerProviderAlreadyReleasedError.js.map +1 -1
- package/lib/typeorm/error/RepositoryNotTreeError.js +9 -13
- package/lib/typeorm/error/RepositoryNotTreeError.js.map +1 -1
- package/lib/typeorm/error/ReturningStatementNotSupportedError.js +5 -8
- package/lib/typeorm/error/ReturningStatementNotSupportedError.js.map +1 -1
- package/lib/typeorm/error/SubjectRemovedAndUpdatedError.js +6 -9
- package/lib/typeorm/error/SubjectRemovedAndUpdatedError.js.map +1 -1
- package/lib/typeorm/error/SubjectWithoutIdentifierError.js +5 -8
- package/lib/typeorm/error/SubjectWithoutIdentifierError.js.map +1 -1
- package/lib/typeorm/error/TransactionAlreadyStartedError.js +5 -8
- package/lib/typeorm/error/TransactionAlreadyStartedError.js.map +1 -1
- package/lib/typeorm/error/TransactionNotStartedError.js +5 -8
- package/lib/typeorm/error/TransactionNotStartedError.js.map +1 -1
- package/lib/typeorm/error/TreeRepositoryNotSupportedError.js +5 -8
- package/lib/typeorm/error/TreeRepositoryNotSupportedError.js.map +1 -1
- package/lib/typeorm/error/TypeORMError.js +9 -18
- package/lib/typeorm/error/TypeORMError.js.map +1 -1
- package/lib/typeorm/error/UpdateValuesMissingError.js +5 -8
- package/lib/typeorm/error/UpdateValuesMissingError.js.map +1 -1
- package/lib/typeorm/error/UsingJoinColumnIsNotAllowedError.js +6 -9
- package/lib/typeorm/error/UsingJoinColumnIsNotAllowedError.js.map +1 -1
- package/lib/typeorm/error/UsingJoinColumnOnlyOnOneSideAllowedError.js +7 -10
- package/lib/typeorm/error/UsingJoinColumnOnlyOnOneSideAllowedError.js.map +1 -1
- package/lib/typeorm/error/UsingJoinTableIsNotAllowedError.js +7 -10
- package/lib/typeorm/error/UsingJoinTableIsNotAllowedError.js.map +1 -1
- package/lib/typeorm/error/UsingJoinTableOnlyOnOneSideAllowedError.js +7 -10
- package/lib/typeorm/error/UsingJoinTableOnlyOnOneSideAllowedError.js.map +1 -1
- package/lib/typeorm/error/index.js +75 -62
- package/lib/typeorm/error/index.js.map +1 -1
- package/lib/typeorm/find-options/EqualOperator.js +6 -10
- package/lib/typeorm/find-options/EqualOperator.js.map +1 -1
- package/lib/typeorm/find-options/FindManyOptions.js.map +1 -1
- package/lib/typeorm/find-options/FindOneOptions.js.map +1 -1
- package/lib/typeorm/find-options/FindOperator.js +90 -94
- package/lib/typeorm/find-options/FindOperator.js.map +1 -1
- package/lib/typeorm/find-options/FindOperatorType.js.map +1 -1
- package/lib/typeorm/find-options/FindOptionsOrder.js.map +1 -1
- package/lib/typeorm/find-options/FindOptionsRelations.js.map +1 -1
- package/lib/typeorm/find-options/FindOptionsSelect.js.map +1 -1
- package/lib/typeorm/find-options/FindOptionsUtils.js +56 -87
- package/lib/typeorm/find-options/FindOptionsUtils.js.map +1 -1
- package/lib/typeorm/find-options/FindOptionsWhere.js.map +1 -1
- package/lib/typeorm/find-options/FindTreeOptions.js.map +1 -1
- package/lib/typeorm/find-options/JoinOptions.js.map +1 -1
- package/lib/typeorm/find-options/OrderByCondition.js.map +1 -1
- package/lib/typeorm/find-options/mongodb/MongoFindManyOptions.js.map +1 -1
- package/lib/typeorm/find-options/mongodb/MongoFindOneOptions.js.map +1 -1
- package/lib/typeorm/find-options/operator/And.js +2 -6
- package/lib/typeorm/find-options/operator/And.js.map +1 -1
- package/lib/typeorm/find-options/operator/Any.js +1 -1
- package/lib/typeorm/find-options/operator/Any.js.map +1 -1
- package/lib/typeorm/find-options/operator/ArrayContainedBy.js +1 -1
- package/lib/typeorm/find-options/operator/ArrayContainedBy.js.map +1 -1
- package/lib/typeorm/find-options/operator/ArrayContains.js +1 -1
- package/lib/typeorm/find-options/operator/ArrayContains.js.map +1 -1
- package/lib/typeorm/find-options/operator/ArrayOverlap.js +1 -1
- package/lib/typeorm/find-options/operator/ArrayOverlap.js.map +1 -1
- package/lib/typeorm/find-options/operator/Between.js +1 -1
- package/lib/typeorm/find-options/operator/Between.js.map +1 -1
- package/lib/typeorm/find-options/operator/Equal.js +1 -1
- package/lib/typeorm/find-options/operator/Equal.js.map +1 -1
- package/lib/typeorm/find-options/operator/ILike.js +1 -1
- package/lib/typeorm/find-options/operator/ILike.js.map +1 -1
- package/lib/typeorm/find-options/operator/In.js +1 -1
- package/lib/typeorm/find-options/operator/In.js.map +1 -1
- package/lib/typeorm/find-options/operator/IsNull.js +1 -1
- package/lib/typeorm/find-options/operator/IsNull.js.map +1 -1
- package/lib/typeorm/find-options/operator/LessThan.js +1 -1
- package/lib/typeorm/find-options/operator/LessThan.js.map +1 -1
- package/lib/typeorm/find-options/operator/LessThanOrEqual.js +1 -1
- package/lib/typeorm/find-options/operator/LessThanOrEqual.js.map +1 -1
- package/lib/typeorm/find-options/operator/Like.js +1 -1
- package/lib/typeorm/find-options/operator/Like.js.map +1 -1
- package/lib/typeorm/find-options/operator/MoreThan.js +1 -1
- package/lib/typeorm/find-options/operator/MoreThan.js.map +1 -1
- package/lib/typeorm/find-options/operator/MoreThanOrEqual.js +1 -1
- package/lib/typeorm/find-options/operator/MoreThanOrEqual.js.map +1 -1
- package/lib/typeorm/find-options/operator/Not.js +1 -1
- package/lib/typeorm/find-options/operator/Not.js.map +1 -1
- package/lib/typeorm/find-options/operator/Raw.js +1 -1
- package/lib/typeorm/find-options/operator/Raw.js.map +1 -1
- package/lib/typeorm/globals.js +33 -99
- package/lib/typeorm/globals.js.map +1 -1
- package/lib/typeorm/index.d.ts +0 -1
- package/lib/typeorm/index.js +136 -126
- package/lib/typeorm/index.js.map +1 -1
- package/lib/typeorm/logger/AdvancedConsoleLogger.js +26 -26
- package/lib/typeorm/logger/AdvancedConsoleLogger.js.map +1 -1
- package/lib/typeorm/logger/DebugLogger.js +24 -27
- package/lib/typeorm/logger/DebugLogger.js.map +1 -1
- package/lib/typeorm/logger/FileLogger.js +31 -30
- package/lib/typeorm/logger/FileLogger.js.map +1 -1
- package/lib/typeorm/logger/Logger.js.map +1 -1
- package/lib/typeorm/logger/LoggerFactory.js +9 -12
- package/lib/typeorm/logger/LoggerFactory.js.map +1 -1
- package/lib/typeorm/logger/LoggerOptions.js.map +1 -1
- package/lib/typeorm/logger/SimpleConsoleLogger.js +25 -25
- package/lib/typeorm/logger/SimpleConsoleLogger.js.map +1 -1
- package/lib/typeorm/metadata/CheckMetadata.js +30 -6
- package/lib/typeorm/metadata/CheckMetadata.js.map +1 -1
- package/lib/typeorm/metadata/ColumnMetadata.js +343 -199
- package/lib/typeorm/metadata/ColumnMetadata.js.map +1 -1
- package/lib/typeorm/metadata/EmbeddedMetadata.js +174 -153
- package/lib/typeorm/metadata/EmbeddedMetadata.js.map +1 -1
- package/lib/typeorm/metadata/EntityListenerMetadata.js +35 -15
- package/lib/typeorm/metadata/EntityListenerMetadata.js.map +1 -1
- package/lib/typeorm/metadata/EntityMetadata.js +516 -372
- package/lib/typeorm/metadata/EntityMetadata.js.map +1 -1
- package/lib/typeorm/metadata/ExclusionMetadata.js +30 -6
- package/lib/typeorm/metadata/ExclusionMetadata.js.map +1 -1
- package/lib/typeorm/metadata/ForeignKeyMetadata.js +60 -24
- package/lib/typeorm/metadata/ForeignKeyMetadata.js.map +1 -1
- package/lib/typeorm/metadata/IndexMetadata.js +119 -73
- package/lib/typeorm/metadata/IndexMetadata.js.map +1 -1
- package/lib/typeorm/metadata/RelationCountMetadata.js +40 -10
- package/lib/typeorm/metadata/RelationCountMetadata.js.map +1 -1
- package/lib/typeorm/metadata/RelationIdMetadata.js +47 -18
- package/lib/typeorm/metadata/RelationIdMetadata.js.map +1 -1
- package/lib/typeorm/metadata/RelationMetadata.js +270 -187
- package/lib/typeorm/metadata/RelationMetadata.js.map +1 -1
- package/lib/typeorm/metadata/UniqueMetadata.js +72 -47
- package/lib/typeorm/metadata/UniqueMetadata.js.map +1 -1
- package/lib/typeorm/metadata/types/ClosureTreeOptions.js.map +1 -1
- package/lib/typeorm/metadata/types/DeferrableType.js.map +1 -1
- package/lib/typeorm/metadata/types/EventListenerTypes.js +13 -16
- package/lib/typeorm/metadata/types/EventListenerTypes.js.map +1 -1
- package/lib/typeorm/metadata/types/OnDeleteType.js.map +1 -1
- package/lib/typeorm/metadata/types/OnUpdateType.js.map +1 -1
- package/lib/typeorm/metadata/types/PropertyTypeInFunction.js.map +1 -1
- package/lib/typeorm/metadata/types/RelationTypeInFunction.js.map +1 -1
- package/lib/typeorm/metadata/types/RelationTypes.js.map +1 -1
- package/lib/typeorm/metadata/types/TableTypes.js.map +1 -1
- package/lib/typeorm/metadata/types/TreeTypes.js.map +1 -1
- package/lib/typeorm/metadata-args/CheckMetadataArgs.js.map +1 -1
- package/lib/typeorm/metadata-args/ColumnMetadataArgs.js.map +1 -1
- package/lib/typeorm/metadata-args/DiscriminatorValueMetadataArgs.js.map +1 -1
- package/lib/typeorm/metadata-args/EmbeddedMetadataArgs.js.map +1 -1
- package/lib/typeorm/metadata-args/EntityListenerMetadataArgs.js.map +1 -1
- package/lib/typeorm/metadata-args/EntityRepositoryMetadataArgs.js.map +1 -1
- package/lib/typeorm/metadata-args/EntitySubscriberMetadataArgs.js.map +1 -1
- package/lib/typeorm/metadata-args/ExclusionMetadataArgs.js.map +1 -1
- package/lib/typeorm/metadata-args/GeneratedMetadataArgs.js.map +1 -1
- package/lib/typeorm/metadata-args/IndexMetadataArgs.js.map +1 -1
- package/lib/typeorm/metadata-args/InheritanceMetadataArgs.js.map +1 -1
- package/lib/typeorm/metadata-args/JoinColumnMetadataArgs.js.map +1 -1
- package/lib/typeorm/metadata-args/JoinTableMetadataArgs.js.map +1 -1
- package/lib/typeorm/metadata-args/MetadataArgsStorage.js +108 -113
- package/lib/typeorm/metadata-args/MetadataArgsStorage.js.map +1 -1
- package/lib/typeorm/metadata-args/NamingStrategyMetadataArgs.js.map +1 -1
- package/lib/typeorm/metadata-args/RelationCountMetadataArgs.js.map +1 -1
- package/lib/typeorm/metadata-args/RelationIdMetadataArgs.js.map +1 -1
- package/lib/typeorm/metadata-args/RelationMetadataArgs.js.map +1 -1
- package/lib/typeorm/metadata-args/TableMetadataArgs.js.map +1 -1
- package/lib/typeorm/metadata-args/TransactionEntityMetadataArgs.js.map +1 -1
- package/lib/typeorm/metadata-args/TransactionRepositoryMetadataArgs.js.map +1 -1
- package/lib/typeorm/metadata-args/TreeMetadataArgs.js.map +1 -1
- package/lib/typeorm/metadata-args/UniqueMetadataArgs.js.map +1 -1
- package/lib/typeorm/metadata-args/types/ColumnMode.js.map +1 -1
- package/lib/typeorm/metadata-builder/ClosureJunctionEntityMetadataBuilder.js +14 -15
- package/lib/typeorm/metadata-builder/ClosureJunctionEntityMetadataBuilder.js.map +1 -1
- package/lib/typeorm/metadata-builder/EntityMetadataBuilder.js +291 -347
- package/lib/typeorm/metadata-builder/EntityMetadataBuilder.js.map +1 -1
- package/lib/typeorm/metadata-builder/EntityMetadataValidator.js +63 -77
- package/lib/typeorm/metadata-builder/EntityMetadataValidator.js.map +1 -1
- package/lib/typeorm/metadata-builder/JunctionEntityMetadataBuilder.js +64 -69
- package/lib/typeorm/metadata-builder/JunctionEntityMetadataBuilder.js.map +1 -1
- package/lib/typeorm/metadata-builder/MetadataUtils.js +12 -15
- package/lib/typeorm/metadata-builder/MetadataUtils.js.map +1 -1
- package/lib/typeorm/metadata-builder/RelationJoinColumnBuilder.js +43 -49
- package/lib/typeorm/metadata-builder/RelationJoinColumnBuilder.js.map +1 -1
- package/lib/typeorm/migration/Migration.js +23 -4
- package/lib/typeorm/migration/Migration.js.map +1 -1
- package/lib/typeorm/migration/MigrationExecutor.js +432 -691
- package/lib/typeorm/migration/MigrationExecutor.js.map +1 -1
- package/lib/typeorm/migration/MigrationInterface.js.map +1 -1
- package/lib/typeorm/naming-strategy/DefaultNamingStrategy.js +80 -84
- package/lib/typeorm/naming-strategy/DefaultNamingStrategy.js.map +1 -1
- package/lib/typeorm/naming-strategy/NamingStrategyInterface.js.map +1 -1
- package/lib/typeorm/persistence/EntityPersistExecutor.js +154 -212
- package/lib/typeorm/persistence/EntityPersistExecutor.js.map +1 -1
- package/lib/typeorm/persistence/Subject.js +162 -149
- package/lib/typeorm/persistence/Subject.js.map +1 -1
- package/lib/typeorm/persistence/SubjectChangeMap.js.map +1 -1
- package/lib/typeorm/persistence/SubjectChangedColumnsComputer.js +29 -35
- package/lib/typeorm/persistence/SubjectChangedColumnsComputer.js.map +1 -1
- package/lib/typeorm/persistence/SubjectDatabaseEntityLoader.js +99 -130
- package/lib/typeorm/persistence/SubjectDatabaseEntityLoader.js.map +1 -1
- package/lib/typeorm/persistence/SubjectExecutor.js +635 -879
- package/lib/typeorm/persistence/SubjectExecutor.js.map +1 -1
- package/lib/typeorm/persistence/SubjectTopoligicalSorter.js +62 -58
- package/lib/typeorm/persistence/SubjectTopoligicalSorter.js.map +1 -1
- package/lib/typeorm/persistence/subject-builder/CascadesSubjectBuilder.js +16 -19
- package/lib/typeorm/persistence/subject-builder/CascadesSubjectBuilder.js.map +1 -1
- package/lib/typeorm/persistence/subject-builder/ManyToManySubjectBuilder.js +50 -53
- package/lib/typeorm/persistence/subject-builder/ManyToManySubjectBuilder.js.map +1 -1
- package/lib/typeorm/persistence/subject-builder/OneToManySubjectBuilder.js +28 -33
- package/lib/typeorm/persistence/subject-builder/OneToManySubjectBuilder.js.map +1 -1
- package/lib/typeorm/persistence/subject-builder/OneToOneInverseSideSubjectBuilder.js +19 -20
- package/lib/typeorm/persistence/subject-builder/OneToOneInverseSideSubjectBuilder.js.map +1 -1
- package/lib/typeorm/persistence/tree/ClosureSubjectExecutor.js +202 -271
- package/lib/typeorm/persistence/tree/ClosureSubjectExecutor.js.map +1 -1
- package/lib/typeorm/persistence/tree/MaterializedPathSubjectExecutor.js +79 -121
- package/lib/typeorm/persistence/tree/MaterializedPathSubjectExecutor.js.map +1 -1
- package/lib/typeorm/persistence/tree/NestedSetSubjectExecutor.js +220 -353
- package/lib/typeorm/persistence/tree/NestedSetSubjectExecutor.js.map +1 -1
- package/lib/typeorm/platform/PlatformTools.js +66 -78
- package/lib/typeorm/platform/PlatformTools.js.map +1 -1
- package/lib/typeorm/query-builder/Alias.js +31 -32
- package/lib/typeorm/query-builder/Alias.js.map +1 -1
- package/lib/typeorm/query-builder/Brackets.js +8 -5
- package/lib/typeorm/query-builder/Brackets.js.map +1 -1
- package/lib/typeorm/query-builder/DeleteQueryBuilder.js +96 -120
- package/lib/typeorm/query-builder/DeleteQueryBuilder.js.map +1 -1
- package/lib/typeorm/query-builder/InsertOrUpdateOptions.js.map +1 -1
- package/lib/typeorm/query-builder/InsertQueryBuilder.js +321 -367
- package/lib/typeorm/query-builder/InsertQueryBuilder.js.map +1 -1
- package/lib/typeorm/query-builder/JoinAttribute.js +175 -206
- package/lib/typeorm/query-builder/JoinAttribute.js.map +1 -1
- package/lib/typeorm/query-builder/JoinOptions.js.map +1 -1
- package/lib/typeorm/query-builder/NotBrackets.js +4 -11
- package/lib/typeorm/query-builder/NotBrackets.js.map +1 -1
- package/lib/typeorm/query-builder/QueryBuilder.js +400 -646
- package/lib/typeorm/query-builder/QueryBuilder.js.map +1 -1
- package/lib/typeorm/query-builder/QueryBuilderCte.js.map +1 -1
- package/lib/typeorm/query-builder/QueryBuilderUtils.js +5 -9
- package/lib/typeorm/query-builder/QueryBuilderUtils.js.map +1 -1
- package/lib/typeorm/query-builder/QueryExpressionMap.js +304 -233
- package/lib/typeorm/query-builder/QueryExpressionMap.js.map +1 -1
- package/lib/typeorm/query-builder/QueryPartialEntity.js.map +1 -1
- package/lib/typeorm/query-builder/RelationIdLoader.js +166 -189
- package/lib/typeorm/query-builder/RelationIdLoader.js.map +1 -1
- package/lib/typeorm/query-builder/RelationLoader.js +81 -94
- package/lib/typeorm/query-builder/RelationLoader.js.map +1 -1
- package/lib/typeorm/query-builder/RelationQueryBuilder.js +91 -127
- package/lib/typeorm/query-builder/RelationQueryBuilder.js.map +1 -1
- package/lib/typeorm/query-builder/RelationRemover.js +121 -124
- package/lib/typeorm/query-builder/RelationRemover.js.map +1 -1
- package/lib/typeorm/query-builder/RelationUpdater.js +130 -148
- package/lib/typeorm/query-builder/RelationUpdater.js.map +1 -1
- package/lib/typeorm/query-builder/ReturningResultsEntityUpdator.js +131 -159
- package/lib/typeorm/query-builder/ReturningResultsEntityUpdator.js.map +1 -1
- package/lib/typeorm/query-builder/SelectQuery.js.map +1 -1
- package/lib/typeorm/query-builder/SelectQueryBuilder.js +955 -1211
- package/lib/typeorm/query-builder/SelectQueryBuilder.js.map +1 -1
- package/lib/typeorm/query-builder/SelectQueryBuilderOption.js.map +1 -1
- package/lib/typeorm/query-builder/SoftDeleteQueryBuilder.js +155 -194
- package/lib/typeorm/query-builder/SoftDeleteQueryBuilder.js.map +1 -1
- package/lib/typeorm/query-builder/UpdateQueryBuilder.js +204 -246
- package/lib/typeorm/query-builder/UpdateQueryBuilder.js.map +1 -1
- package/lib/typeorm/query-builder/WhereClause.js.map +1 -1
- package/lib/typeorm/query-builder/WhereExpressionBuilder.js.map +1 -1
- package/lib/typeorm/query-builder/relation-count/RelationCountAttribute.js +85 -98
- package/lib/typeorm/query-builder/relation-count/RelationCountAttribute.js.map +1 -1
- package/lib/typeorm/query-builder/relation-count/RelationCountLoadResult.js.map +1 -1
- package/lib/typeorm/query-builder/relation-count/RelationCountLoader.js +153 -172
- package/lib/typeorm/query-builder/relation-count/RelationCountLoader.js.map +1 -1
- package/lib/typeorm/query-builder/relation-count/RelationCountMetadataToAttributeTransformer.js +16 -17
- package/lib/typeorm/query-builder/relation-count/RelationCountMetadataToAttributeTransformer.js.map +1 -1
- package/lib/typeorm/query-builder/relation-id/RelationIdAttribute.js +93 -107
- package/lib/typeorm/query-builder/relation-id/RelationIdAttribute.js.map +1 -1
- package/lib/typeorm/query-builder/relation-id/RelationIdLoadResult.js.map +1 -1
- package/lib/typeorm/query-builder/relation-id/RelationIdLoader.js +259 -267
- package/lib/typeorm/query-builder/relation-id/RelationIdLoader.js.map +1 -1
- package/lib/typeorm/query-builder/relation-id/RelationIdMetadataToAttributeTransformer.js +16 -17
- package/lib/typeorm/query-builder/relation-id/RelationIdMetadataToAttributeTransformer.js.map +1 -1
- package/lib/typeorm/query-builder/result/DeleteResult.js +14 -8
- package/lib/typeorm/query-builder/result/DeleteResult.js.map +1 -1
- package/lib/typeorm/query-builder/result/InsertResult.js +19 -18
- package/lib/typeorm/query-builder/result/InsertResult.js.map +1 -1
- package/lib/typeorm/query-builder/result/UpdateResult.js +24 -18
- package/lib/typeorm/query-builder/result/UpdateResult.js.map +1 -1
- package/lib/typeorm/query-builder/transformer/DocumentToEntityTransformer.js +24 -26
- package/lib/typeorm/query-builder/transformer/DocumentToEntityTransformer.js.map +1 -1
- package/lib/typeorm/query-builder/transformer/PlainObjectToDatabaseEntityTransformer.js +77 -112
- package/lib/typeorm/query-builder/transformer/PlainObjectToDatabaseEntityTransformer.js.map +1 -1
- package/lib/typeorm/query-builder/transformer/PlainObjectToNewEntityTransformer.js +16 -22
- package/lib/typeorm/query-builder/transformer/PlainObjectToNewEntityTransformer.js.map +1 -1
- package/lib/typeorm/query-builder/transformer/RawSqlResultsToEntityTransformer.js +117 -132
- package/lib/typeorm/query-builder/transformer/RawSqlResultsToEntityTransformer.js.map +1 -1
- package/lib/typeorm/query-runner/BaseQueryRunner.js +227 -393
- package/lib/typeorm/query-runner/BaseQueryRunner.js.map +1 -1
- package/lib/typeorm/query-runner/QueryLock.js +19 -32
- package/lib/typeorm/query-runner/QueryLock.js.map +1 -1
- package/lib/typeorm/query-runner/QueryResult.js +14 -9
- package/lib/typeorm/query-runner/QueryResult.js.map +1 -1
- package/lib/typeorm/query-runner/QueryRunner.js.map +1 -1
- package/lib/typeorm/repository/AbstractRepository.js +46 -50
- package/lib/typeorm/repository/AbstractRepository.js.map +1 -1
- package/lib/typeorm/repository/BaseEntity.js +106 -123
- package/lib/typeorm/repository/BaseEntity.js.map +1 -1
- package/lib/typeorm/repository/EntityId.js.map +1 -1
- package/lib/typeorm/repository/FindTreesOptions.js.map +1 -1
- package/lib/typeorm/repository/MongoRepository.js +109 -135
- package/lib/typeorm/repository/MongoRepository.js.map +1 -1
- package/lib/typeorm/repository/RemoveOptions.js.map +1 -1
- package/lib/typeorm/repository/Repository.js +108 -140
- package/lib/typeorm/repository/Repository.js.map +1 -1
- package/lib/typeorm/repository/SaveOptions.js.map +1 -1
- package/lib/typeorm/repository/TreeRepository.js +107 -154
- package/lib/typeorm/repository/TreeRepository.js.map +1 -1
- package/lib/typeorm/repository/UpsertOptions.js.map +1 -1
- package/lib/typeorm/schema-builder/MongoSchemaBuilder.js +30 -42
- package/lib/typeorm/schema-builder/MongoSchemaBuilder.js.map +1 -1
- package/lib/typeorm/schema-builder/RdbmsSchemaBuilder.js +727 -1938
- package/lib/typeorm/schema-builder/RdbmsSchemaBuilder.js.map +1 -1
- package/lib/typeorm/schema-builder/SchemaBuilder.js.map +1 -1
- package/lib/typeorm/schema-builder/options/TableCheckOptions.js.map +1 -1
- package/lib/typeorm/schema-builder/options/TableColumnOptions.js.map +1 -1
- package/lib/typeorm/schema-builder/options/TableExclusionOptions.js.map +1 -1
- package/lib/typeorm/schema-builder/options/TableForeignKeyOptions.js.map +1 -1
- package/lib/typeorm/schema-builder/options/TableIndexOptions.js.map +1 -1
- package/lib/typeorm/schema-builder/options/TableOptions.js.map +1 -1
- package/lib/typeorm/schema-builder/options/TableUniqueOptions.js.map +1 -1
- package/lib/typeorm/schema-builder/options/ViewOptions.js.map +1 -1
- package/lib/typeorm/schema-builder/table/Table.js +160 -157
- package/lib/typeorm/schema-builder/table/Table.js.map +1 -1
- package/lib/typeorm/schema-builder/table/TableCheck.js +24 -15
- package/lib/typeorm/schema-builder/table/TableCheck.js.map +1 -1
- package/lib/typeorm/schema-builder/table/TableColumn.js +123 -41
- package/lib/typeorm/schema-builder/table/TableColumn.js.map +1 -1
- package/lib/typeorm/schema-builder/table/TableExclusion.js +19 -9
- package/lib/typeorm/schema-builder/table/TableExclusion.js.map +1 -1
- package/lib/typeorm/schema-builder/table/TableForeignKey.js +52 -20
- package/lib/typeorm/schema-builder/table/TableForeignKey.js.map +1 -1
- package/lib/typeorm/schema-builder/table/TableIndex.js +52 -16
- package/lib/typeorm/schema-builder/table/TableIndex.js.map +1 -1
- package/lib/typeorm/schema-builder/table/TableUnique.js +26 -16
- package/lib/typeorm/schema-builder/table/TableUnique.js.map +1 -1
- package/lib/typeorm/schema-builder/util/TableUtils.js +5 -8
- package/lib/typeorm/schema-builder/util/TableUtils.js.map +1 -1
- package/lib/typeorm/schema-builder/util/ViewUtils.js +4 -7
- package/lib/typeorm/schema-builder/util/ViewUtils.js.map +1 -1
- package/lib/typeorm/schema-builder/view/View.js +32 -10
- package/lib/typeorm/schema-builder/view/View.js.map +1 -1
- package/lib/typeorm/subscriber/Broadcaster.js +180 -216
- package/lib/typeorm/subscriber/Broadcaster.js.map +1 -1
- package/lib/typeorm/subscriber/BroadcasterResult.js +16 -29
- package/lib/typeorm/subscriber/BroadcasterResult.js.map +1 -1
- package/lib/typeorm/subscriber/EntitySubscriberInterface.js.map +1 -1
- package/lib/typeorm/subscriber/event/InsertEvent.js.map +1 -1
- package/lib/typeorm/subscriber/event/LoadEvent.js.map +1 -1
- package/lib/typeorm/subscriber/event/RecoverEvent.js.map +1 -1
- package/lib/typeorm/subscriber/event/RemoveEvent.js.map +1 -1
- package/lib/typeorm/subscriber/event/SoftRemoveEvent.js.map +1 -1
- package/lib/typeorm/subscriber/event/TransactionCommitEvent.js.map +1 -1
- package/lib/typeorm/subscriber/event/TransactionRollbackEvent.js.map +1 -1
- package/lib/typeorm/subscriber/event/TransactionStartEvent.js.map +1 -1
- package/lib/typeorm/subscriber/event/UpdateEvent.js.map +1 -1
- package/lib/typeorm/util/ApplyValueTransformers.js +9 -12
- package/lib/typeorm/util/ApplyValueTransformers.js.map +1 -1
- package/lib/typeorm/util/DateUtils.js +44 -53
- package/lib/typeorm/util/DateUtils.js.map +1 -1
- package/lib/typeorm/util/DepGraph.js +50 -53
- package/lib/typeorm/util/DepGraph.js.map +1 -1
- package/lib/typeorm/util/DirectoryExportedClassesLoader.js +48 -70
- package/lib/typeorm/util/DirectoryExportedClassesLoader.js.map +1 -1
- package/lib/typeorm/util/ImportUtils.js +43 -65
- package/lib/typeorm/util/ImportUtils.js.map +1 -1
- package/lib/typeorm/util/InstanceChecker.js +64 -67
- package/lib/typeorm/util/InstanceChecker.js.map +1 -1
- package/lib/typeorm/util/ObjectUtils.js +13 -42
- package/lib/typeorm/util/ObjectUtils.js.map +1 -1
- package/lib/typeorm/util/OrmUtils.js +91 -158
- package/lib/typeorm/util/OrmUtils.js.map +1 -1
- package/lib/typeorm/util/PathUtils.js +8 -8
- package/lib/typeorm/util/PathUtils.js.map +1 -1
- package/lib/typeorm/util/RandomGenerator.js +22 -25
- package/lib/typeorm/util/RandomGenerator.js.map +1 -1
- package/lib/typeorm/util/StringUtils.js +17 -21
- package/lib/typeorm/util/StringUtils.js.map +1 -1
- package/lib/typeorm/util/TreeRepositoryUtils.js +27 -30
- package/lib/typeorm/util/TreeRepositoryUtils.js.map +1 -1
- package/lib/typeorm/util/VersionUtils.js +9 -13
- package/lib/typeorm/util/VersionUtils.js.map +1 -1
- package/lib/typeorm/util/escapeRegExp.js +2 -2
- package/lib/typeorm/util/escapeRegExp.js.map +1 -1
- package/migrations/index.js +15 -2
- package/migrations/index.js.map +1 -1
- package/migrations/migrations_index._auto-generated_.d.ts +1 -0
- package/migrations/migrations_index._auto-generated_.js.map +1 -1
- package/package.json +8 -44
- package/src.d.ts +1 -1
- package/taon.jsonc +3 -30
- package/tmp-environment.json +8 -370
- package/websql/esm2022/lib/typeorm/driver/cordova/CordovaDriver.mjs +1 -1
- package/websql/esm2022/lib/typeorm/driver/cordova/CordovaQueryRunner.mjs +1 -1
- package/websql/esm2022/lib/typeorm/driver/nativescript/NativescriptDriver.mjs +1 -1
- package/websql/esm2022/lib/typeorm/driver/nativescript/NativescriptQueryRunner.mjs +1 -1
- package/websql/esm2022/lib/typeorm/driver/react-native/ReactNativeDriver.mjs +1 -1
- package/websql/esm2022/lib/typeorm/driver/react-native/ReactNativeQueryRunner.mjs +1 -1
- package/websql/esm2022/lib/typeorm/driver/sqljs/SqljsDriver.mjs +1 -1
- package/websql/esm2022/lib/typeorm/driver/sqljs/SqljsQueryRunner.mjs +1 -1
- package/websql/esm2022/lib/typeorm/index.mjs +1 -3
- package/websql/fesm2022/taon-typeorm.mjs.map +1 -1
- package/browser/package.json +0 -25
- package/websql/package.json +0 -25
|
@@ -1,43 +1,54 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SapQueryRunner = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
var util_1 = require("util");
|
|
4
|
+
const QueryRunnerAlreadyReleasedError_1 = require("../../error/QueryRunnerAlreadyReleasedError");
|
|
5
|
+
const TransactionAlreadyStartedError_1 = require("../../error/TransactionAlreadyStartedError");
|
|
6
|
+
const TransactionNotStartedError_1 = require("../../error/TransactionNotStartedError");
|
|
7
|
+
const BaseQueryRunner_1 = require("../../query-runner/BaseQueryRunner");
|
|
8
|
+
const Table_1 = require("../../schema-builder/table/Table");
|
|
9
|
+
const TableCheck_1 = require("../../schema-builder/table/TableCheck");
|
|
10
|
+
const TableColumn_1 = require("../../schema-builder/table/TableColumn");
|
|
11
|
+
const TableForeignKey_1 = require("../../schema-builder/table/TableForeignKey");
|
|
12
|
+
const TableIndex_1 = require("../../schema-builder/table/TableIndex");
|
|
13
|
+
const TableUnique_1 = require("../../schema-builder/table/TableUnique");
|
|
14
|
+
const View_1 = require("../../schema-builder/view/View");
|
|
15
|
+
const Broadcaster_1 = require("../../subscriber/Broadcaster");
|
|
16
|
+
const OrmUtils_1 = require("../../util/OrmUtils");
|
|
17
|
+
const Query_1 = require("../Query");
|
|
18
|
+
const error_1 = require("../../error");
|
|
19
|
+
const QueryResult_1 = require("../../query-runner/QueryResult");
|
|
20
|
+
const QueryLock_1 = require("../../query-runner/QueryLock");
|
|
21
|
+
const MetadataTableType_1 = require("../types/MetadataTableType");
|
|
22
|
+
const InstanceChecker_1 = require("../../util/InstanceChecker");
|
|
23
|
+
const util_1 = require("util");
|
|
25
24
|
/**
|
|
26
25
|
* Runs queries on a single SQL Server database connection.
|
|
27
26
|
*/
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
class SapQueryRunner extends BaseQueryRunner_1.BaseQueryRunner {
|
|
28
|
+
// -------------------------------------------------------------------------
|
|
29
|
+
// Public Implemented Properties
|
|
30
|
+
// -------------------------------------------------------------------------
|
|
31
|
+
/**
|
|
32
|
+
* Database driver used by connection.
|
|
33
|
+
*/
|
|
34
|
+
driver;
|
|
35
|
+
// -------------------------------------------------------------------------
|
|
36
|
+
// Protected Properties
|
|
37
|
+
// -------------------------------------------------------------------------
|
|
38
|
+
/**
|
|
39
|
+
* Promise used to obtain a database connection from a pool for a first time.
|
|
40
|
+
*/
|
|
41
|
+
databaseConnectionPromise;
|
|
42
|
+
lock = new QueryLock_1.QueryLock();
|
|
30
43
|
// -------------------------------------------------------------------------
|
|
31
44
|
// Constructor
|
|
32
45
|
// -------------------------------------------------------------------------
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
_this.mode = mode;
|
|
40
|
-
return _this;
|
|
46
|
+
constructor(driver, mode) {
|
|
47
|
+
super();
|
|
48
|
+
this.driver = driver;
|
|
49
|
+
this.connection = driver.connection;
|
|
50
|
+
this.broadcaster = new Broadcaster_1.Broadcaster(this);
|
|
51
|
+
this.mode = mode;
|
|
41
52
|
}
|
|
42
53
|
// -------------------------------------------------------------------------
|
|
43
54
|
// Public Methods
|
|
@@ -46,2608 +57,1693 @@ var SapQueryRunner = /** @class */ (function (_super) {
|
|
|
46
57
|
* Creates/uses database connection from the connection pool to perform further operations.
|
|
47
58
|
* Returns obtained database connection.
|
|
48
59
|
*/
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
if (this.databaseConnection)
|
|
56
|
-
return [2 /*return*/, this.databaseConnection];
|
|
57
|
-
_a = this;
|
|
58
|
-
return [4 /*yield*/, this.driver.obtainMasterConnection()];
|
|
59
|
-
case 1:
|
|
60
|
-
_a.databaseConnection = _b.sent();
|
|
61
|
-
return [2 /*return*/, this.databaseConnection];
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
};
|
|
60
|
+
async connect() {
|
|
61
|
+
if (this.databaseConnection)
|
|
62
|
+
return this.databaseConnection;
|
|
63
|
+
this.databaseConnection = await this.driver.obtainMasterConnection();
|
|
64
|
+
return this.databaseConnection;
|
|
65
|
+
}
|
|
66
66
|
/**
|
|
67
67
|
* Releases used database connection.
|
|
68
68
|
* You cannot use query runner methods once its released.
|
|
69
69
|
*/
|
|
70
|
-
|
|
70
|
+
release() {
|
|
71
71
|
this.isReleased = true;
|
|
72
72
|
if (this.databaseConnection) {
|
|
73
73
|
return this.driver.master.release(this.databaseConnection);
|
|
74
74
|
}
|
|
75
75
|
return Promise.resolve();
|
|
76
|
-
}
|
|
76
|
+
}
|
|
77
77
|
/**
|
|
78
78
|
* Starts transaction.
|
|
79
79
|
*/
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
return [4 /*yield*/, this.setAutoCommit({ status: "off" })];
|
|
99
|
-
case 2:
|
|
100
|
-
/**
|
|
101
|
-
* Disable AUTOCOMMIT while running transaction.
|
|
102
|
-
* Otherwise, COMMIT/ROLLBACK doesn't work in autocommit mode.
|
|
103
|
-
*/
|
|
104
|
-
_a.sent();
|
|
105
|
-
if (!isolationLevel) return [3 /*break*/, 4];
|
|
106
|
-
return [4 /*yield*/, this.query("SET TRANSACTION ISOLATION LEVEL ".concat(isolationLevel || ""))];
|
|
107
|
-
case 3:
|
|
108
|
-
_a.sent();
|
|
109
|
-
_a.label = 4;
|
|
110
|
-
case 4: return [4 /*yield*/, this.broadcaster.broadcast("AfterTransactionStart")];
|
|
111
|
-
case 5:
|
|
112
|
-
_a.sent();
|
|
113
|
-
return [2 /*return*/];
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
});
|
|
117
|
-
};
|
|
80
|
+
async startTransaction(isolationLevel) {
|
|
81
|
+
if (this.isReleased)
|
|
82
|
+
throw new QueryRunnerAlreadyReleasedError_1.QueryRunnerAlreadyReleasedError();
|
|
83
|
+
if (this.isTransactionActive &&
|
|
84
|
+
this.driver.transactionSupport === "simple")
|
|
85
|
+
throw new TransactionAlreadyStartedError_1.TransactionAlreadyStartedError();
|
|
86
|
+
await this.broadcaster.broadcast("BeforeTransactionStart");
|
|
87
|
+
this.isTransactionActive = true;
|
|
88
|
+
/**
|
|
89
|
+
* Disable AUTOCOMMIT while running transaction.
|
|
90
|
+
* Otherwise, COMMIT/ROLLBACK doesn't work in autocommit mode.
|
|
91
|
+
*/
|
|
92
|
+
await this.setAutoCommit({ status: "off" });
|
|
93
|
+
if (isolationLevel) {
|
|
94
|
+
await this.query(`SET TRANSACTION ISOLATION LEVEL ${isolationLevel || ""}`);
|
|
95
|
+
}
|
|
96
|
+
await this.broadcaster.broadcast("AfterTransactionStart");
|
|
97
|
+
}
|
|
118
98
|
/**
|
|
119
99
|
* Commits transaction.
|
|
120
100
|
* Error will be thrown if transaction was not started.
|
|
121
101
|
*/
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
_a.sent();
|
|
134
|
-
return [4 /*yield*/, this.query("COMMIT")];
|
|
135
|
-
case 2:
|
|
136
|
-
_a.sent();
|
|
137
|
-
this.isTransactionActive = false;
|
|
138
|
-
return [4 /*yield*/, this.setAutoCommit({ status: "on" })];
|
|
139
|
-
case 3:
|
|
140
|
-
_a.sent();
|
|
141
|
-
return [4 /*yield*/, this.broadcaster.broadcast("AfterTransactionCommit")];
|
|
142
|
-
case 4:
|
|
143
|
-
_a.sent();
|
|
144
|
-
return [2 /*return*/];
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
});
|
|
148
|
-
};
|
|
102
|
+
async commitTransaction() {
|
|
103
|
+
if (this.isReleased)
|
|
104
|
+
throw new QueryRunnerAlreadyReleasedError_1.QueryRunnerAlreadyReleasedError();
|
|
105
|
+
if (!this.isTransactionActive)
|
|
106
|
+
throw new TransactionNotStartedError_1.TransactionNotStartedError();
|
|
107
|
+
await this.broadcaster.broadcast("BeforeTransactionCommit");
|
|
108
|
+
await this.query("COMMIT");
|
|
109
|
+
this.isTransactionActive = false;
|
|
110
|
+
await this.setAutoCommit({ status: "on" });
|
|
111
|
+
await this.broadcaster.broadcast("AfterTransactionCommit");
|
|
112
|
+
}
|
|
149
113
|
/**
|
|
150
114
|
* Rollbacks transaction.
|
|
151
115
|
* Error will be thrown if transaction was not started.
|
|
152
116
|
*/
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
_a.sent();
|
|
165
|
-
return [4 /*yield*/, this.query("ROLLBACK")];
|
|
166
|
-
case 2:
|
|
167
|
-
_a.sent();
|
|
168
|
-
this.isTransactionActive = false;
|
|
169
|
-
return [4 /*yield*/, this.setAutoCommit({ status: "on" })];
|
|
170
|
-
case 3:
|
|
171
|
-
_a.sent();
|
|
172
|
-
return [4 /*yield*/, this.broadcaster.broadcast("AfterTransactionRollback")];
|
|
173
|
-
case 4:
|
|
174
|
-
_a.sent();
|
|
175
|
-
return [2 /*return*/];
|
|
176
|
-
}
|
|
177
|
-
});
|
|
178
|
-
});
|
|
179
|
-
};
|
|
117
|
+
async rollbackTransaction() {
|
|
118
|
+
if (this.isReleased)
|
|
119
|
+
throw new QueryRunnerAlreadyReleasedError_1.QueryRunnerAlreadyReleasedError();
|
|
120
|
+
if (!this.isTransactionActive)
|
|
121
|
+
throw new TransactionNotStartedError_1.TransactionNotStartedError();
|
|
122
|
+
await this.broadcaster.broadcast("BeforeTransactionRollback");
|
|
123
|
+
await this.query("ROLLBACK");
|
|
124
|
+
this.isTransactionActive = false;
|
|
125
|
+
await this.setAutoCommit({ status: "on" });
|
|
126
|
+
await this.broadcaster.broadcast("AfterTransactionRollback");
|
|
127
|
+
}
|
|
180
128
|
/**
|
|
181
129
|
* @description Switches on/off AUTOCOMMIT mode
|
|
182
130
|
* @link https://help.sap.com/docs/HANA_SERVICE_CF/7c78579ce9b14a669c1f3295b0d8ca16/d538d11053bd4f3f847ec5ce817a3d4c.html?locale=en-US
|
|
183
131
|
*/
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
case 2:
|
|
197
|
-
_a.trys.push([2, 4, , 5]);
|
|
198
|
-
return [4 /*yield*/, execute(query)];
|
|
199
|
-
case 3:
|
|
200
|
-
_a.sent();
|
|
201
|
-
return [3 /*break*/, 5];
|
|
202
|
-
case 4:
|
|
203
|
-
error_2 = _a.sent();
|
|
204
|
-
throw new error_1.QueryFailedError(query, [], error_2);
|
|
205
|
-
case 5: return [2 /*return*/];
|
|
206
|
-
}
|
|
207
|
-
});
|
|
208
|
-
});
|
|
209
|
-
};
|
|
132
|
+
async setAutoCommit(options) {
|
|
133
|
+
const connection = await this.connect();
|
|
134
|
+
const execute = (0, util_1.promisify)(connection.exec.bind(connection));
|
|
135
|
+
connection.setAutoCommit(options.status === "on");
|
|
136
|
+
const query = `SET TRANSACTION AUTOCOMMIT DDL ${options.status.toUpperCase()};`;
|
|
137
|
+
try {
|
|
138
|
+
await execute(query);
|
|
139
|
+
}
|
|
140
|
+
catch (error) {
|
|
141
|
+
throw new error_1.QueryFailedError(query, [], error);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
210
144
|
/**
|
|
211
145
|
* Executes a given SQL query.
|
|
212
146
|
*/
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
return [4 /*yield*/, this.connect()];
|
|
230
|
-
case 3:
|
|
231
|
-
databaseConnection_1 = _a.sent();
|
|
232
|
-
this.driver.connection.logger.logQuery(query, parameters, this);
|
|
233
|
-
queryStartTime = +new Date();
|
|
234
|
-
isInsertQuery = query.substr(0, 11) === "INSERT INTO";
|
|
235
|
-
statement = databaseConnection_1.prepare(query);
|
|
236
|
-
return [4 /*yield*/, new Promise(function (ok, fail) {
|
|
237
|
-
statement.exec(parameters, function (err, raw) {
|
|
238
|
-
return err
|
|
239
|
-
? fail(new error_1.QueryFailedError(query, parameters, err))
|
|
240
|
-
: ok(raw);
|
|
241
|
-
});
|
|
242
|
-
})
|
|
243
|
-
// log slow queries if maxQueryExecution time is set
|
|
244
|
-
];
|
|
245
|
-
case 4:
|
|
246
|
-
raw = _a.sent();
|
|
247
|
-
maxQueryExecutionTime = this.driver.connection.options.maxQueryExecutionTime;
|
|
248
|
-
queryEndTime = +new Date();
|
|
249
|
-
queryExecutionTime = queryEndTime - queryStartTime;
|
|
250
|
-
if (maxQueryExecutionTime &&
|
|
251
|
-
queryExecutionTime > maxQueryExecutionTime) {
|
|
252
|
-
this.driver.connection.logger.logQuerySlow(queryExecutionTime, query, parameters, this);
|
|
253
|
-
}
|
|
254
|
-
if (typeof raw === "number") {
|
|
255
|
-
result.affected = raw;
|
|
256
|
-
}
|
|
257
|
-
else if (Array.isArray(raw)) {
|
|
258
|
-
result.records = raw;
|
|
259
|
-
}
|
|
260
|
-
result.raw = raw;
|
|
261
|
-
if (!isInsertQuery) return [3 /*break*/, 6];
|
|
262
|
-
lastIdQuery_1 = "SELECT CURRENT_IDENTITY_VALUE() FROM \"SYS\".\"DUMMY\"";
|
|
263
|
-
this.driver.connection.logger.logQuery(lastIdQuery_1, [], this);
|
|
264
|
-
return [4 /*yield*/, new Promise(function (ok, fail) {
|
|
265
|
-
databaseConnection_1.exec(lastIdQuery_1, function (err, raw) {
|
|
266
|
-
return err
|
|
267
|
-
? fail(new error_1.QueryFailedError(lastIdQuery_1, [], err))
|
|
268
|
-
: ok(raw);
|
|
269
|
-
});
|
|
270
|
-
})];
|
|
271
|
-
case 5:
|
|
272
|
-
identityValueResult = _a.sent();
|
|
273
|
-
result.raw = identityValueResult[0]["CURRENT_IDENTITY_VALUE()"];
|
|
274
|
-
result.records = identityValueResult;
|
|
275
|
-
_a.label = 6;
|
|
276
|
-
case 6: return [3 /*break*/, 11];
|
|
277
|
-
case 7:
|
|
278
|
-
e_1 = _a.sent();
|
|
279
|
-
this.driver.connection.logger.logQueryError(e_1, query, parameters, this);
|
|
280
|
-
throw e_1;
|
|
281
|
-
case 8:
|
|
282
|
-
if (!(statement === null || statement === void 0 ? void 0 : statement.drop)) return [3 /*break*/, 10];
|
|
283
|
-
return [4 /*yield*/, new Promise(function (ok) { return statement.drop(function () { return ok(); }); })];
|
|
284
|
-
case 9:
|
|
285
|
-
_a.sent();
|
|
286
|
-
_a.label = 10;
|
|
287
|
-
case 10:
|
|
288
|
-
// Always release the lock.
|
|
289
|
-
release();
|
|
290
|
-
return [7 /*endfinally*/];
|
|
291
|
-
case 11:
|
|
292
|
-
if (useStructuredResult) {
|
|
293
|
-
return [2 /*return*/, result];
|
|
294
|
-
}
|
|
295
|
-
else {
|
|
296
|
-
return [2 /*return*/, result.raw];
|
|
297
|
-
}
|
|
298
|
-
return [2 /*return*/];
|
|
299
|
-
}
|
|
147
|
+
async query(query, parameters, useStructuredResult = false) {
|
|
148
|
+
if (this.isReleased)
|
|
149
|
+
throw new QueryRunnerAlreadyReleasedError_1.QueryRunnerAlreadyReleasedError();
|
|
150
|
+
const release = await this.lock.acquire();
|
|
151
|
+
let statement;
|
|
152
|
+
const result = new QueryResult_1.QueryResult();
|
|
153
|
+
try {
|
|
154
|
+
const databaseConnection = await this.connect();
|
|
155
|
+
this.driver.connection.logger.logQuery(query, parameters, this);
|
|
156
|
+
const queryStartTime = +new Date();
|
|
157
|
+
const isInsertQuery = query.substr(0, 11) === "INSERT INTO";
|
|
158
|
+
statement = databaseConnection.prepare(query);
|
|
159
|
+
const raw = await new Promise((ok, fail) => {
|
|
160
|
+
statement.exec(parameters, (err, raw) => err
|
|
161
|
+
? fail(new error_1.QueryFailedError(query, parameters, err))
|
|
162
|
+
: ok(raw));
|
|
300
163
|
});
|
|
301
|
-
|
|
302
|
-
|
|
164
|
+
// log slow queries if maxQueryExecution time is set
|
|
165
|
+
const maxQueryExecutionTime = this.driver.connection.options.maxQueryExecutionTime;
|
|
166
|
+
const queryEndTime = +new Date();
|
|
167
|
+
const queryExecutionTime = queryEndTime - queryStartTime;
|
|
168
|
+
if (maxQueryExecutionTime &&
|
|
169
|
+
queryExecutionTime > maxQueryExecutionTime) {
|
|
170
|
+
this.driver.connection.logger.logQuerySlow(queryExecutionTime, query, parameters, this);
|
|
171
|
+
}
|
|
172
|
+
if (typeof raw === "number") {
|
|
173
|
+
result.affected = raw;
|
|
174
|
+
}
|
|
175
|
+
else if (Array.isArray(raw)) {
|
|
176
|
+
result.records = raw;
|
|
177
|
+
}
|
|
178
|
+
result.raw = raw;
|
|
179
|
+
if (isInsertQuery) {
|
|
180
|
+
const lastIdQuery = `SELECT CURRENT_IDENTITY_VALUE() FROM "SYS"."DUMMY"`;
|
|
181
|
+
this.driver.connection.logger.logQuery(lastIdQuery, [], this);
|
|
182
|
+
const identityValueResult = await new Promise((ok, fail) => {
|
|
183
|
+
databaseConnection.exec(lastIdQuery, (err, raw) => err
|
|
184
|
+
? fail(new error_1.QueryFailedError(lastIdQuery, [], err))
|
|
185
|
+
: ok(raw));
|
|
186
|
+
});
|
|
187
|
+
result.raw = identityValueResult[0]["CURRENT_IDENTITY_VALUE()"];
|
|
188
|
+
result.records = identityValueResult;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
catch (e) {
|
|
192
|
+
this.driver.connection.logger.logQueryError(e, query, parameters, this);
|
|
193
|
+
throw e;
|
|
194
|
+
}
|
|
195
|
+
finally {
|
|
196
|
+
// Never forget to drop the statement we reserved
|
|
197
|
+
if (statement?.drop) {
|
|
198
|
+
await new Promise((ok) => statement.drop(() => ok()));
|
|
199
|
+
}
|
|
200
|
+
// Always release the lock.
|
|
201
|
+
release();
|
|
202
|
+
}
|
|
203
|
+
if (useStructuredResult) {
|
|
204
|
+
return result;
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
return result.raw;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
303
210
|
/**
|
|
304
211
|
* Returns raw data stream.
|
|
305
212
|
*/
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
throw new error_1.TypeORMError("Stream is not supported by SAP driver.");
|
|
310
|
-
});
|
|
311
|
-
});
|
|
312
|
-
};
|
|
213
|
+
async stream(query, parameters, onEnd, onError) {
|
|
214
|
+
throw new error_1.TypeORMError(`Stream is not supported by SAP driver.`);
|
|
215
|
+
}
|
|
313
216
|
/**
|
|
314
217
|
* Returns all available database names including system databases.
|
|
315
218
|
*/
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
switch (_a.label) {
|
|
321
|
-
case 0: return [4 /*yield*/, this.query("SELECT DATABASE_NAME FROM \"SYS\".\"M_DATABASES\"")];
|
|
322
|
-
case 1:
|
|
323
|
-
results = _a.sent();
|
|
324
|
-
return [2 /*return*/, results.map(function (result) { return result["DATABASE_NAME"]; })];
|
|
325
|
-
}
|
|
326
|
-
});
|
|
327
|
-
});
|
|
328
|
-
};
|
|
219
|
+
async getDatabases() {
|
|
220
|
+
const results = await this.query(`SELECT DATABASE_NAME FROM "SYS"."M_DATABASES"`);
|
|
221
|
+
return results.map((result) => result["DATABASE_NAME"]);
|
|
222
|
+
}
|
|
329
223
|
/**
|
|
330
224
|
* Returns all available schema names including system schemas.
|
|
331
225
|
* If database parameter specified, returns schemas of that database.
|
|
332
226
|
*/
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
? "SELECT * FROM \"".concat(database, "\".\"SYS\".\"SCHEMAS\"")
|
|
341
|
-
: "SELECT * FROM \"SYS\".\"SCHEMAS\"";
|
|
342
|
-
return [4 /*yield*/, this.query(query)];
|
|
343
|
-
case 1:
|
|
344
|
-
results = _a.sent();
|
|
345
|
-
return [2 /*return*/, results.map(function (result) { return result["SCHEMA_NAME"]; })];
|
|
346
|
-
}
|
|
347
|
-
});
|
|
348
|
-
});
|
|
349
|
-
};
|
|
227
|
+
async getSchemas(database) {
|
|
228
|
+
const query = database
|
|
229
|
+
? `SELECT * FROM "${database}"."SYS"."SCHEMAS"`
|
|
230
|
+
: `SELECT * FROM "SYS"."SCHEMAS"`;
|
|
231
|
+
const results = await this.query(query);
|
|
232
|
+
return results.map((result) => result["SCHEMA_NAME"]);
|
|
233
|
+
}
|
|
350
234
|
/**
|
|
351
235
|
* Checks if database with the given name exist.
|
|
352
236
|
*/
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
switch (_a.label) {
|
|
358
|
-
case 0: return [4 /*yield*/, this.getDatabases()];
|
|
359
|
-
case 1:
|
|
360
|
-
databases = _a.sent();
|
|
361
|
-
return [2 /*return*/, databases.indexOf(database) !== -1];
|
|
362
|
-
}
|
|
363
|
-
});
|
|
364
|
-
});
|
|
365
|
-
};
|
|
237
|
+
async hasDatabase(database) {
|
|
238
|
+
const databases = await this.getDatabases();
|
|
239
|
+
return databases.indexOf(database) !== -1;
|
|
240
|
+
}
|
|
366
241
|
/**
|
|
367
242
|
* Returns current database.
|
|
368
243
|
*/
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
switch (_a.label) {
|
|
374
|
-
case 0: return [4 /*yield*/, this.query("SELECT \"VALUE\" AS \"db_name\" FROM \"SYS\".\"M_SYSTEM_OVERVIEW\" WHERE \"SECTION\" = 'System' and \"NAME\" = 'Instance ID'")];
|
|
375
|
-
case 1:
|
|
376
|
-
currentDBQuery = _a.sent();
|
|
377
|
-
return [2 /*return*/, currentDBQuery[0]["db_name"]];
|
|
378
|
-
}
|
|
379
|
-
});
|
|
380
|
-
});
|
|
381
|
-
};
|
|
244
|
+
async getCurrentDatabase() {
|
|
245
|
+
const currentDBQuery = await this.query(`SELECT "VALUE" AS "db_name" FROM "SYS"."M_SYSTEM_OVERVIEW" WHERE "SECTION" = 'System' and "NAME" = 'Instance ID'`);
|
|
246
|
+
return currentDBQuery[0]["db_name"];
|
|
247
|
+
}
|
|
382
248
|
/**
|
|
383
249
|
* Checks if schema with the given name exist.
|
|
384
250
|
*/
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
switch (_a.label) {
|
|
390
|
-
case 0: return [4 /*yield*/, this.getSchemas()];
|
|
391
|
-
case 1:
|
|
392
|
-
schemas = _a.sent();
|
|
393
|
-
return [2 /*return*/, schemas.indexOf(schema) !== -1];
|
|
394
|
-
}
|
|
395
|
-
});
|
|
396
|
-
});
|
|
397
|
-
};
|
|
251
|
+
async hasSchema(schema) {
|
|
252
|
+
const schemas = await this.getSchemas();
|
|
253
|
+
return schemas.indexOf(schema) !== -1;
|
|
254
|
+
}
|
|
398
255
|
/**
|
|
399
256
|
* Returns current schema.
|
|
400
257
|
*/
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
switch (_a.label) {
|
|
406
|
-
case 0: return [4 /*yield*/, this.query("SELECT CURRENT_SCHEMA AS \"schema_name\" FROM \"SYS\".\"DUMMY\"")];
|
|
407
|
-
case 1:
|
|
408
|
-
currentSchemaQuery = _a.sent();
|
|
409
|
-
return [2 /*return*/, currentSchemaQuery[0]["schema_name"]];
|
|
410
|
-
}
|
|
411
|
-
});
|
|
412
|
-
});
|
|
413
|
-
};
|
|
258
|
+
async getCurrentSchema() {
|
|
259
|
+
const currentSchemaQuery = await this.query(`SELECT CURRENT_SCHEMA AS "schema_name" FROM "SYS"."DUMMY"`);
|
|
260
|
+
return currentSchemaQuery[0]["schema_name"];
|
|
261
|
+
}
|
|
414
262
|
/**
|
|
415
263
|
* Checks if table with the given name exist in the database.
|
|
416
264
|
*/
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
return [4 /*yield*/, this.getCurrentSchema()];
|
|
427
|
-
case 1:
|
|
428
|
-
_a.schema = _b.sent();
|
|
429
|
-
_b.label = 2;
|
|
430
|
-
case 2:
|
|
431
|
-
sql = "SELECT * FROM \"SYS\".\"TABLES\" WHERE \"SCHEMA_NAME\" = '".concat(parsedTableName.schema, "' AND \"TABLE_NAME\" = '").concat(parsedTableName.tableName, "'");
|
|
432
|
-
return [4 /*yield*/, this.query(sql)];
|
|
433
|
-
case 3:
|
|
434
|
-
result = _b.sent();
|
|
435
|
-
return [2 /*return*/, result.length ? true : false];
|
|
436
|
-
}
|
|
437
|
-
});
|
|
438
|
-
});
|
|
439
|
-
};
|
|
265
|
+
async hasTable(tableOrName) {
|
|
266
|
+
const parsedTableName = this.driver.parseTableName(tableOrName);
|
|
267
|
+
if (!parsedTableName.schema) {
|
|
268
|
+
parsedTableName.schema = await this.getCurrentSchema();
|
|
269
|
+
}
|
|
270
|
+
const sql = `SELECT * FROM "SYS"."TABLES" WHERE "SCHEMA_NAME" = '${parsedTableName.schema}' AND "TABLE_NAME" = '${parsedTableName.tableName}'`;
|
|
271
|
+
const result = await this.query(sql);
|
|
272
|
+
return result.length ? true : false;
|
|
273
|
+
}
|
|
440
274
|
/**
|
|
441
275
|
* Checks if column with the given name exist in the given table.
|
|
442
276
|
*/
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
return [4 /*yield*/, this.getCurrentSchema()];
|
|
453
|
-
case 1:
|
|
454
|
-
_a.schema = _b.sent();
|
|
455
|
-
_b.label = 2;
|
|
456
|
-
case 2:
|
|
457
|
-
sql = "SELECT * FROM \"SYS\".\"TABLE_COLUMNS\" WHERE \"SCHEMA_NAME\" = ".concat(parsedTableName.schema, " AND \"TABLE_NAME\" = ").concat(parsedTableName.tableName, " AND \"COLUMN_NAME\" = '").concat(columnName, "'");
|
|
458
|
-
return [4 /*yield*/, this.query(sql)];
|
|
459
|
-
case 3:
|
|
460
|
-
result = _b.sent();
|
|
461
|
-
return [2 /*return*/, result.length ? true : false];
|
|
462
|
-
}
|
|
463
|
-
});
|
|
464
|
-
});
|
|
465
|
-
};
|
|
277
|
+
async hasColumn(tableOrName, columnName) {
|
|
278
|
+
const parsedTableName = this.driver.parseTableName(tableOrName);
|
|
279
|
+
if (!parsedTableName.schema) {
|
|
280
|
+
parsedTableName.schema = await this.getCurrentSchema();
|
|
281
|
+
}
|
|
282
|
+
const sql = `SELECT * FROM "SYS"."TABLE_COLUMNS" WHERE "SCHEMA_NAME" = ${parsedTableName.schema} AND "TABLE_NAME" = ${parsedTableName.tableName} AND "COLUMN_NAME" = '${columnName}'`;
|
|
283
|
+
const result = await this.query(sql);
|
|
284
|
+
return result.length ? true : false;
|
|
285
|
+
}
|
|
466
286
|
/**
|
|
467
287
|
* Creates a new database.
|
|
468
288
|
*/
|
|
469
|
-
|
|
470
|
-
return
|
|
471
|
-
|
|
472
|
-
return [2 /*return*/, Promise.resolve()];
|
|
473
|
-
});
|
|
474
|
-
});
|
|
475
|
-
};
|
|
289
|
+
async createDatabase(database, ifNotExist) {
|
|
290
|
+
return Promise.resolve();
|
|
291
|
+
}
|
|
476
292
|
/**
|
|
477
293
|
* Drops database.
|
|
478
294
|
*/
|
|
479
|
-
|
|
480
|
-
return
|
|
481
|
-
|
|
482
|
-
return [2 /*return*/, Promise.resolve()];
|
|
483
|
-
});
|
|
484
|
-
});
|
|
485
|
-
};
|
|
295
|
+
async dropDatabase(database, ifExist) {
|
|
296
|
+
return Promise.resolve();
|
|
297
|
+
}
|
|
486
298
|
/**
|
|
487
299
|
* Creates a new table schema.
|
|
488
300
|
*/
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
_a.label = 2;
|
|
505
|
-
case 2:
|
|
506
|
-
if (!(!ifNotExist || (ifNotExist && !exist))) return [3 /*break*/, 4];
|
|
507
|
-
up = "CREATE SCHEMA \"".concat(schema, "\"");
|
|
508
|
-
down = "DROP SCHEMA \"".concat(schema, "\" CASCADE");
|
|
509
|
-
return [4 /*yield*/, this.executeQueries(new Query_1.Query(up), new Query_1.Query(down))];
|
|
510
|
-
case 3:
|
|
511
|
-
_a.sent();
|
|
512
|
-
_a.label = 4;
|
|
513
|
-
case 4: return [2 /*return*/];
|
|
514
|
-
}
|
|
515
|
-
});
|
|
516
|
-
});
|
|
517
|
-
};
|
|
301
|
+
async createSchema(schemaPath, ifNotExist) {
|
|
302
|
+
const schema = schemaPath.indexOf(".") === -1
|
|
303
|
+
? schemaPath
|
|
304
|
+
: schemaPath.split(".")[1];
|
|
305
|
+
let exist = false;
|
|
306
|
+
if (ifNotExist) {
|
|
307
|
+
const result = await this.query(`SELECT * FROM "SYS"."SCHEMAS" WHERE "SCHEMA_NAME" = '${schema}'`);
|
|
308
|
+
exist = !!result.length;
|
|
309
|
+
}
|
|
310
|
+
if (!ifNotExist || (ifNotExist && !exist)) {
|
|
311
|
+
const up = `CREATE SCHEMA "${schema}"`;
|
|
312
|
+
const down = `DROP SCHEMA "${schema}" CASCADE`;
|
|
313
|
+
await this.executeQueries(new Query_1.Query(up), new Query_1.Query(down));
|
|
314
|
+
}
|
|
315
|
+
}
|
|
518
316
|
/**
|
|
519
317
|
* Drops table schema
|
|
520
318
|
*/
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
_a.label = 2;
|
|
537
|
-
case 2:
|
|
538
|
-
if (!(!ifExist || (ifExist && exist))) return [3 /*break*/, 4];
|
|
539
|
-
up = "DROP SCHEMA \"".concat(schema, "\" ").concat(isCascade ? "CASCADE" : "");
|
|
540
|
-
down = "CREATE SCHEMA \"".concat(schema, "\"");
|
|
541
|
-
return [4 /*yield*/, this.executeQueries(new Query_1.Query(up), new Query_1.Query(down))];
|
|
542
|
-
case 3:
|
|
543
|
-
_a.sent();
|
|
544
|
-
_a.label = 4;
|
|
545
|
-
case 4: return [2 /*return*/];
|
|
546
|
-
}
|
|
547
|
-
});
|
|
548
|
-
});
|
|
549
|
-
};
|
|
319
|
+
async dropSchema(schemaPath, ifExist, isCascade) {
|
|
320
|
+
const schema = schemaPath.indexOf(".") === -1
|
|
321
|
+
? schemaPath
|
|
322
|
+
: schemaPath.split(".")[0];
|
|
323
|
+
let exist = false;
|
|
324
|
+
if (ifExist) {
|
|
325
|
+
const result = await this.query(`SELECT * FROM "SYS"."SCHEMAS" WHERE "SCHEMA_NAME" = '${schema}'`);
|
|
326
|
+
exist = !!result.length;
|
|
327
|
+
}
|
|
328
|
+
if (!ifExist || (ifExist && exist)) {
|
|
329
|
+
const up = `DROP SCHEMA "${schema}" ${isCascade ? "CASCADE" : ""}`;
|
|
330
|
+
const down = `CREATE SCHEMA "${schema}"`;
|
|
331
|
+
await this.executeQueries(new Query_1.Query(up), new Query_1.Query(down));
|
|
332
|
+
}
|
|
333
|
+
}
|
|
550
334
|
/**
|
|
551
335
|
* Creates a new table.
|
|
552
336
|
*/
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
downQueries.push(this.dropTableSql(table));
|
|
575
|
-
// if createForeignKeys is true, we must drop created foreign keys in down query.
|
|
576
|
-
// createTable does not need separate method to create foreign keys, because it create fk's in the same query with table creation.
|
|
577
|
-
if (createForeignKeys)
|
|
578
|
-
table.foreignKeys.forEach(function (foreignKey) {
|
|
579
|
-
return downQueries.push(_this.dropForeignKeySql(table, foreignKey));
|
|
580
|
-
});
|
|
581
|
-
if (createIndices) {
|
|
582
|
-
table.indices.forEach(function (index) {
|
|
583
|
-
// new index may be passed without name. In this case we generate index name manually.
|
|
584
|
-
if (!index.name)
|
|
585
|
-
index.name = _this.connection.namingStrategy.indexName(table, index.columnNames, index.where);
|
|
586
|
-
upQueries.push(_this.createIndexSql(table, index));
|
|
587
|
-
downQueries.push(_this.dropIndexSql(table, index));
|
|
588
|
-
});
|
|
589
|
-
}
|
|
590
|
-
return [4 /*yield*/, this.executeQueries(upQueries, downQueries)];
|
|
591
|
-
case 3:
|
|
592
|
-
_a.sent();
|
|
593
|
-
return [2 /*return*/];
|
|
594
|
-
}
|
|
337
|
+
async createTable(table, ifNotExist = false, createForeignKeys = true, createIndices = true) {
|
|
338
|
+
if (ifNotExist) {
|
|
339
|
+
const isTableExist = await this.hasTable(table);
|
|
340
|
+
if (isTableExist)
|
|
341
|
+
return Promise.resolve();
|
|
342
|
+
}
|
|
343
|
+
const upQueries = [];
|
|
344
|
+
const downQueries = [];
|
|
345
|
+
upQueries.push(this.createTableSql(table, createForeignKeys));
|
|
346
|
+
downQueries.push(this.dropTableSql(table));
|
|
347
|
+
// if createForeignKeys is true, we must drop created foreign keys in down query.
|
|
348
|
+
// createTable does not need separate method to create foreign keys, because it create fk's in the same query with table creation.
|
|
349
|
+
if (createForeignKeys)
|
|
350
|
+
table.foreignKeys.forEach((foreignKey) => downQueries.push(this.dropForeignKeySql(table, foreignKey)));
|
|
351
|
+
if (createIndices) {
|
|
352
|
+
table.indices.forEach((index) => {
|
|
353
|
+
// new index may be passed without name. In this case we generate index name manually.
|
|
354
|
+
if (!index.name)
|
|
355
|
+
index.name = this.connection.namingStrategy.indexName(table, index.columnNames, index.where);
|
|
356
|
+
upQueries.push(this.createIndexSql(table, index));
|
|
357
|
+
downQueries.push(this.dropIndexSql(table, index));
|
|
595
358
|
});
|
|
596
|
-
}
|
|
597
|
-
|
|
359
|
+
}
|
|
360
|
+
await this.executeQueries(upQueries, downQueries);
|
|
361
|
+
}
|
|
598
362
|
/**
|
|
599
363
|
* Drops the table.
|
|
600
364
|
*/
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
_a = tableOrName;
|
|
621
|
-
return [3 /*break*/, 5];
|
|
622
|
-
case 3: return [4 /*yield*/, this.getCachedTable(tableOrName)];
|
|
623
|
-
case 4:
|
|
624
|
-
_a = _b.sent();
|
|
625
|
-
_b.label = 5;
|
|
626
|
-
case 5:
|
|
627
|
-
table = _a;
|
|
628
|
-
upQueries = [];
|
|
629
|
-
downQueries = [];
|
|
630
|
-
// It needs because if table does not exist and dropForeignKeys or dropIndices is true, we don't need
|
|
631
|
-
// to perform drop queries for foreign keys and indices.
|
|
632
|
-
if (dropIndices) {
|
|
633
|
-
table.indices.forEach(function (index) {
|
|
634
|
-
upQueries.push(_this.dropIndexSql(table, index));
|
|
635
|
-
downQueries.push(_this.createIndexSql(table, index));
|
|
636
|
-
});
|
|
637
|
-
}
|
|
638
|
-
// if dropForeignKeys is true, we just drop the table, otherwise we also drop table foreign keys.
|
|
639
|
-
// createTable does not need separate method to create foreign keys, because it create fk's in the same query with table creation.
|
|
640
|
-
if (dropForeignKeys)
|
|
641
|
-
table.foreignKeys.forEach(function (foreignKey) {
|
|
642
|
-
return upQueries.push(_this.dropForeignKeySql(table, foreignKey));
|
|
643
|
-
});
|
|
644
|
-
upQueries.push(this.dropTableSql(table));
|
|
645
|
-
downQueries.push(this.createTableSql(table, createForeignKeys));
|
|
646
|
-
return [4 /*yield*/, this.executeQueries(upQueries, downQueries)];
|
|
647
|
-
case 6:
|
|
648
|
-
_b.sent();
|
|
649
|
-
return [2 /*return*/];
|
|
650
|
-
}
|
|
365
|
+
async dropTable(tableOrName, ifExist, dropForeignKeys = true, dropIndices = true) {
|
|
366
|
+
if (ifExist) {
|
|
367
|
+
const isTableExist = await this.hasTable(tableOrName);
|
|
368
|
+
if (!isTableExist)
|
|
369
|
+
return Promise.resolve();
|
|
370
|
+
}
|
|
371
|
+
// if dropTable called with dropForeignKeys = true, we must create foreign keys in down query.
|
|
372
|
+
const createForeignKeys = dropForeignKeys;
|
|
373
|
+
const table = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
|
|
374
|
+
? tableOrName
|
|
375
|
+
: await this.getCachedTable(tableOrName);
|
|
376
|
+
const upQueries = [];
|
|
377
|
+
const downQueries = [];
|
|
378
|
+
// It needs because if table does not exist and dropForeignKeys or dropIndices is true, we don't need
|
|
379
|
+
// to perform drop queries for foreign keys and indices.
|
|
380
|
+
if (dropIndices) {
|
|
381
|
+
table.indices.forEach((index) => {
|
|
382
|
+
upQueries.push(this.dropIndexSql(table, index));
|
|
383
|
+
downQueries.push(this.createIndexSql(table, index));
|
|
651
384
|
});
|
|
652
|
-
}
|
|
653
|
-
|
|
385
|
+
}
|
|
386
|
+
// if dropForeignKeys is true, we just drop the table, otherwise we also drop table foreign keys.
|
|
387
|
+
// createTable does not need separate method to create foreign keys, because it create fk's in the same query with table creation.
|
|
388
|
+
if (dropForeignKeys)
|
|
389
|
+
table.foreignKeys.forEach((foreignKey) => upQueries.push(this.dropForeignKeySql(table, foreignKey)));
|
|
390
|
+
upQueries.push(this.dropTableSql(table));
|
|
391
|
+
downQueries.push(this.createTableSql(table, createForeignKeys));
|
|
392
|
+
await this.executeQueries(upQueries, downQueries);
|
|
393
|
+
}
|
|
654
394
|
/**
|
|
655
395
|
* Creates a new view.
|
|
656
396
|
*/
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
_b = (_a = upQueries).push;
|
|
669
|
-
return [4 /*yield*/, this.insertViewDefinitionSql(view)];
|
|
670
|
-
case 1:
|
|
671
|
-
_b.apply(_a, [_e.sent()]);
|
|
672
|
-
_e.label = 2;
|
|
673
|
-
case 2:
|
|
674
|
-
downQueries.push(this.dropViewSql(view));
|
|
675
|
-
if (!syncWithMetadata) return [3 /*break*/, 4];
|
|
676
|
-
_d = (_c = downQueries).push;
|
|
677
|
-
return [4 /*yield*/, this.deleteViewDefinitionSql(view)];
|
|
678
|
-
case 3:
|
|
679
|
-
_d.apply(_c, [_e.sent()]);
|
|
680
|
-
_e.label = 4;
|
|
681
|
-
case 4: return [4 /*yield*/, this.executeQueries(upQueries, downQueries)];
|
|
682
|
-
case 5:
|
|
683
|
-
_e.sent();
|
|
684
|
-
return [2 /*return*/];
|
|
685
|
-
}
|
|
686
|
-
});
|
|
687
|
-
});
|
|
688
|
-
};
|
|
397
|
+
async createView(view, syncWithMetadata = false) {
|
|
398
|
+
const upQueries = [];
|
|
399
|
+
const downQueries = [];
|
|
400
|
+
upQueries.push(this.createViewSql(view));
|
|
401
|
+
if (syncWithMetadata)
|
|
402
|
+
upQueries.push(await this.insertViewDefinitionSql(view));
|
|
403
|
+
downQueries.push(this.dropViewSql(view));
|
|
404
|
+
if (syncWithMetadata)
|
|
405
|
+
downQueries.push(await this.deleteViewDefinitionSql(view));
|
|
406
|
+
await this.executeQueries(upQueries, downQueries);
|
|
407
|
+
}
|
|
689
408
|
/**
|
|
690
409
|
* Drops the view.
|
|
691
410
|
*/
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
downQueries = [];
|
|
704
|
-
_b = (_a = upQueries).push;
|
|
705
|
-
return [4 /*yield*/, this.deleteViewDefinitionSql(view)];
|
|
706
|
-
case 2:
|
|
707
|
-
_b.apply(_a, [_e.sent()]);
|
|
708
|
-
upQueries.push(this.dropViewSql(view));
|
|
709
|
-
_d = (_c = downQueries).push;
|
|
710
|
-
return [4 /*yield*/, this.insertViewDefinitionSql(view)];
|
|
711
|
-
case 3:
|
|
712
|
-
_d.apply(_c, [_e.sent()]);
|
|
713
|
-
downQueries.push(this.createViewSql(view));
|
|
714
|
-
return [4 /*yield*/, this.executeQueries(upQueries, downQueries)];
|
|
715
|
-
case 4:
|
|
716
|
-
_e.sent();
|
|
717
|
-
return [2 /*return*/];
|
|
718
|
-
}
|
|
719
|
-
});
|
|
720
|
-
});
|
|
721
|
-
};
|
|
411
|
+
async dropView(target) {
|
|
412
|
+
const viewName = InstanceChecker_1.InstanceChecker.isView(target) ? target.name : target;
|
|
413
|
+
const view = await this.getCachedView(viewName);
|
|
414
|
+
const upQueries = [];
|
|
415
|
+
const downQueries = [];
|
|
416
|
+
upQueries.push(await this.deleteViewDefinitionSql(view));
|
|
417
|
+
upQueries.push(this.dropViewSql(view));
|
|
418
|
+
downQueries.push(await this.insertViewDefinitionSql(view));
|
|
419
|
+
downQueries.push(this.createViewSql(view));
|
|
420
|
+
await this.executeQueries(upQueries, downQueries);
|
|
421
|
+
}
|
|
722
422
|
/**
|
|
723
423
|
* Renames a table.
|
|
724
424
|
*/
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
name: dbForeignKey["CONSTRAINT_NAME"],
|
|
774
|
-
columnNames: foreignKeys.map(function (dbFk) { return dbFk["COLUMN_NAME"]; }),
|
|
775
|
-
referencedDatabase: newTable.database,
|
|
776
|
-
referencedSchema: newTable.schema,
|
|
777
|
-
referencedTableName: newTable.name, // we use renamed table name
|
|
778
|
-
referencedColumnNames: foreignKeys.map(function (dbFk) { return dbFk["REFERENCED_COLUMN_NAME"]; }),
|
|
779
|
-
onDelete: dbForeignKey["DELETE_RULE"] === "RESTRICT"
|
|
780
|
-
? "NO ACTION"
|
|
781
|
-
: dbForeignKey["DELETE_RULE"],
|
|
782
|
-
onUpdate: dbForeignKey["UPDATE_RULE"] === "RESTRICT"
|
|
783
|
-
? "NO ACTION"
|
|
784
|
-
: dbForeignKey["UPDATE_RULE"],
|
|
785
|
-
deferrable: dbForeignKey["CHECK_TIME"].replace("_", " "), // "CHECK_TIME" is "INITIALLY_IMMEDIATE" or "INITIALLY DEFERRED"
|
|
786
|
-
});
|
|
787
|
-
});
|
|
788
|
-
// drop referenced foreign keys
|
|
789
|
-
referencedForeignKeys.forEach(function (foreignKey) {
|
|
790
|
-
var mapping = referencedForeignKeyTableMapping.find(function (it) { return it.fkName === foreignKey.name; });
|
|
791
|
-
upQueries.push(_this.dropForeignKeySql(mapping.tableName, foreignKey));
|
|
792
|
-
downQueries.push(_this.createForeignKeySql(mapping.tableName, foreignKey));
|
|
793
|
-
});
|
|
794
|
-
}
|
|
795
|
-
// rename primary key constraint
|
|
796
|
-
if (newTable.primaryColumns.length > 0) {
|
|
797
|
-
columnNames = newTable.primaryColumns.map(function (column) { return column.name; });
|
|
798
|
-
columnNamesString = columnNames
|
|
799
|
-
.map(function (columnName) { return "\"".concat(columnName, "\""); })
|
|
800
|
-
.join(", ");
|
|
801
|
-
oldPkName = this.connection.namingStrategy.primaryKeyName(oldTable, columnNames);
|
|
802
|
-
newPkName = this.connection.namingStrategy.primaryKeyName(newTable, columnNames);
|
|
803
|
-
// drop old PK
|
|
804
|
-
upQueries.push(new Query_1.Query("ALTER TABLE ".concat(this.escapePath(newTable), " DROP CONSTRAINT \"").concat(oldPkName, "\"")));
|
|
805
|
-
downQueries.push(new Query_1.Query("ALTER TABLE ".concat(this.escapePath(newTable), " ADD CONSTRAINT \"").concat(oldPkName, "\" PRIMARY KEY (").concat(columnNamesString, ")")));
|
|
806
|
-
// create new PK
|
|
807
|
-
upQueries.push(new Query_1.Query("ALTER TABLE ".concat(this.escapePath(newTable), " ADD CONSTRAINT \"").concat(newPkName, "\" PRIMARY KEY (").concat(columnNamesString, ")")));
|
|
808
|
-
downQueries.push(new Query_1.Query("ALTER TABLE ".concat(this.escapePath(newTable), " DROP CONSTRAINT \"").concat(newPkName, "\"")));
|
|
809
|
-
}
|
|
810
|
-
// recreate foreign keys with new constraint names
|
|
811
|
-
newTable.foreignKeys.forEach(function (foreignKey) {
|
|
812
|
-
// replace constraint name
|
|
813
|
-
foreignKey.name = _this.connection.namingStrategy.foreignKeyName(newTable, foreignKey.columnNames, _this.getTablePath(foreignKey), foreignKey.referencedColumnNames);
|
|
814
|
-
// create new FK's
|
|
815
|
-
upQueries.push(_this.createForeignKeySql(newTable, foreignKey));
|
|
816
|
-
downQueries.push(_this.dropForeignKeySql(newTable, foreignKey));
|
|
817
|
-
});
|
|
818
|
-
// restore referenced foreign keys
|
|
819
|
-
referencedForeignKeys.forEach(function (foreignKey) {
|
|
820
|
-
var mapping = referencedForeignKeyTableMapping.find(function (it) { return it.fkName === foreignKey.name; });
|
|
821
|
-
upQueries.push(_this.createForeignKeySql(mapping.tableName, foreignKey));
|
|
822
|
-
downQueries.push(_this.dropForeignKeySql(mapping.tableName, foreignKey));
|
|
823
|
-
});
|
|
824
|
-
// rename index constraints
|
|
825
|
-
newTable.indices.forEach(function (index) {
|
|
826
|
-
// build new constraint name
|
|
827
|
-
var newIndexName = _this.connection.namingStrategy.indexName(newTable, index.columnNames, index.where);
|
|
828
|
-
// drop old index
|
|
829
|
-
upQueries.push(_this.dropIndexSql(newTable, index));
|
|
830
|
-
downQueries.push(_this.createIndexSql(newTable, index));
|
|
831
|
-
// replace constraint name
|
|
832
|
-
index.name = newIndexName;
|
|
833
|
-
// create new index
|
|
834
|
-
upQueries.push(_this.createIndexSql(newTable, index));
|
|
835
|
-
downQueries.push(_this.dropIndexSql(newTable, index));
|
|
836
|
-
});
|
|
837
|
-
return [4 /*yield*/, this.executeQueries(upQueries, downQueries)
|
|
838
|
-
// rename old table and replace it in cached tabled;
|
|
839
|
-
];
|
|
840
|
-
case 5:
|
|
841
|
-
_c.sent();
|
|
842
|
-
// rename old table and replace it in cached tabled;
|
|
843
|
-
oldTable.name = newTable.name;
|
|
844
|
-
this.replaceCachedTable(oldTable, newTable);
|
|
845
|
-
return [2 /*return*/];
|
|
846
|
-
}
|
|
425
|
+
async renameTable(oldTableOrName, newTableName) {
|
|
426
|
+
const upQueries = [];
|
|
427
|
+
const downQueries = [];
|
|
428
|
+
const oldTable = InstanceChecker_1.InstanceChecker.isTable(oldTableOrName)
|
|
429
|
+
? oldTableOrName
|
|
430
|
+
: await this.getCachedTable(oldTableOrName);
|
|
431
|
+
const newTable = oldTable.clone();
|
|
432
|
+
const { schema: schemaName, tableName: oldTableName } = this.driver.parseTableName(oldTable);
|
|
433
|
+
newTable.name = schemaName
|
|
434
|
+
? `${schemaName}.${newTableName}`
|
|
435
|
+
: newTableName;
|
|
436
|
+
// rename table
|
|
437
|
+
upQueries.push(new Query_1.Query(`RENAME TABLE ${this.escapePath(oldTable)} TO ${this.escapePath(newTableName)}`));
|
|
438
|
+
downQueries.push(new Query_1.Query(`RENAME TABLE ${this.escapePath(newTable)} TO ${this.escapePath(oldTableName)}`));
|
|
439
|
+
// drop old FK's. Foreign keys must be dropped before the primary keys are dropped
|
|
440
|
+
newTable.foreignKeys.forEach((foreignKey) => {
|
|
441
|
+
upQueries.push(this.dropForeignKeySql(newTable, foreignKey));
|
|
442
|
+
downQueries.push(this.createForeignKeySql(newTable, foreignKey));
|
|
443
|
+
});
|
|
444
|
+
// SAP HANA does not allow to drop PK's which is referenced by foreign keys.
|
|
445
|
+
// To avoid this, we must drop all referential foreign keys and recreate them later
|
|
446
|
+
const referencedForeignKeySql = `SELECT * FROM "SYS"."REFERENTIAL_CONSTRAINTS" WHERE "REFERENCED_SCHEMA_NAME" = '${schemaName}' AND "REFERENCED_TABLE_NAME" = '${oldTableName}'`;
|
|
447
|
+
const dbForeignKeys = await this.query(referencedForeignKeySql);
|
|
448
|
+
let referencedForeignKeys = [];
|
|
449
|
+
const referencedForeignKeyTableMapping = [];
|
|
450
|
+
if (dbForeignKeys.length > 0) {
|
|
451
|
+
referencedForeignKeys = dbForeignKeys.map((dbForeignKey) => {
|
|
452
|
+
const foreignKeys = dbForeignKeys.filter((dbFk) => dbFk["CONSTRAINT_NAME"] ===
|
|
453
|
+
dbForeignKey["CONSTRAINT_NAME"]);
|
|
454
|
+
referencedForeignKeyTableMapping.push({
|
|
455
|
+
tableName: `${dbForeignKey["SCHEMA_NAME"]}.${dbForeignKey["TABLE_NAME"]}`,
|
|
456
|
+
fkName: dbForeignKey["CONSTRAINT_NAME"],
|
|
457
|
+
});
|
|
458
|
+
return new TableForeignKey_1.TableForeignKey({
|
|
459
|
+
name: dbForeignKey["CONSTRAINT_NAME"],
|
|
460
|
+
columnNames: foreignKeys.map((dbFk) => dbFk["COLUMN_NAME"]),
|
|
461
|
+
referencedDatabase: newTable.database,
|
|
462
|
+
referencedSchema: newTable.schema,
|
|
463
|
+
referencedTableName: newTable.name, // we use renamed table name
|
|
464
|
+
referencedColumnNames: foreignKeys.map((dbFk) => dbFk["REFERENCED_COLUMN_NAME"]),
|
|
465
|
+
onDelete: dbForeignKey["DELETE_RULE"] === "RESTRICT"
|
|
466
|
+
? "NO ACTION"
|
|
467
|
+
: dbForeignKey["DELETE_RULE"],
|
|
468
|
+
onUpdate: dbForeignKey["UPDATE_RULE"] === "RESTRICT"
|
|
469
|
+
? "NO ACTION"
|
|
470
|
+
: dbForeignKey["UPDATE_RULE"],
|
|
471
|
+
deferrable: dbForeignKey["CHECK_TIME"].replace("_", " "), // "CHECK_TIME" is "INITIALLY_IMMEDIATE" or "INITIALLY DEFERRED"
|
|
472
|
+
});
|
|
847
473
|
});
|
|
474
|
+
// drop referenced foreign keys
|
|
475
|
+
referencedForeignKeys.forEach((foreignKey) => {
|
|
476
|
+
const mapping = referencedForeignKeyTableMapping.find((it) => it.fkName === foreignKey.name);
|
|
477
|
+
upQueries.push(this.dropForeignKeySql(mapping.tableName, foreignKey));
|
|
478
|
+
downQueries.push(this.createForeignKeySql(mapping.tableName, foreignKey));
|
|
479
|
+
});
|
|
480
|
+
}
|
|
481
|
+
// rename primary key constraint
|
|
482
|
+
if (newTable.primaryColumns.length > 0) {
|
|
483
|
+
const columnNames = newTable.primaryColumns.map((column) => column.name);
|
|
484
|
+
const columnNamesString = columnNames
|
|
485
|
+
.map((columnName) => `"${columnName}"`)
|
|
486
|
+
.join(", ");
|
|
487
|
+
const oldPkName = this.connection.namingStrategy.primaryKeyName(oldTable, columnNames);
|
|
488
|
+
const newPkName = this.connection.namingStrategy.primaryKeyName(newTable, columnNames);
|
|
489
|
+
// drop old PK
|
|
490
|
+
upQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(newTable)} DROP CONSTRAINT "${oldPkName}"`));
|
|
491
|
+
downQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(newTable)} ADD CONSTRAINT "${oldPkName}" PRIMARY KEY (${columnNamesString})`));
|
|
492
|
+
// create new PK
|
|
493
|
+
upQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(newTable)} ADD CONSTRAINT "${newPkName}" PRIMARY KEY (${columnNamesString})`));
|
|
494
|
+
downQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(newTable)} DROP CONSTRAINT "${newPkName}"`));
|
|
495
|
+
}
|
|
496
|
+
// recreate foreign keys with new constraint names
|
|
497
|
+
newTable.foreignKeys.forEach((foreignKey) => {
|
|
498
|
+
// replace constraint name
|
|
499
|
+
foreignKey.name = this.connection.namingStrategy.foreignKeyName(newTable, foreignKey.columnNames, this.getTablePath(foreignKey), foreignKey.referencedColumnNames);
|
|
500
|
+
// create new FK's
|
|
501
|
+
upQueries.push(this.createForeignKeySql(newTable, foreignKey));
|
|
502
|
+
downQueries.push(this.dropForeignKeySql(newTable, foreignKey));
|
|
503
|
+
});
|
|
504
|
+
// restore referenced foreign keys
|
|
505
|
+
referencedForeignKeys.forEach((foreignKey) => {
|
|
506
|
+
const mapping = referencedForeignKeyTableMapping.find((it) => it.fkName === foreignKey.name);
|
|
507
|
+
upQueries.push(this.createForeignKeySql(mapping.tableName, foreignKey));
|
|
508
|
+
downQueries.push(this.dropForeignKeySql(mapping.tableName, foreignKey));
|
|
509
|
+
});
|
|
510
|
+
// rename index constraints
|
|
511
|
+
newTable.indices.forEach((index) => {
|
|
512
|
+
// build new constraint name
|
|
513
|
+
const newIndexName = this.connection.namingStrategy.indexName(newTable, index.columnNames, index.where);
|
|
514
|
+
// drop old index
|
|
515
|
+
upQueries.push(this.dropIndexSql(newTable, index));
|
|
516
|
+
downQueries.push(this.createIndexSql(newTable, index));
|
|
517
|
+
// replace constraint name
|
|
518
|
+
index.name = newIndexName;
|
|
519
|
+
// create new index
|
|
520
|
+
upQueries.push(this.createIndexSql(newTable, index));
|
|
521
|
+
downQueries.push(this.dropIndexSql(newTable, index));
|
|
848
522
|
});
|
|
849
|
-
|
|
523
|
+
await this.executeQueries(upQueries, downQueries);
|
|
524
|
+
// rename old table and replace it in cached tabled;
|
|
525
|
+
oldTable.name = newTable.name;
|
|
526
|
+
this.replaceCachedTable(oldTable, newTable);
|
|
527
|
+
}
|
|
850
528
|
/**
|
|
851
529
|
* Creates a new column from the column in the table.
|
|
852
530
|
*/
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
if (!(primaryColumns.length > 0)) return [3 /*break*/, 7];
|
|
885
|
-
referencedForeignKeySql = "SELECT * FROM \"SYS\".\"REFERENTIAL_CONSTRAINTS\" WHERE \"REFERENCED_SCHEMA_NAME\" = '".concat(parsedTableName.schema, "' AND \"REFERENCED_TABLE_NAME\" = '").concat(parsedTableName.tableName, "'");
|
|
886
|
-
return [4 /*yield*/, this.query(referencedForeignKeySql)];
|
|
887
|
-
case 6:
|
|
888
|
-
dbForeignKeys_1 = _c.sent();
|
|
889
|
-
referencedForeignKeys = [];
|
|
890
|
-
referencedForeignKeyTableMapping_1 = [];
|
|
891
|
-
if (dbForeignKeys_1.length > 0) {
|
|
892
|
-
referencedForeignKeys = dbForeignKeys_1.map(function (dbForeignKey) {
|
|
893
|
-
var foreignKeys = dbForeignKeys_1.filter(function (dbFk) {
|
|
894
|
-
return dbFk["CONSTRAINT_NAME"] ===
|
|
895
|
-
dbForeignKey["CONSTRAINT_NAME"];
|
|
896
|
-
});
|
|
897
|
-
referencedForeignKeyTableMapping_1.push({
|
|
898
|
-
tableName: "".concat(dbForeignKey["SCHEMA_NAME"], ".").concat(dbForeignKey["TABLE_NAME"]),
|
|
899
|
-
fkName: dbForeignKey["CONSTRAINT_NAME"],
|
|
900
|
-
});
|
|
901
|
-
return new TableForeignKey_1.TableForeignKey({
|
|
902
|
-
name: dbForeignKey["CONSTRAINT_NAME"],
|
|
903
|
-
columnNames: foreignKeys.map(function (dbFk) { return dbFk["COLUMN_NAME"]; }),
|
|
904
|
-
referencedDatabase: table.database,
|
|
905
|
-
referencedSchema: table.schema,
|
|
906
|
-
referencedTableName: table.name,
|
|
907
|
-
referencedColumnNames: foreignKeys.map(function (dbFk) { return dbFk["REFERENCED_COLUMN_NAME"]; }),
|
|
908
|
-
onDelete: dbForeignKey["DELETE_RULE"] === "RESTRICT"
|
|
909
|
-
? "NO ACTION"
|
|
910
|
-
: dbForeignKey["DELETE_RULE"],
|
|
911
|
-
onUpdate: dbForeignKey["UPDATE_RULE"] === "RESTRICT"
|
|
912
|
-
? "NO ACTION"
|
|
913
|
-
: dbForeignKey["UPDATE_RULE"],
|
|
914
|
-
deferrable: dbForeignKey["CHECK_TIME"].replace("_", " "),
|
|
915
|
-
});
|
|
916
|
-
});
|
|
917
|
-
// drop referenced foreign keys
|
|
918
|
-
referencedForeignKeys.forEach(function (foreignKey) {
|
|
919
|
-
var mapping = referencedForeignKeyTableMapping_1.find(function (it) { return it.fkName === foreignKey.name; });
|
|
920
|
-
upQueries.push(_this.dropForeignKeySql(mapping.tableName, foreignKey));
|
|
921
|
-
downQueries.push(_this.createForeignKeySql(mapping.tableName, foreignKey));
|
|
922
|
-
});
|
|
923
|
-
}
|
|
924
|
-
pkName_1 = this.connection.namingStrategy.primaryKeyName(clonedTable, primaryColumns.map(function (column) { return column.name; }));
|
|
925
|
-
columnNames_1 = primaryColumns
|
|
926
|
-
.map(function (column) { return "\"".concat(column.name, "\""); })
|
|
927
|
-
.join(", ");
|
|
928
|
-
upQueries.push(new Query_1.Query("ALTER TABLE ".concat(this.escapePath(table), " DROP CONSTRAINT \"").concat(pkName_1, "\"")));
|
|
929
|
-
downQueries.push(new Query_1.Query("ALTER TABLE ".concat(this.escapePath(table), " ADD CONSTRAINT \"").concat(pkName_1, "\" PRIMARY KEY (").concat(columnNames_1, ")")));
|
|
930
|
-
// restore referenced foreign keys
|
|
931
|
-
referencedForeignKeys.forEach(function (foreignKey) {
|
|
932
|
-
var mapping = referencedForeignKeyTableMapping_1.find(function (it) { return it.fkName === foreignKey.name; });
|
|
933
|
-
upQueries.push(_this.createForeignKeySql(mapping.tableName, foreignKey));
|
|
934
|
-
downQueries.push(_this.dropForeignKeySql(mapping.tableName, foreignKey));
|
|
531
|
+
async addColumn(tableOrName, column) {
|
|
532
|
+
const table = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
|
|
533
|
+
? tableOrName
|
|
534
|
+
: await this.getCachedTable(tableOrName);
|
|
535
|
+
const parsedTableName = this.driver.parseTableName(table);
|
|
536
|
+
if (!parsedTableName.schema) {
|
|
537
|
+
parsedTableName.schema = await this.getCurrentSchema();
|
|
538
|
+
}
|
|
539
|
+
const clonedTable = table.clone();
|
|
540
|
+
const upQueries = [];
|
|
541
|
+
const downQueries = [];
|
|
542
|
+
upQueries.push(new Query_1.Query(this.addColumnSql(table, column)));
|
|
543
|
+
downQueries.push(new Query_1.Query(this.dropColumnSql(table, column)));
|
|
544
|
+
// create or update primary key constraint
|
|
545
|
+
if (column.isPrimary) {
|
|
546
|
+
const primaryColumns = clonedTable.primaryColumns;
|
|
547
|
+
// if table already have primary key, me must drop it and recreate again
|
|
548
|
+
if (primaryColumns.length > 0) {
|
|
549
|
+
// SAP HANA does not allow to drop PK's which is referenced by foreign keys.
|
|
550
|
+
// To avoid this, we must drop all referential foreign keys and recreate them later
|
|
551
|
+
const referencedForeignKeySql = `SELECT * FROM "SYS"."REFERENTIAL_CONSTRAINTS" WHERE "REFERENCED_SCHEMA_NAME" = '${parsedTableName.schema}' AND "REFERENCED_TABLE_NAME" = '${parsedTableName.tableName}'`;
|
|
552
|
+
const dbForeignKeys = await this.query(referencedForeignKeySql);
|
|
553
|
+
let referencedForeignKeys = [];
|
|
554
|
+
const referencedForeignKeyTableMapping = [];
|
|
555
|
+
if (dbForeignKeys.length > 0) {
|
|
556
|
+
referencedForeignKeys = dbForeignKeys.map((dbForeignKey) => {
|
|
557
|
+
const foreignKeys = dbForeignKeys.filter((dbFk) => dbFk["CONSTRAINT_NAME"] ===
|
|
558
|
+
dbForeignKey["CONSTRAINT_NAME"]);
|
|
559
|
+
referencedForeignKeyTableMapping.push({
|
|
560
|
+
tableName: `${dbForeignKey["SCHEMA_NAME"]}.${dbForeignKey["TABLE_NAME"]}`,
|
|
561
|
+
fkName: dbForeignKey["CONSTRAINT_NAME"],
|
|
935
562
|
});
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
.
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
563
|
+
return new TableForeignKey_1.TableForeignKey({
|
|
564
|
+
name: dbForeignKey["CONSTRAINT_NAME"],
|
|
565
|
+
columnNames: foreignKeys.map((dbFk) => dbFk["COLUMN_NAME"]),
|
|
566
|
+
referencedDatabase: table.database,
|
|
567
|
+
referencedSchema: table.schema,
|
|
568
|
+
referencedTableName: table.name,
|
|
569
|
+
referencedColumnNames: foreignKeys.map((dbFk) => dbFk["REFERENCED_COLUMN_NAME"]),
|
|
570
|
+
onDelete: dbForeignKey["DELETE_RULE"] === "RESTRICT"
|
|
571
|
+
? "NO ACTION"
|
|
572
|
+
: dbForeignKey["DELETE_RULE"],
|
|
573
|
+
onUpdate: dbForeignKey["UPDATE_RULE"] === "RESTRICT"
|
|
574
|
+
? "NO ACTION"
|
|
575
|
+
: dbForeignKey["UPDATE_RULE"],
|
|
576
|
+
deferrable: dbForeignKey["CHECK_TIME"].replace("_", " "),
|
|
950
577
|
});
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
column.name,
|
|
959
|
-
]),
|
|
960
|
-
columnNames: [column.name],
|
|
961
|
-
isUnique: true,
|
|
962
|
-
});
|
|
963
|
-
clonedTable.indices.push(uniqueIndex);
|
|
964
|
-
clonedTable.uniques.push(new TableUnique_1.TableUnique({
|
|
965
|
-
name: uniqueIndex.name,
|
|
966
|
-
columnNames: uniqueIndex.columnNames,
|
|
967
|
-
}));
|
|
968
|
-
upQueries.push(this.createIndexSql(table, uniqueIndex));
|
|
969
|
-
downQueries.push(this.dropIndexSql(table, uniqueIndex));
|
|
970
|
-
}
|
|
971
|
-
return [4 /*yield*/, this.executeQueries(upQueries, downQueries)];
|
|
972
|
-
case 9:
|
|
973
|
-
_c.sent();
|
|
974
|
-
clonedTable.addColumn(column);
|
|
975
|
-
this.replaceCachedTable(table, clonedTable);
|
|
976
|
-
return [2 /*return*/];
|
|
578
|
+
});
|
|
579
|
+
// drop referenced foreign keys
|
|
580
|
+
referencedForeignKeys.forEach((foreignKey) => {
|
|
581
|
+
const mapping = referencedForeignKeyTableMapping.find((it) => it.fkName === foreignKey.name);
|
|
582
|
+
upQueries.push(this.dropForeignKeySql(mapping.tableName, foreignKey));
|
|
583
|
+
downQueries.push(this.createForeignKeySql(mapping.tableName, foreignKey));
|
|
584
|
+
});
|
|
977
585
|
}
|
|
586
|
+
const pkName = this.connection.namingStrategy.primaryKeyName(clonedTable, primaryColumns.map((column) => column.name));
|
|
587
|
+
const columnNames = primaryColumns
|
|
588
|
+
.map((column) => `"${column.name}"`)
|
|
589
|
+
.join(", ");
|
|
590
|
+
upQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} DROP CONSTRAINT "${pkName}"`));
|
|
591
|
+
downQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} ADD CONSTRAINT "${pkName}" PRIMARY KEY (${columnNames})`));
|
|
592
|
+
// restore referenced foreign keys
|
|
593
|
+
referencedForeignKeys.forEach((foreignKey) => {
|
|
594
|
+
const mapping = referencedForeignKeyTableMapping.find((it) => it.fkName === foreignKey.name);
|
|
595
|
+
upQueries.push(this.createForeignKeySql(mapping.tableName, foreignKey));
|
|
596
|
+
downQueries.push(this.dropForeignKeySql(mapping.tableName, foreignKey));
|
|
597
|
+
});
|
|
598
|
+
}
|
|
599
|
+
primaryColumns.push(column);
|
|
600
|
+
const pkName = this.connection.namingStrategy.primaryKeyName(clonedTable, primaryColumns.map((column) => column.name));
|
|
601
|
+
const columnNames = primaryColumns
|
|
602
|
+
.map((column) => `"${column.name}"`)
|
|
603
|
+
.join(", ");
|
|
604
|
+
upQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} ADD CONSTRAINT "${pkName}" PRIMARY KEY (${columnNames})`));
|
|
605
|
+
downQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} DROP CONSTRAINT "${pkName}"`));
|
|
606
|
+
}
|
|
607
|
+
// create column index
|
|
608
|
+
const columnIndex = clonedTable.indices.find((index) => index.columnNames.length === 1 &&
|
|
609
|
+
index.columnNames[0] === column.name);
|
|
610
|
+
if (columnIndex) {
|
|
611
|
+
upQueries.push(this.createIndexSql(table, columnIndex));
|
|
612
|
+
downQueries.push(this.dropIndexSql(table, columnIndex));
|
|
613
|
+
}
|
|
614
|
+
else if (column.isUnique) {
|
|
615
|
+
const uniqueIndex = new TableIndex_1.TableIndex({
|
|
616
|
+
name: this.connection.namingStrategy.indexName(table, [
|
|
617
|
+
column.name,
|
|
618
|
+
]),
|
|
619
|
+
columnNames: [column.name],
|
|
620
|
+
isUnique: true,
|
|
978
621
|
});
|
|
979
|
-
|
|
980
|
-
|
|
622
|
+
clonedTable.indices.push(uniqueIndex);
|
|
623
|
+
clonedTable.uniques.push(new TableUnique_1.TableUnique({
|
|
624
|
+
name: uniqueIndex.name,
|
|
625
|
+
columnNames: uniqueIndex.columnNames,
|
|
626
|
+
}));
|
|
627
|
+
upQueries.push(this.createIndexSql(table, uniqueIndex));
|
|
628
|
+
downQueries.push(this.dropIndexSql(table, uniqueIndex));
|
|
629
|
+
}
|
|
630
|
+
await this.executeQueries(upQueries, downQueries);
|
|
631
|
+
clonedTable.addColumn(column);
|
|
632
|
+
this.replaceCachedTable(table, clonedTable);
|
|
633
|
+
}
|
|
981
634
|
/**
|
|
982
635
|
* Creates a new columns from the column in the table.
|
|
983
636
|
*/
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
switch (_b.label) {
|
|
990
|
-
case 0:
|
|
991
|
-
_b.trys.push([0, 5, 6, 7]);
|
|
992
|
-
columns_1 = tslib_1.__values(columns), columns_1_1 = columns_1.next();
|
|
993
|
-
_b.label = 1;
|
|
994
|
-
case 1:
|
|
995
|
-
if (!!columns_1_1.done) return [3 /*break*/, 4];
|
|
996
|
-
column = columns_1_1.value;
|
|
997
|
-
return [4 /*yield*/, this.addColumn(tableOrName, column)];
|
|
998
|
-
case 2:
|
|
999
|
-
_b.sent();
|
|
1000
|
-
_b.label = 3;
|
|
1001
|
-
case 3:
|
|
1002
|
-
columns_1_1 = columns_1.next();
|
|
1003
|
-
return [3 /*break*/, 1];
|
|
1004
|
-
case 4: return [3 /*break*/, 7];
|
|
1005
|
-
case 5:
|
|
1006
|
-
e_2_1 = _b.sent();
|
|
1007
|
-
e_2 = { error: e_2_1 };
|
|
1008
|
-
return [3 /*break*/, 7];
|
|
1009
|
-
case 6:
|
|
1010
|
-
try {
|
|
1011
|
-
if (columns_1_1 && !columns_1_1.done && (_a = columns_1.return)) _a.call(columns_1);
|
|
1012
|
-
}
|
|
1013
|
-
finally { if (e_2) throw e_2.error; }
|
|
1014
|
-
return [7 /*endfinally*/];
|
|
1015
|
-
case 7: return [2 /*return*/];
|
|
1016
|
-
}
|
|
1017
|
-
});
|
|
1018
|
-
});
|
|
1019
|
-
};
|
|
637
|
+
async addColumns(tableOrName, columns) {
|
|
638
|
+
for (const column of columns) {
|
|
639
|
+
await this.addColumn(tableOrName, column);
|
|
640
|
+
}
|
|
641
|
+
}
|
|
1020
642
|
/**
|
|
1021
643
|
* Renames column in the given table.
|
|
1022
644
|
*/
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
throw new error_1.TypeORMError("Column \"".concat(oldTableColumnOrName, "\" was not found in the \"").concat(table.name, "\" table."));
|
|
1043
|
-
newColumn = undefined;
|
|
1044
|
-
if (InstanceChecker_1.InstanceChecker.isTableColumn(newTableColumnOrName)) {
|
|
1045
|
-
newColumn = newTableColumnOrName;
|
|
1046
|
-
}
|
|
1047
|
-
else {
|
|
1048
|
-
newColumn = oldColumn.clone();
|
|
1049
|
-
newColumn.name = newTableColumnOrName;
|
|
1050
|
-
}
|
|
1051
|
-
return [4 /*yield*/, this.changeColumn(table, oldColumn, newColumn)];
|
|
1052
|
-
case 4:
|
|
1053
|
-
_b.sent();
|
|
1054
|
-
return [2 /*return*/];
|
|
1055
|
-
}
|
|
1056
|
-
});
|
|
1057
|
-
});
|
|
1058
|
-
};
|
|
645
|
+
async renameColumn(tableOrName, oldTableColumnOrName, newTableColumnOrName) {
|
|
646
|
+
const table = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
|
|
647
|
+
? tableOrName
|
|
648
|
+
: await this.getCachedTable(tableOrName);
|
|
649
|
+
const oldColumn = InstanceChecker_1.InstanceChecker.isTableColumn(oldTableColumnOrName)
|
|
650
|
+
? oldTableColumnOrName
|
|
651
|
+
: table.columns.find((c) => c.name === oldTableColumnOrName);
|
|
652
|
+
if (!oldColumn)
|
|
653
|
+
throw new error_1.TypeORMError(`Column "${oldTableColumnOrName}" was not found in the "${table.name}" table.`);
|
|
654
|
+
let newColumn = undefined;
|
|
655
|
+
if (InstanceChecker_1.InstanceChecker.isTableColumn(newTableColumnOrName)) {
|
|
656
|
+
newColumn = newTableColumnOrName;
|
|
657
|
+
}
|
|
658
|
+
else {
|
|
659
|
+
newColumn = oldColumn.clone();
|
|
660
|
+
newColumn.name = newTableColumnOrName;
|
|
661
|
+
}
|
|
662
|
+
await this.changeColumn(table, oldColumn, newColumn);
|
|
663
|
+
}
|
|
1059
664
|
/**
|
|
1060
665
|
* Changes a column in the table.
|
|
1061
666
|
*/
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
downQueries.push(new Query_1.Query("RENAME COLUMN ".concat(this.escapePath(table), ".\"").concat(newColumn.name, "\" TO \"").concat(oldColumn.name, "\"")));
|
|
1110
|
-
if (oldColumn.isPrimary === true) {
|
|
1111
|
-
primaryColumns = clonedTable.primaryColumns;
|
|
1112
|
-
columnNames = primaryColumns.map(function (column) { return column.name; });
|
|
1113
|
-
oldPkName = this.connection.namingStrategy.primaryKeyName(clonedTable, columnNames);
|
|
1114
|
-
// replace old column name with new column name
|
|
1115
|
-
columnNames.splice(columnNames.indexOf(oldColumn.name), 1);
|
|
1116
|
-
columnNames.push(newColumn.name);
|
|
1117
|
-
columnNamesString = columnNames
|
|
1118
|
-
.map(function (columnName) { return "\"".concat(columnName, "\""); })
|
|
1119
|
-
.join(", ");
|
|
1120
|
-
// drop old PK
|
|
1121
|
-
upQueries.push(new Query_1.Query("ALTER TABLE ".concat(this.escapePath(clonedTable), " DROP CONSTRAINT \"").concat(oldPkName, "\"")));
|
|
1122
|
-
downQueries.push(new Query_1.Query("ALTER TABLE ".concat(this.escapePath(clonedTable), " ADD CONSTRAINT \"").concat(oldPkName, "\" PRIMARY KEY (").concat(columnNamesString, ")")));
|
|
1123
|
-
newPkName = this.connection.namingStrategy.primaryKeyName(clonedTable, columnNames);
|
|
1124
|
-
// create new PK
|
|
1125
|
-
upQueries.push(new Query_1.Query("ALTER TABLE ".concat(this.escapePath(clonedTable), " ADD CONSTRAINT \"").concat(newPkName, "\" PRIMARY KEY (").concat(columnNamesString, ")")));
|
|
1126
|
-
downQueries.push(new Query_1.Query("ALTER TABLE ".concat(this.escapePath(clonedTable), " DROP CONSTRAINT \"").concat(newPkName, "\"")));
|
|
1127
|
-
}
|
|
1128
|
-
// rename index constraints
|
|
1129
|
-
clonedTable.findColumnIndices(oldColumn).forEach(function (index) {
|
|
1130
|
-
// build new constraint name
|
|
1131
|
-
index.columnNames.splice(index.columnNames.indexOf(oldColumn.name), 1);
|
|
1132
|
-
index.columnNames.push(newColumn.name);
|
|
1133
|
-
var newIndexName = _this.connection.namingStrategy.indexName(clonedTable, index.columnNames, index.where);
|
|
1134
|
-
// drop old index
|
|
1135
|
-
upQueries.push(_this.dropIndexSql(clonedTable, index));
|
|
1136
|
-
downQueries.push(_this.createIndexSql(clonedTable, index));
|
|
1137
|
-
// replace constraint name
|
|
1138
|
-
index.name = newIndexName;
|
|
1139
|
-
// create new index
|
|
1140
|
-
upQueries.push(_this.createIndexSql(clonedTable, index));
|
|
1141
|
-
downQueries.push(_this.dropIndexSql(clonedTable, index));
|
|
1142
|
-
});
|
|
1143
|
-
// rename foreign key constraints
|
|
1144
|
-
clonedTable
|
|
1145
|
-
.findColumnForeignKeys(oldColumn)
|
|
1146
|
-
.forEach(function (foreignKey) {
|
|
1147
|
-
// build new constraint name
|
|
1148
|
-
foreignKey.columnNames.splice(foreignKey.columnNames.indexOf(oldColumn.name), 1);
|
|
1149
|
-
foreignKey.columnNames.push(newColumn.name);
|
|
1150
|
-
var newForeignKeyName = _this.connection.namingStrategy.foreignKeyName(clonedTable, foreignKey.columnNames, _this.getTablePath(foreignKey), foreignKey.referencedColumnNames);
|
|
1151
|
-
upQueries.push(_this.dropForeignKeySql(clonedTable, foreignKey));
|
|
1152
|
-
downQueries.push(_this.createForeignKeySql(clonedTable, foreignKey));
|
|
1153
|
-
// replace constraint name
|
|
1154
|
-
foreignKey.name = newForeignKeyName;
|
|
1155
|
-
// create new FK's
|
|
1156
|
-
upQueries.push(_this.createForeignKeySql(clonedTable, foreignKey));
|
|
1157
|
-
downQueries.push(_this.dropForeignKeySql(clonedTable, foreignKey));
|
|
1158
|
-
});
|
|
1159
|
-
// rename check constraints
|
|
1160
|
-
clonedTable.findColumnChecks(oldColumn).forEach(function (check) {
|
|
1161
|
-
// build new constraint name
|
|
1162
|
-
check.columnNames.splice(check.columnNames.indexOf(oldColumn.name), 1);
|
|
1163
|
-
check.columnNames.push(newColumn.name);
|
|
1164
|
-
var newCheckName = _this.connection.namingStrategy.checkConstraintName(clonedTable, check.expression);
|
|
1165
|
-
upQueries.push(_this.dropCheckConstraintSql(clonedTable, check));
|
|
1166
|
-
downQueries.push(_this.createCheckConstraintSql(clonedTable, check));
|
|
1167
|
-
// replace constraint name
|
|
1168
|
-
check.name = newCheckName;
|
|
1169
|
-
upQueries.push(_this.createCheckConstraintSql(clonedTable, check));
|
|
1170
|
-
downQueries.push(_this.dropCheckConstraintSql(clonedTable, check));
|
|
1171
|
-
});
|
|
1172
|
-
oldTableColumn = clonedTable.columns.find(function (column) { return column.name === oldColumn.name; });
|
|
1173
|
-
clonedTable.columns[clonedTable.columns.indexOf(oldTableColumn)].name = newColumn.name;
|
|
1174
|
-
oldColumn.name = newColumn.name;
|
|
1175
|
-
}
|
|
1176
|
-
if (this.isColumnChanged(oldColumn, newColumn)) {
|
|
1177
|
-
upQueries.push(new Query_1.Query("ALTER TABLE ".concat(this.escapePath(table), " ALTER (").concat(this.buildCreateColumnSql(newColumn), ")")));
|
|
1178
|
-
downQueries.push(new Query_1.Query("ALTER TABLE ".concat(this.escapePath(table), " ALTER (").concat(this.buildCreateColumnSql(oldColumn), ")")));
|
|
1179
|
-
}
|
|
1180
|
-
if (newColumn.isPrimary !== oldColumn.isPrimary) {
|
|
1181
|
-
primaryColumns = clonedTable.primaryColumns;
|
|
1182
|
-
// if primary column state changed, we must always drop existed constraint.
|
|
1183
|
-
if (primaryColumns.length > 0) {
|
|
1184
|
-
pkName = this.connection.namingStrategy.primaryKeyName(clonedTable, primaryColumns.map(function (column) { return column.name; }));
|
|
1185
|
-
columnNames = primaryColumns
|
|
1186
|
-
.map(function (column) { return "\"".concat(column.name, "\""); })
|
|
1187
|
-
.join(", ");
|
|
1188
|
-
upQueries.push(new Query_1.Query("ALTER TABLE ".concat(this.escapePath(table), " DROP CONSTRAINT \"").concat(pkName, "\"")));
|
|
1189
|
-
downQueries.push(new Query_1.Query("ALTER TABLE ".concat(this.escapePath(table), " ADD CONSTRAINT \"").concat(pkName, "\" PRIMARY KEY (").concat(columnNames, ")")));
|
|
1190
|
-
}
|
|
1191
|
-
if (newColumn.isPrimary === true) {
|
|
1192
|
-
primaryColumns.push(newColumn);
|
|
1193
|
-
column = clonedTable.columns.find(function (column) { return column.name === newColumn.name; });
|
|
1194
|
-
column.isPrimary = true;
|
|
1195
|
-
pkName = this.connection.namingStrategy.primaryKeyName(clonedTable, primaryColumns.map(function (column) { return column.name; }));
|
|
1196
|
-
columnNames = primaryColumns
|
|
1197
|
-
.map(function (column) { return "\"".concat(column.name, "\""); })
|
|
1198
|
-
.join(", ");
|
|
1199
|
-
upQueries.push(new Query_1.Query("ALTER TABLE ".concat(this.escapePath(table), " ADD CONSTRAINT \"").concat(pkName, "\" PRIMARY KEY (").concat(columnNames, ")")));
|
|
1200
|
-
downQueries.push(new Query_1.Query("ALTER TABLE ".concat(this.escapePath(table), " DROP CONSTRAINT \"").concat(pkName, "\"")));
|
|
1201
|
-
}
|
|
1202
|
-
else {
|
|
1203
|
-
primaryColumn = primaryColumns.find(function (c) { return c.name === newColumn.name; });
|
|
1204
|
-
primaryColumns.splice(primaryColumns.indexOf(primaryColumn), 1);
|
|
1205
|
-
column = clonedTable.columns.find(function (column) { return column.name === newColumn.name; });
|
|
1206
|
-
column.isPrimary = false;
|
|
1207
|
-
// if we have another primary keys, we must recreate constraint.
|
|
1208
|
-
if (primaryColumns.length > 0) {
|
|
1209
|
-
pkName = this.connection.namingStrategy.primaryKeyName(clonedTable, primaryColumns.map(function (column) { return column.name; }));
|
|
1210
|
-
columnNames = primaryColumns
|
|
1211
|
-
.map(function (column) { return "\"".concat(column.name, "\""); })
|
|
1212
|
-
.join(", ");
|
|
1213
|
-
upQueries.push(new Query_1.Query("ALTER TABLE ".concat(this.escapePath(table), " ADD CONSTRAINT \"").concat(pkName, "\" PRIMARY KEY (").concat(columnNames, ")")));
|
|
1214
|
-
downQueries.push(new Query_1.Query("ALTER TABLE ".concat(this.escapePath(table), " DROP CONSTRAINT \"").concat(pkName, "\"")));
|
|
1215
|
-
}
|
|
1216
|
-
}
|
|
1217
|
-
}
|
|
1218
|
-
if (newColumn.isUnique !== oldColumn.isUnique) {
|
|
1219
|
-
if (newColumn.isUnique === true) {
|
|
1220
|
-
uniqueIndex = new TableIndex_1.TableIndex({
|
|
1221
|
-
name: this.connection.namingStrategy.indexName(table, [
|
|
1222
|
-
newColumn.name,
|
|
1223
|
-
]),
|
|
1224
|
-
columnNames: [newColumn.name],
|
|
1225
|
-
isUnique: true,
|
|
1226
|
-
});
|
|
1227
|
-
clonedTable.indices.push(uniqueIndex);
|
|
1228
|
-
clonedTable.uniques.push(new TableUnique_1.TableUnique({
|
|
1229
|
-
name: uniqueIndex.name,
|
|
1230
|
-
columnNames: uniqueIndex.columnNames,
|
|
1231
|
-
}));
|
|
1232
|
-
upQueries.push(this.createIndexSql(table, uniqueIndex));
|
|
1233
|
-
downQueries.push(this.dropIndexSql(table, uniqueIndex));
|
|
1234
|
-
}
|
|
1235
|
-
else {
|
|
1236
|
-
uniqueIndex_1 = clonedTable.indices.find(function (index) {
|
|
1237
|
-
return (index.columnNames.length === 1 &&
|
|
1238
|
-
index.isUnique === true &&
|
|
1239
|
-
!!index.columnNames.find(function (columnName) { return columnName === newColumn.name; }));
|
|
1240
|
-
});
|
|
1241
|
-
clonedTable.indices.splice(clonedTable.indices.indexOf(uniqueIndex_1), 1);
|
|
1242
|
-
tableUnique = clonedTable.uniques.find(function (unique) { return unique.name === uniqueIndex_1.name; });
|
|
1243
|
-
clonedTable.uniques.splice(clonedTable.uniques.indexOf(tableUnique), 1);
|
|
1244
|
-
upQueries.push(this.dropIndexSql(table, uniqueIndex_1));
|
|
1245
|
-
downQueries.push(this.createIndexSql(table, uniqueIndex_1));
|
|
1246
|
-
}
|
|
1247
|
-
}
|
|
1248
|
-
if (newColumn.default !== oldColumn.default) {
|
|
1249
|
-
if (newColumn.default !== null &&
|
|
1250
|
-
newColumn.default !== undefined) {
|
|
1251
|
-
upQueries.push(new Query_1.Query("ALTER TABLE ".concat(this.escapePath(table), " ALTER (\"").concat(newColumn.name, "\" ").concat(this.connection.driver.createFullType(newColumn), " DEFAULT ").concat(newColumn.default, ")")));
|
|
1252
|
-
if (oldColumn.default !== null &&
|
|
1253
|
-
oldColumn.default !== undefined) {
|
|
1254
|
-
downQueries.push(new Query_1.Query("ALTER TABLE ".concat(this.escapePath(table), " ALTER (\"").concat(oldColumn.name, "\" ").concat(this.connection.driver.createFullType(oldColumn), " DEFAULT ").concat(oldColumn.default, ")")));
|
|
1255
|
-
}
|
|
1256
|
-
else {
|
|
1257
|
-
downQueries.push(new Query_1.Query("ALTER TABLE ".concat(this.escapePath(table), " ALTER (\"").concat(oldColumn.name, "\" ").concat(this.connection.driver.createFullType(oldColumn), " DEFAULT NULL)")));
|
|
1258
|
-
}
|
|
1259
|
-
}
|
|
1260
|
-
else if (oldColumn.default !== null &&
|
|
1261
|
-
oldColumn.default !== undefined) {
|
|
1262
|
-
upQueries.push(new Query_1.Query("ALTER TABLE ".concat(this.escapePath(table), " ALTER (\"").concat(newColumn.name, "\" ").concat(this.connection.driver.createFullType(newColumn), " DEFAULT NULL)")));
|
|
1263
|
-
downQueries.push(new Query_1.Query("ALTER TABLE ".concat(this.escapePath(table), " ALTER (\"").concat(oldColumn.name, "\" ").concat(this.connection.driver.createFullType(oldColumn), " DEFAULT ").concat(oldColumn.default, ")")));
|
|
1264
|
-
}
|
|
1265
|
-
}
|
|
1266
|
-
return [4 /*yield*/, this.executeQueries(upQueries, downQueries)];
|
|
1267
|
-
case 7:
|
|
1268
|
-
_b.sent();
|
|
1269
|
-
this.replaceCachedTable(table, clonedTable);
|
|
1270
|
-
_b.label = 8;
|
|
1271
|
-
case 8: return [2 /*return*/];
|
|
667
|
+
async changeColumn(tableOrName, oldTableColumnOrName, newColumn) {
|
|
668
|
+
const table = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
|
|
669
|
+
? tableOrName
|
|
670
|
+
: await this.getCachedTable(tableOrName);
|
|
671
|
+
let clonedTable = table.clone();
|
|
672
|
+
const upQueries = [];
|
|
673
|
+
const downQueries = [];
|
|
674
|
+
const oldColumn = InstanceChecker_1.InstanceChecker.isTableColumn(oldTableColumnOrName)
|
|
675
|
+
? oldTableColumnOrName
|
|
676
|
+
: table.columns.find((column) => column.name === oldTableColumnOrName);
|
|
677
|
+
if (!oldColumn)
|
|
678
|
+
throw new error_1.TypeORMError(`Column "${oldTableColumnOrName}" was not found in the "${table.name}" table.`);
|
|
679
|
+
if ((newColumn.isGenerated !== oldColumn.isGenerated &&
|
|
680
|
+
newColumn.generationStrategy !== "uuid") ||
|
|
681
|
+
newColumn.type !== oldColumn.type ||
|
|
682
|
+
newColumn.length !== oldColumn.length) {
|
|
683
|
+
// SQL Server does not support changing of IDENTITY column, so we must drop column and recreate it again.
|
|
684
|
+
// Also, we recreate column if column type changed
|
|
685
|
+
await this.dropColumn(table, oldColumn);
|
|
686
|
+
await this.addColumn(table, newColumn);
|
|
687
|
+
// update cloned table
|
|
688
|
+
clonedTable = table.clone();
|
|
689
|
+
}
|
|
690
|
+
else {
|
|
691
|
+
if (newColumn.name !== oldColumn.name) {
|
|
692
|
+
// rename column
|
|
693
|
+
upQueries.push(new Query_1.Query(`RENAME COLUMN ${this.escapePath(table)}."${oldColumn.name}" TO "${newColumn.name}"`));
|
|
694
|
+
downQueries.push(new Query_1.Query(`RENAME COLUMN ${this.escapePath(table)}."${newColumn.name}" TO "${oldColumn.name}"`));
|
|
695
|
+
if (oldColumn.isPrimary === true) {
|
|
696
|
+
const primaryColumns = clonedTable.primaryColumns;
|
|
697
|
+
// build old primary constraint name
|
|
698
|
+
const columnNames = primaryColumns.map((column) => column.name);
|
|
699
|
+
const oldPkName = this.connection.namingStrategy.primaryKeyName(clonedTable, columnNames);
|
|
700
|
+
// replace old column name with new column name
|
|
701
|
+
columnNames.splice(columnNames.indexOf(oldColumn.name), 1);
|
|
702
|
+
columnNames.push(newColumn.name);
|
|
703
|
+
const columnNamesString = columnNames
|
|
704
|
+
.map((columnName) => `"${columnName}"`)
|
|
705
|
+
.join(", ");
|
|
706
|
+
// drop old PK
|
|
707
|
+
upQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(clonedTable)} DROP CONSTRAINT "${oldPkName}"`));
|
|
708
|
+
downQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(clonedTable)} ADD CONSTRAINT "${oldPkName}" PRIMARY KEY (${columnNamesString})`));
|
|
709
|
+
// build new primary constraint name
|
|
710
|
+
const newPkName = this.connection.namingStrategy.primaryKeyName(clonedTable, columnNames);
|
|
711
|
+
// create new PK
|
|
712
|
+
upQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(clonedTable)} ADD CONSTRAINT "${newPkName}" PRIMARY KEY (${columnNamesString})`));
|
|
713
|
+
downQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(clonedTable)} DROP CONSTRAINT "${newPkName}"`));
|
|
1272
714
|
}
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
715
|
+
// rename index constraints
|
|
716
|
+
clonedTable.findColumnIndices(oldColumn).forEach((index) => {
|
|
717
|
+
// build new constraint name
|
|
718
|
+
index.columnNames.splice(index.columnNames.indexOf(oldColumn.name), 1);
|
|
719
|
+
index.columnNames.push(newColumn.name);
|
|
720
|
+
const newIndexName = this.connection.namingStrategy.indexName(clonedTable, index.columnNames, index.where);
|
|
721
|
+
// drop old index
|
|
722
|
+
upQueries.push(this.dropIndexSql(clonedTable, index));
|
|
723
|
+
downQueries.push(this.createIndexSql(clonedTable, index));
|
|
724
|
+
// replace constraint name
|
|
725
|
+
index.name = newIndexName;
|
|
726
|
+
// create new index
|
|
727
|
+
upQueries.push(this.createIndexSql(clonedTable, index));
|
|
728
|
+
downQueries.push(this.dropIndexSql(clonedTable, index));
|
|
729
|
+
});
|
|
730
|
+
// rename foreign key constraints
|
|
731
|
+
clonedTable
|
|
732
|
+
.findColumnForeignKeys(oldColumn)
|
|
733
|
+
.forEach((foreignKey) => {
|
|
734
|
+
// build new constraint name
|
|
735
|
+
foreignKey.columnNames.splice(foreignKey.columnNames.indexOf(oldColumn.name), 1);
|
|
736
|
+
foreignKey.columnNames.push(newColumn.name);
|
|
737
|
+
const newForeignKeyName = this.connection.namingStrategy.foreignKeyName(clonedTable, foreignKey.columnNames, this.getTablePath(foreignKey), foreignKey.referencedColumnNames);
|
|
738
|
+
upQueries.push(this.dropForeignKeySql(clonedTable, foreignKey));
|
|
739
|
+
downQueries.push(this.createForeignKeySql(clonedTable, foreignKey));
|
|
740
|
+
// replace constraint name
|
|
741
|
+
foreignKey.name = newForeignKeyName;
|
|
742
|
+
// create new FK's
|
|
743
|
+
upQueries.push(this.createForeignKeySql(clonedTable, foreignKey));
|
|
744
|
+
downQueries.push(this.dropForeignKeySql(clonedTable, foreignKey));
|
|
745
|
+
});
|
|
746
|
+
// rename check constraints
|
|
747
|
+
clonedTable.findColumnChecks(oldColumn).forEach((check) => {
|
|
748
|
+
// build new constraint name
|
|
749
|
+
check.columnNames.splice(check.columnNames.indexOf(oldColumn.name), 1);
|
|
750
|
+
check.columnNames.push(newColumn.name);
|
|
751
|
+
const newCheckName = this.connection.namingStrategy.checkConstraintName(clonedTable, check.expression);
|
|
752
|
+
upQueries.push(this.dropCheckConstraintSql(clonedTable, check));
|
|
753
|
+
downQueries.push(this.createCheckConstraintSql(clonedTable, check));
|
|
754
|
+
// replace constraint name
|
|
755
|
+
check.name = newCheckName;
|
|
756
|
+
upQueries.push(this.createCheckConstraintSql(clonedTable, check));
|
|
757
|
+
downQueries.push(this.dropCheckConstraintSql(clonedTable, check));
|
|
758
|
+
});
|
|
759
|
+
// rename old column in the Table object
|
|
760
|
+
const oldTableColumn = clonedTable.columns.find((column) => column.name === oldColumn.name);
|
|
761
|
+
clonedTable.columns[clonedTable.columns.indexOf(oldTableColumn)].name = newColumn.name;
|
|
762
|
+
oldColumn.name = newColumn.name;
|
|
763
|
+
}
|
|
764
|
+
if (this.isColumnChanged(oldColumn, newColumn)) {
|
|
765
|
+
upQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} ALTER (${this.buildCreateColumnSql(newColumn)})`));
|
|
766
|
+
downQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} ALTER (${this.buildCreateColumnSql(oldColumn)})`));
|
|
767
|
+
}
|
|
768
|
+
if (newColumn.isPrimary !== oldColumn.isPrimary) {
|
|
769
|
+
const primaryColumns = clonedTable.primaryColumns;
|
|
770
|
+
// if primary column state changed, we must always drop existed constraint.
|
|
771
|
+
if (primaryColumns.length > 0) {
|
|
772
|
+
const pkName = this.connection.namingStrategy.primaryKeyName(clonedTable, primaryColumns.map((column) => column.name));
|
|
773
|
+
const columnNames = primaryColumns
|
|
774
|
+
.map((column) => `"${column.name}"`)
|
|
775
|
+
.join(", ");
|
|
776
|
+
upQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} DROP CONSTRAINT "${pkName}"`));
|
|
777
|
+
downQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} ADD CONSTRAINT "${pkName}" PRIMARY KEY (${columnNames})`));
|
|
778
|
+
}
|
|
779
|
+
if (newColumn.isPrimary === true) {
|
|
780
|
+
primaryColumns.push(newColumn);
|
|
781
|
+
// update column in table
|
|
782
|
+
const column = clonedTable.columns.find((column) => column.name === newColumn.name);
|
|
783
|
+
column.isPrimary = true;
|
|
784
|
+
const pkName = this.connection.namingStrategy.primaryKeyName(clonedTable, primaryColumns.map((column) => column.name));
|
|
785
|
+
const columnNames = primaryColumns
|
|
786
|
+
.map((column) => `"${column.name}"`)
|
|
787
|
+
.join(", ");
|
|
788
|
+
upQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} ADD CONSTRAINT "${pkName}" PRIMARY KEY (${columnNames})`));
|
|
789
|
+
downQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} DROP CONSTRAINT "${pkName}"`));
|
|
790
|
+
}
|
|
791
|
+
else {
|
|
792
|
+
const primaryColumn = primaryColumns.find((c) => c.name === newColumn.name);
|
|
793
|
+
primaryColumns.splice(primaryColumns.indexOf(primaryColumn), 1);
|
|
794
|
+
// update column in table
|
|
795
|
+
const column = clonedTable.columns.find((column) => column.name === newColumn.name);
|
|
796
|
+
column.isPrimary = false;
|
|
797
|
+
// if we have another primary keys, we must recreate constraint.
|
|
798
|
+
if (primaryColumns.length > 0) {
|
|
799
|
+
const pkName = this.connection.namingStrategy.primaryKeyName(clonedTable, primaryColumns.map((column) => column.name));
|
|
800
|
+
const columnNames = primaryColumns
|
|
801
|
+
.map((column) => `"${column.name}"`)
|
|
802
|
+
.join(", ");
|
|
803
|
+
upQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} ADD CONSTRAINT "${pkName}" PRIMARY KEY (${columnNames})`));
|
|
804
|
+
downQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} DROP CONSTRAINT "${pkName}"`));
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
if (newColumn.isUnique !== oldColumn.isUnique) {
|
|
809
|
+
if (newColumn.isUnique === true) {
|
|
810
|
+
const uniqueIndex = new TableIndex_1.TableIndex({
|
|
811
|
+
name: this.connection.namingStrategy.indexName(table, [
|
|
812
|
+
newColumn.name,
|
|
813
|
+
]),
|
|
814
|
+
columnNames: [newColumn.name],
|
|
815
|
+
isUnique: true,
|
|
816
|
+
});
|
|
817
|
+
clonedTable.indices.push(uniqueIndex);
|
|
818
|
+
clonedTable.uniques.push(new TableUnique_1.TableUnique({
|
|
819
|
+
name: uniqueIndex.name,
|
|
820
|
+
columnNames: uniqueIndex.columnNames,
|
|
821
|
+
}));
|
|
822
|
+
upQueries.push(this.createIndexSql(table, uniqueIndex));
|
|
823
|
+
downQueries.push(this.dropIndexSql(table, uniqueIndex));
|
|
824
|
+
}
|
|
825
|
+
else {
|
|
826
|
+
const uniqueIndex = clonedTable.indices.find((index) => {
|
|
827
|
+
return (index.columnNames.length === 1 &&
|
|
828
|
+
index.isUnique === true &&
|
|
829
|
+
!!index.columnNames.find((columnName) => columnName === newColumn.name));
|
|
830
|
+
});
|
|
831
|
+
clonedTable.indices.splice(clonedTable.indices.indexOf(uniqueIndex), 1);
|
|
832
|
+
const tableUnique = clonedTable.uniques.find((unique) => unique.name === uniqueIndex.name);
|
|
833
|
+
clonedTable.uniques.splice(clonedTable.uniques.indexOf(tableUnique), 1);
|
|
834
|
+
upQueries.push(this.dropIndexSql(table, uniqueIndex));
|
|
835
|
+
downQueries.push(this.createIndexSql(table, uniqueIndex));
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
if (newColumn.default !== oldColumn.default) {
|
|
839
|
+
if (newColumn.default !== null &&
|
|
840
|
+
newColumn.default !== undefined) {
|
|
841
|
+
upQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} ALTER ("${newColumn.name}" ${this.connection.driver.createFullType(newColumn)} DEFAULT ${newColumn.default})`));
|
|
842
|
+
if (oldColumn.default !== null &&
|
|
843
|
+
oldColumn.default !== undefined) {
|
|
844
|
+
downQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} ALTER ("${oldColumn.name}" ${this.connection.driver.createFullType(oldColumn)} DEFAULT ${oldColumn.default})`));
|
|
845
|
+
}
|
|
846
|
+
else {
|
|
847
|
+
downQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} ALTER ("${oldColumn.name}" ${this.connection.driver.createFullType(oldColumn)} DEFAULT NULL)`));
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
else if (oldColumn.default !== null &&
|
|
851
|
+
oldColumn.default !== undefined) {
|
|
852
|
+
upQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} ALTER ("${newColumn.name}" ${this.connection.driver.createFullType(newColumn)} DEFAULT NULL)`));
|
|
853
|
+
downQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} ALTER ("${oldColumn.name}" ${this.connection.driver.createFullType(oldColumn)} DEFAULT ${oldColumn.default})`));
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
await this.executeQueries(upQueries, downQueries);
|
|
857
|
+
this.replaceCachedTable(table, clonedTable);
|
|
858
|
+
}
|
|
859
|
+
}
|
|
1276
860
|
/**
|
|
1277
861
|
* Changes a column in the table.
|
|
1278
862
|
*/
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
switch (_c.label) {
|
|
1285
|
-
case 0:
|
|
1286
|
-
_c.trys.push([0, 5, 6, 7]);
|
|
1287
|
-
changedColumns_1 = tslib_1.__values(changedColumns), changedColumns_1_1 = changedColumns_1.next();
|
|
1288
|
-
_c.label = 1;
|
|
1289
|
-
case 1:
|
|
1290
|
-
if (!!changedColumns_1_1.done) return [3 /*break*/, 4];
|
|
1291
|
-
_a = changedColumns_1_1.value, oldColumn = _a.oldColumn, newColumn = _a.newColumn;
|
|
1292
|
-
return [4 /*yield*/, this.changeColumn(tableOrName, oldColumn, newColumn)];
|
|
1293
|
-
case 2:
|
|
1294
|
-
_c.sent();
|
|
1295
|
-
_c.label = 3;
|
|
1296
|
-
case 3:
|
|
1297
|
-
changedColumns_1_1 = changedColumns_1.next();
|
|
1298
|
-
return [3 /*break*/, 1];
|
|
1299
|
-
case 4: return [3 /*break*/, 7];
|
|
1300
|
-
case 5:
|
|
1301
|
-
e_3_1 = _c.sent();
|
|
1302
|
-
e_3 = { error: e_3_1 };
|
|
1303
|
-
return [3 /*break*/, 7];
|
|
1304
|
-
case 6:
|
|
1305
|
-
try {
|
|
1306
|
-
if (changedColumns_1_1 && !changedColumns_1_1.done && (_b = changedColumns_1.return)) _b.call(changedColumns_1);
|
|
1307
|
-
}
|
|
1308
|
-
finally { if (e_3) throw e_3.error; }
|
|
1309
|
-
return [7 /*endfinally*/];
|
|
1310
|
-
case 7: return [2 /*return*/];
|
|
1311
|
-
}
|
|
1312
|
-
});
|
|
1313
|
-
});
|
|
1314
|
-
};
|
|
863
|
+
async changeColumns(tableOrName, changedColumns) {
|
|
864
|
+
for (const { oldColumn, newColumn } of changedColumns) {
|
|
865
|
+
await this.changeColumn(tableOrName, oldColumn, newColumn);
|
|
866
|
+
}
|
|
867
|
+
}
|
|
1315
868
|
/**
|
|
1316
869
|
* Drops column in the table.
|
|
1317
870
|
*/
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
tableColumn = clonedTable.findColumnByName(column.name);
|
|
1397
|
-
tableColumn.isPrimary = false;
|
|
1398
|
-
// if primary key have multiple columns, we must recreate it without dropped column
|
|
1399
|
-
if (clonedTable.primaryColumns.length > 0) {
|
|
1400
|
-
pkName_2 = this.connection.namingStrategy.primaryKeyName(clonedTable, clonedTable.primaryColumns.map(function (column) { return column.name; }));
|
|
1401
|
-
columnNames_2 = clonedTable.primaryColumns
|
|
1402
|
-
.map(function (primaryColumn) { return "\"".concat(primaryColumn.name, "\""); })
|
|
1403
|
-
.join(", ");
|
|
1404
|
-
upQueries.push(new Query_1.Query("ALTER TABLE ".concat(this.escapePath(clonedTable), " ADD CONSTRAINT \"").concat(pkName_2, "\" PRIMARY KEY (").concat(columnNames_2, ")")));
|
|
1405
|
-
downQueries.push(new Query_1.Query("ALTER TABLE ".concat(this.escapePath(clonedTable), " DROP CONSTRAINT \"").concat(pkName_2, "\"")));
|
|
1406
|
-
}
|
|
1407
|
-
// restore referenced foreign keys
|
|
1408
|
-
referencedForeignKeys.forEach(function (foreignKey) {
|
|
1409
|
-
var mapping = referencedForeignKeyTableMapping_2.find(function (it) { return it.fkName === foreignKey.name; });
|
|
1410
|
-
upQueries.push(_this.createForeignKeySql(mapping.tableName, foreignKey));
|
|
1411
|
-
downQueries.push(_this.dropForeignKeySql(mapping.tableName, foreignKey));
|
|
1412
|
-
});
|
|
1413
|
-
_c.label = 7;
|
|
1414
|
-
case 7:
|
|
1415
|
-
columnIndex = clonedTable.indices.find(function (index) {
|
|
1416
|
-
return index.columnNames.length === 1 &&
|
|
1417
|
-
index.columnNames[0] === column.name;
|
|
1418
|
-
});
|
|
1419
|
-
if (columnIndex) {
|
|
1420
|
-
clonedTable.indices.splice(clonedTable.indices.indexOf(columnIndex), 1);
|
|
1421
|
-
upQueries.push(this.dropIndexSql(table, columnIndex));
|
|
1422
|
-
downQueries.push(this.createIndexSql(table, columnIndex));
|
|
1423
|
-
}
|
|
1424
|
-
else if (column.isUnique) {
|
|
1425
|
-
uniqueName_1 = this.connection.namingStrategy.uniqueConstraintName(table, [
|
|
1426
|
-
column.name,
|
|
1427
|
-
]);
|
|
1428
|
-
foundUnique = clonedTable.uniques.find(function (unique) { return unique.name === uniqueName_1; });
|
|
1429
|
-
if (foundUnique) {
|
|
1430
|
-
clonedTable.uniques.splice(clonedTable.uniques.indexOf(foundUnique), 1);
|
|
1431
|
-
upQueries.push(this.dropIndexSql(table, uniqueName_1));
|
|
1432
|
-
downQueries.push(new Query_1.Query("CREATE UNIQUE INDEX \"".concat(uniqueName_1, "\" ON ").concat(this.escapePath(table), " (\"").concat(column.name, "\")")));
|
|
1433
|
-
}
|
|
1434
|
-
indexName_1 = this.connection.namingStrategy.indexName(table, [
|
|
1435
|
-
column.name,
|
|
1436
|
-
]);
|
|
1437
|
-
foundIndex = clonedTable.indices.find(function (index) { return index.name === indexName_1; });
|
|
1438
|
-
if (foundIndex) {
|
|
1439
|
-
clonedTable.indices.splice(clonedTable.indices.indexOf(foundIndex), 1);
|
|
1440
|
-
upQueries.push(this.dropIndexSql(table, indexName_1));
|
|
1441
|
-
downQueries.push(new Query_1.Query("CREATE UNIQUE INDEX \"".concat(indexName_1, "\" ON ").concat(this.escapePath(table), " (\"").concat(column.name, "\")")));
|
|
1442
|
-
}
|
|
1443
|
-
}
|
|
1444
|
-
columnCheck = clonedTable.checks.find(function (check) {
|
|
1445
|
-
return !!check.columnNames &&
|
|
1446
|
-
check.columnNames.length === 1 &&
|
|
1447
|
-
check.columnNames[0] === column.name;
|
|
1448
|
-
});
|
|
1449
|
-
if (columnCheck) {
|
|
1450
|
-
clonedTable.checks.splice(clonedTable.checks.indexOf(columnCheck), 1);
|
|
1451
|
-
upQueries.push(this.dropCheckConstraintSql(table, columnCheck));
|
|
1452
|
-
downQueries.push(this.createCheckConstraintSql(table, columnCheck));
|
|
1453
|
-
}
|
|
1454
|
-
upQueries.push(new Query_1.Query(this.dropColumnSql(table, column)));
|
|
1455
|
-
downQueries.push(new Query_1.Query(this.addColumnSql(table, column)));
|
|
1456
|
-
return [4 /*yield*/, this.executeQueries(upQueries, downQueries)];
|
|
1457
|
-
case 8:
|
|
1458
|
-
_c.sent();
|
|
1459
|
-
clonedTable.removeColumn(column);
|
|
1460
|
-
this.replaceCachedTable(table, clonedTable);
|
|
1461
|
-
return [2 /*return*/];
|
|
1462
|
-
}
|
|
871
|
+
async dropColumn(tableOrName, columnOrName) {
|
|
872
|
+
const table = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
|
|
873
|
+
? tableOrName
|
|
874
|
+
: await this.getCachedTable(tableOrName);
|
|
875
|
+
const parsedTableName = this.driver.parseTableName(table);
|
|
876
|
+
if (!parsedTableName.schema) {
|
|
877
|
+
parsedTableName.schema = await this.getCurrentSchema();
|
|
878
|
+
}
|
|
879
|
+
const column = InstanceChecker_1.InstanceChecker.isTableColumn(columnOrName)
|
|
880
|
+
? columnOrName
|
|
881
|
+
: table.findColumnByName(columnOrName);
|
|
882
|
+
if (!column)
|
|
883
|
+
throw new error_1.TypeORMError(`Column "${columnOrName}" was not found in table "${table.name}"`);
|
|
884
|
+
const clonedTable = table.clone();
|
|
885
|
+
const upQueries = [];
|
|
886
|
+
const downQueries = [];
|
|
887
|
+
// drop primary key constraint
|
|
888
|
+
if (column.isPrimary) {
|
|
889
|
+
// SAP HANA does not allow to drop PK's which is referenced by foreign keys.
|
|
890
|
+
// To avoid this, we must drop all referential foreign keys and recreate them later
|
|
891
|
+
const referencedForeignKeySql = `SELECT * FROM "SYS"."REFERENTIAL_CONSTRAINTS" WHERE "REFERENCED_SCHEMA_NAME" = '${parsedTableName.schema}' AND "REFERENCED_TABLE_NAME" = '${parsedTableName.tableName}'`;
|
|
892
|
+
const dbForeignKeys = await this.query(referencedForeignKeySql);
|
|
893
|
+
let referencedForeignKeys = [];
|
|
894
|
+
const referencedForeignKeyTableMapping = [];
|
|
895
|
+
if (dbForeignKeys.length > 0) {
|
|
896
|
+
referencedForeignKeys = dbForeignKeys.map((dbForeignKey) => {
|
|
897
|
+
const foreignKeys = dbForeignKeys.filter((dbFk) => dbFk["CONSTRAINT_NAME"] ===
|
|
898
|
+
dbForeignKey["CONSTRAINT_NAME"]);
|
|
899
|
+
referencedForeignKeyTableMapping.push({
|
|
900
|
+
tableName: `${dbForeignKey["SCHEMA_NAME"]}.${dbForeignKey["TABLE_NAME"]}`,
|
|
901
|
+
fkName: dbForeignKey["CONSTRAINT_NAME"],
|
|
902
|
+
});
|
|
903
|
+
return new TableForeignKey_1.TableForeignKey({
|
|
904
|
+
name: dbForeignKey["CONSTRAINT_NAME"],
|
|
905
|
+
columnNames: foreignKeys.map((dbFk) => dbFk["COLUMN_NAME"]),
|
|
906
|
+
referencedDatabase: table.database,
|
|
907
|
+
referencedSchema: table.schema,
|
|
908
|
+
referencedTableName: table.name,
|
|
909
|
+
referencedColumnNames: foreignKeys.map((dbFk) => dbFk["REFERENCED_COLUMN_NAME"]),
|
|
910
|
+
onDelete: dbForeignKey["DELETE_RULE"] === "RESTRICT"
|
|
911
|
+
? "NO ACTION"
|
|
912
|
+
: dbForeignKey["DELETE_RULE"],
|
|
913
|
+
onUpdate: dbForeignKey["UPDATE_RULE"] === "RESTRICT"
|
|
914
|
+
? "NO ACTION"
|
|
915
|
+
: dbForeignKey["UPDATE_RULE"],
|
|
916
|
+
deferrable: dbForeignKey["CHECK_TIME"].replace("_", " "),
|
|
917
|
+
});
|
|
918
|
+
});
|
|
919
|
+
// drop referenced foreign keys
|
|
920
|
+
referencedForeignKeys.forEach((foreignKey) => {
|
|
921
|
+
const mapping = referencedForeignKeyTableMapping.find((it) => it.fkName === foreignKey.name);
|
|
922
|
+
upQueries.push(this.dropForeignKeySql(mapping.tableName, foreignKey));
|
|
923
|
+
downQueries.push(this.createForeignKeySql(mapping.tableName, foreignKey));
|
|
924
|
+
});
|
|
925
|
+
}
|
|
926
|
+
const pkName = this.connection.namingStrategy.primaryKeyName(clonedTable, clonedTable.primaryColumns.map((column) => column.name));
|
|
927
|
+
const columnNames = clonedTable.primaryColumns
|
|
928
|
+
.map((primaryColumn) => `"${primaryColumn.name}"`)
|
|
929
|
+
.join(", ");
|
|
930
|
+
upQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(clonedTable)} DROP CONSTRAINT "${pkName}"`));
|
|
931
|
+
downQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(clonedTable)} ADD CONSTRAINT "${pkName}" PRIMARY KEY (${columnNames})`));
|
|
932
|
+
// update column in table
|
|
933
|
+
const tableColumn = clonedTable.findColumnByName(column.name);
|
|
934
|
+
tableColumn.isPrimary = false;
|
|
935
|
+
// if primary key have multiple columns, we must recreate it without dropped column
|
|
936
|
+
if (clonedTable.primaryColumns.length > 0) {
|
|
937
|
+
const pkName = this.connection.namingStrategy.primaryKeyName(clonedTable, clonedTable.primaryColumns.map((column) => column.name));
|
|
938
|
+
const columnNames = clonedTable.primaryColumns
|
|
939
|
+
.map((primaryColumn) => `"${primaryColumn.name}"`)
|
|
940
|
+
.join(", ");
|
|
941
|
+
upQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(clonedTable)} ADD CONSTRAINT "${pkName}" PRIMARY KEY (${columnNames})`));
|
|
942
|
+
downQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(clonedTable)} DROP CONSTRAINT "${pkName}"`));
|
|
943
|
+
}
|
|
944
|
+
// restore referenced foreign keys
|
|
945
|
+
referencedForeignKeys.forEach((foreignKey) => {
|
|
946
|
+
const mapping = referencedForeignKeyTableMapping.find((it) => it.fkName === foreignKey.name);
|
|
947
|
+
upQueries.push(this.createForeignKeySql(mapping.tableName, foreignKey));
|
|
948
|
+
downQueries.push(this.dropForeignKeySql(mapping.tableName, foreignKey));
|
|
1463
949
|
});
|
|
1464
|
-
}
|
|
1465
|
-
|
|
950
|
+
}
|
|
951
|
+
// drop column index
|
|
952
|
+
const columnIndex = clonedTable.indices.find((index) => index.columnNames.length === 1 &&
|
|
953
|
+
index.columnNames[0] === column.name);
|
|
954
|
+
if (columnIndex) {
|
|
955
|
+
clonedTable.indices.splice(clonedTable.indices.indexOf(columnIndex), 1);
|
|
956
|
+
upQueries.push(this.dropIndexSql(table, columnIndex));
|
|
957
|
+
downQueries.push(this.createIndexSql(table, columnIndex));
|
|
958
|
+
}
|
|
959
|
+
else if (column.isUnique) {
|
|
960
|
+
// we splice constraints both from table uniques and indices.
|
|
961
|
+
const uniqueName = this.connection.namingStrategy.uniqueConstraintName(table, [
|
|
962
|
+
column.name,
|
|
963
|
+
]);
|
|
964
|
+
const foundUnique = clonedTable.uniques.find((unique) => unique.name === uniqueName);
|
|
965
|
+
if (foundUnique) {
|
|
966
|
+
clonedTable.uniques.splice(clonedTable.uniques.indexOf(foundUnique), 1);
|
|
967
|
+
upQueries.push(this.dropIndexSql(table, uniqueName));
|
|
968
|
+
downQueries.push(new Query_1.Query(`CREATE UNIQUE INDEX "${uniqueName}" ON ${this.escapePath(table)} ("${column.name}")`));
|
|
969
|
+
}
|
|
970
|
+
const indexName = this.connection.namingStrategy.indexName(table, [
|
|
971
|
+
column.name,
|
|
972
|
+
]);
|
|
973
|
+
const foundIndex = clonedTable.indices.find((index) => index.name === indexName);
|
|
974
|
+
if (foundIndex) {
|
|
975
|
+
clonedTable.indices.splice(clonedTable.indices.indexOf(foundIndex), 1);
|
|
976
|
+
upQueries.push(this.dropIndexSql(table, indexName));
|
|
977
|
+
downQueries.push(new Query_1.Query(`CREATE UNIQUE INDEX "${indexName}" ON ${this.escapePath(table)} ("${column.name}")`));
|
|
978
|
+
}
|
|
979
|
+
}
|
|
980
|
+
// drop column check
|
|
981
|
+
const columnCheck = clonedTable.checks.find((check) => !!check.columnNames &&
|
|
982
|
+
check.columnNames.length === 1 &&
|
|
983
|
+
check.columnNames[0] === column.name);
|
|
984
|
+
if (columnCheck) {
|
|
985
|
+
clonedTable.checks.splice(clonedTable.checks.indexOf(columnCheck), 1);
|
|
986
|
+
upQueries.push(this.dropCheckConstraintSql(table, columnCheck));
|
|
987
|
+
downQueries.push(this.createCheckConstraintSql(table, columnCheck));
|
|
988
|
+
}
|
|
989
|
+
upQueries.push(new Query_1.Query(this.dropColumnSql(table, column)));
|
|
990
|
+
downQueries.push(new Query_1.Query(this.addColumnSql(table, column)));
|
|
991
|
+
await this.executeQueries(upQueries, downQueries);
|
|
992
|
+
clonedTable.removeColumn(column);
|
|
993
|
+
this.replaceCachedTable(table, clonedTable);
|
|
994
|
+
}
|
|
1466
995
|
/**
|
|
1467
996
|
* Drops the columns in the table.
|
|
1468
997
|
*/
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
switch (_b.label) {
|
|
1475
|
-
case 0:
|
|
1476
|
-
_b.trys.push([0, 5, 6, 7]);
|
|
1477
|
-
columns_2 = tslib_1.__values(columns), columns_2_1 = columns_2.next();
|
|
1478
|
-
_b.label = 1;
|
|
1479
|
-
case 1:
|
|
1480
|
-
if (!!columns_2_1.done) return [3 /*break*/, 4];
|
|
1481
|
-
column = columns_2_1.value;
|
|
1482
|
-
return [4 /*yield*/, this.dropColumn(tableOrName, column)];
|
|
1483
|
-
case 2:
|
|
1484
|
-
_b.sent();
|
|
1485
|
-
_b.label = 3;
|
|
1486
|
-
case 3:
|
|
1487
|
-
columns_2_1 = columns_2.next();
|
|
1488
|
-
return [3 /*break*/, 1];
|
|
1489
|
-
case 4: return [3 /*break*/, 7];
|
|
1490
|
-
case 5:
|
|
1491
|
-
e_4_1 = _b.sent();
|
|
1492
|
-
e_4 = { error: e_4_1 };
|
|
1493
|
-
return [3 /*break*/, 7];
|
|
1494
|
-
case 6:
|
|
1495
|
-
try {
|
|
1496
|
-
if (columns_2_1 && !columns_2_1.done && (_a = columns_2.return)) _a.call(columns_2);
|
|
1497
|
-
}
|
|
1498
|
-
finally { if (e_4) throw e_4.error; }
|
|
1499
|
-
return [7 /*endfinally*/];
|
|
1500
|
-
case 7: return [2 /*return*/];
|
|
1501
|
-
}
|
|
1502
|
-
});
|
|
1503
|
-
});
|
|
1504
|
-
};
|
|
998
|
+
async dropColumns(tableOrName, columns) {
|
|
999
|
+
for (const column of columns) {
|
|
1000
|
+
await this.dropColumn(tableOrName, column);
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1505
1003
|
/**
|
|
1506
1004
|
* Creates a new primary key.
|
|
1507
1005
|
*/
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
case 2:
|
|
1519
|
-
_a = _b.sent();
|
|
1520
|
-
_b.label = 3;
|
|
1521
|
-
case 3:
|
|
1522
|
-
table = _a;
|
|
1523
|
-
clonedTable = table.clone();
|
|
1524
|
-
up = this.createPrimaryKeySql(table, columnNames);
|
|
1525
|
-
// mark columns as primary, because dropPrimaryKeySql build constraint name from table primary column names.
|
|
1526
|
-
clonedTable.columns.forEach(function (column) {
|
|
1527
|
-
if (columnNames.find(function (columnName) { return columnName === column.name; }))
|
|
1528
|
-
column.isPrimary = true;
|
|
1529
|
-
});
|
|
1530
|
-
down = this.dropPrimaryKeySql(clonedTable);
|
|
1531
|
-
return [4 /*yield*/, this.executeQueries(up, down)];
|
|
1532
|
-
case 4:
|
|
1533
|
-
_b.sent();
|
|
1534
|
-
this.replaceCachedTable(table, clonedTable);
|
|
1535
|
-
return [2 /*return*/];
|
|
1536
|
-
}
|
|
1537
|
-
});
|
|
1006
|
+
async createPrimaryKey(tableOrName, columnNames) {
|
|
1007
|
+
const table = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
|
|
1008
|
+
? tableOrName
|
|
1009
|
+
: await this.getCachedTable(tableOrName);
|
|
1010
|
+
const clonedTable = table.clone();
|
|
1011
|
+
const up = this.createPrimaryKeySql(table, columnNames);
|
|
1012
|
+
// mark columns as primary, because dropPrimaryKeySql build constraint name from table primary column names.
|
|
1013
|
+
clonedTable.columns.forEach((column) => {
|
|
1014
|
+
if (columnNames.find((columnName) => columnName === column.name))
|
|
1015
|
+
column.isPrimary = true;
|
|
1538
1016
|
});
|
|
1539
|
-
|
|
1017
|
+
const down = this.dropPrimaryKeySql(clonedTable);
|
|
1018
|
+
await this.executeQueries(up, down);
|
|
1019
|
+
this.replaceCachedTable(table, clonedTable);
|
|
1020
|
+
}
|
|
1540
1021
|
/**
|
|
1541
1022
|
* Updates composite primary keys.
|
|
1542
1023
|
*/
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
referencedDatabase: table.database,
|
|
1591
|
-
referencedSchema: table.schema,
|
|
1592
|
-
referencedTableName: table.name,
|
|
1593
|
-
referencedColumnNames: foreignKeys.map(function (dbFk) { return dbFk["REFERENCED_COLUMN_NAME"]; }),
|
|
1594
|
-
onDelete: dbForeignKey["DELETE_RULE"] === "RESTRICT"
|
|
1595
|
-
? "NO ACTION"
|
|
1596
|
-
: dbForeignKey["DELETE_RULE"],
|
|
1597
|
-
onUpdate: dbForeignKey["UPDATE_RULE"] === "RESTRICT"
|
|
1598
|
-
? "NO ACTION"
|
|
1599
|
-
: dbForeignKey["UPDATE_RULE"],
|
|
1600
|
-
deferrable: dbForeignKey["CHECK_TIME"].replace("_", " "),
|
|
1601
|
-
});
|
|
1602
|
-
});
|
|
1603
|
-
// drop referenced foreign keys
|
|
1604
|
-
referencedForeignKeys.forEach(function (foreignKey) {
|
|
1605
|
-
var mapping = referencedForeignKeyTableMapping.find(function (it) { return it.fkName === foreignKey.name; });
|
|
1606
|
-
upQueries.push(_this.dropForeignKeySql(mapping.tableName, foreignKey));
|
|
1607
|
-
downQueries.push(_this.createForeignKeySql(mapping.tableName, foreignKey));
|
|
1608
|
-
});
|
|
1609
|
-
}
|
|
1610
|
-
primaryColumns = clonedTable.primaryColumns;
|
|
1611
|
-
if (primaryColumns.length > 0) {
|
|
1612
|
-
pkName_3 = this.connection.namingStrategy.primaryKeyName(clonedTable, primaryColumns.map(function (column) { return column.name; }));
|
|
1613
|
-
columnNamesString_1 = primaryColumns
|
|
1614
|
-
.map(function (column) { return "\"".concat(column.name, "\""); })
|
|
1615
|
-
.join(", ");
|
|
1616
|
-
upQueries.push(new Query_1.Query("ALTER TABLE ".concat(this.escapePath(table), " DROP CONSTRAINT \"").concat(pkName_3, "\"")));
|
|
1617
|
-
downQueries.push(new Query_1.Query("ALTER TABLE ".concat(this.escapePath(table), " ADD CONSTRAINT \"").concat(pkName_3, "\" PRIMARY KEY (").concat(columnNamesString_1, ")")));
|
|
1618
|
-
}
|
|
1619
|
-
// update columns in table.
|
|
1620
|
-
clonedTable.columns
|
|
1621
|
-
.filter(function (column) { return columnNames.indexOf(column.name) !== -1; })
|
|
1622
|
-
.forEach(function (column) { return (column.isPrimary = true); });
|
|
1623
|
-
pkName = this.connection.namingStrategy.primaryKeyName(clonedTable, columnNames);
|
|
1624
|
-
columnNamesString = columnNames
|
|
1625
|
-
.map(function (columnName) { return "\"".concat(columnName, "\""); })
|
|
1626
|
-
.join(", ");
|
|
1627
|
-
upQueries.push(new Query_1.Query("ALTER TABLE ".concat(this.escapePath(table), " ADD CONSTRAINT \"").concat(pkName, "\" PRIMARY KEY (").concat(columnNamesString, ")")));
|
|
1628
|
-
downQueries.push(new Query_1.Query("ALTER TABLE ".concat(this.escapePath(table), " DROP CONSTRAINT \"").concat(pkName, "\"")));
|
|
1629
|
-
// restore referenced foreign keys
|
|
1630
|
-
referencedForeignKeys.forEach(function (foreignKey) {
|
|
1631
|
-
var mapping = referencedForeignKeyTableMapping.find(function (it) { return it.fkName === foreignKey.name; });
|
|
1632
|
-
upQueries.push(_this.createForeignKeySql(mapping.tableName, foreignKey));
|
|
1633
|
-
downQueries.push(_this.dropForeignKeySql(mapping.tableName, foreignKey));
|
|
1634
|
-
});
|
|
1635
|
-
return [4 /*yield*/, this.executeQueries(upQueries, downQueries)];
|
|
1636
|
-
case 7:
|
|
1637
|
-
_c.sent();
|
|
1638
|
-
this.replaceCachedTable(table, clonedTable);
|
|
1639
|
-
return [2 /*return*/];
|
|
1640
|
-
}
|
|
1024
|
+
async updatePrimaryKeys(tableOrName, columns) {
|
|
1025
|
+
const table = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
|
|
1026
|
+
? tableOrName
|
|
1027
|
+
: await this.getCachedTable(tableOrName);
|
|
1028
|
+
const parsedTableName = this.driver.parseTableName(table);
|
|
1029
|
+
if (!parsedTableName.schema) {
|
|
1030
|
+
parsedTableName.schema = await this.getCurrentSchema();
|
|
1031
|
+
}
|
|
1032
|
+
const clonedTable = table.clone();
|
|
1033
|
+
const columnNames = columns.map((column) => column.name);
|
|
1034
|
+
const upQueries = [];
|
|
1035
|
+
const downQueries = [];
|
|
1036
|
+
// SAP HANA does not allow to drop PK's which is referenced by foreign keys.
|
|
1037
|
+
// To avoid this, we must drop all referential foreign keys and recreate them later
|
|
1038
|
+
const referencedForeignKeySql = `SELECT * FROM "SYS"."REFERENTIAL_CONSTRAINTS" WHERE "REFERENCED_SCHEMA_NAME" = '${parsedTableName.schema}' AND "REFERENCED_TABLE_NAME" = '${parsedTableName.tableName}'`;
|
|
1039
|
+
const dbForeignKeys = await this.query(referencedForeignKeySql);
|
|
1040
|
+
let referencedForeignKeys = [];
|
|
1041
|
+
const referencedForeignKeyTableMapping = [];
|
|
1042
|
+
if (dbForeignKeys.length > 0) {
|
|
1043
|
+
referencedForeignKeys = dbForeignKeys.map((dbForeignKey) => {
|
|
1044
|
+
const foreignKeys = dbForeignKeys.filter((dbFk) => dbFk["CONSTRAINT_NAME"] ===
|
|
1045
|
+
dbForeignKey["CONSTRAINT_NAME"]);
|
|
1046
|
+
referencedForeignKeyTableMapping.push({
|
|
1047
|
+
tableName: `${dbForeignKey["SCHEMA_NAME"]}.${dbForeignKey["TABLE_NAME"]}`,
|
|
1048
|
+
fkName: dbForeignKey["CONSTRAINT_NAME"],
|
|
1049
|
+
});
|
|
1050
|
+
return new TableForeignKey_1.TableForeignKey({
|
|
1051
|
+
name: dbForeignKey["CONSTRAINT_NAME"],
|
|
1052
|
+
columnNames: foreignKeys.map((dbFk) => dbFk["COLUMN_NAME"]),
|
|
1053
|
+
referencedDatabase: table.database,
|
|
1054
|
+
referencedSchema: table.schema,
|
|
1055
|
+
referencedTableName: table.name,
|
|
1056
|
+
referencedColumnNames: foreignKeys.map((dbFk) => dbFk["REFERENCED_COLUMN_NAME"]),
|
|
1057
|
+
onDelete: dbForeignKey["DELETE_RULE"] === "RESTRICT"
|
|
1058
|
+
? "NO ACTION"
|
|
1059
|
+
: dbForeignKey["DELETE_RULE"],
|
|
1060
|
+
onUpdate: dbForeignKey["UPDATE_RULE"] === "RESTRICT"
|
|
1061
|
+
? "NO ACTION"
|
|
1062
|
+
: dbForeignKey["UPDATE_RULE"],
|
|
1063
|
+
deferrable: dbForeignKey["CHECK_TIME"].replace("_", " "),
|
|
1064
|
+
});
|
|
1065
|
+
});
|
|
1066
|
+
// drop referenced foreign keys
|
|
1067
|
+
referencedForeignKeys.forEach((foreignKey) => {
|
|
1068
|
+
const mapping = referencedForeignKeyTableMapping.find((it) => it.fkName === foreignKey.name);
|
|
1069
|
+
upQueries.push(this.dropForeignKeySql(mapping.tableName, foreignKey));
|
|
1070
|
+
downQueries.push(this.createForeignKeySql(mapping.tableName, foreignKey));
|
|
1641
1071
|
});
|
|
1072
|
+
}
|
|
1073
|
+
// if table already have primary columns, we must drop them.
|
|
1074
|
+
const primaryColumns = clonedTable.primaryColumns;
|
|
1075
|
+
if (primaryColumns.length > 0) {
|
|
1076
|
+
const pkName = this.connection.namingStrategy.primaryKeyName(clonedTable, primaryColumns.map((column) => column.name));
|
|
1077
|
+
const columnNamesString = primaryColumns
|
|
1078
|
+
.map((column) => `"${column.name}"`)
|
|
1079
|
+
.join(", ");
|
|
1080
|
+
upQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} DROP CONSTRAINT "${pkName}"`));
|
|
1081
|
+
downQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} ADD CONSTRAINT "${pkName}" PRIMARY KEY (${columnNamesString})`));
|
|
1082
|
+
}
|
|
1083
|
+
// update columns in table.
|
|
1084
|
+
clonedTable.columns
|
|
1085
|
+
.filter((column) => columnNames.indexOf(column.name) !== -1)
|
|
1086
|
+
.forEach((column) => (column.isPrimary = true));
|
|
1087
|
+
const pkName = this.connection.namingStrategy.primaryKeyName(clonedTable, columnNames);
|
|
1088
|
+
const columnNamesString = columnNames
|
|
1089
|
+
.map((columnName) => `"${columnName}"`)
|
|
1090
|
+
.join(", ");
|
|
1091
|
+
upQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} ADD CONSTRAINT "${pkName}" PRIMARY KEY (${columnNamesString})`));
|
|
1092
|
+
downQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} DROP CONSTRAINT "${pkName}"`));
|
|
1093
|
+
// restore referenced foreign keys
|
|
1094
|
+
referencedForeignKeys.forEach((foreignKey) => {
|
|
1095
|
+
const mapping = referencedForeignKeyTableMapping.find((it) => it.fkName === foreignKey.name);
|
|
1096
|
+
upQueries.push(this.createForeignKeySql(mapping.tableName, foreignKey));
|
|
1097
|
+
downQueries.push(this.dropForeignKeySql(mapping.tableName, foreignKey));
|
|
1642
1098
|
});
|
|
1643
|
-
|
|
1099
|
+
await this.executeQueries(upQueries, downQueries);
|
|
1100
|
+
this.replaceCachedTable(table, clonedTable);
|
|
1101
|
+
}
|
|
1644
1102
|
/**
|
|
1645
1103
|
* Drops a primary key.
|
|
1646
1104
|
*/
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
tableName: "".concat(dbForeignKey["SCHEMA_NAME"], ".").concat(dbForeignKey["TABLE_NAME"]),
|
|
1687
|
-
fkName: dbForeignKey["CONSTRAINT_NAME"],
|
|
1688
|
-
});
|
|
1689
|
-
return new TableForeignKey_1.TableForeignKey({
|
|
1690
|
-
name: dbForeignKey["CONSTRAINT_NAME"],
|
|
1691
|
-
columnNames: foreignKeys.map(function (dbFk) { return dbFk["COLUMN_NAME"]; }),
|
|
1692
|
-
referencedDatabase: table.database,
|
|
1693
|
-
referencedSchema: table.schema,
|
|
1694
|
-
referencedTableName: table.name,
|
|
1695
|
-
referencedColumnNames: foreignKeys.map(function (dbFk) { return dbFk["REFERENCED_COLUMN_NAME"]; }),
|
|
1696
|
-
onDelete: dbForeignKey["DELETE_RULE"] === "RESTRICT"
|
|
1697
|
-
? "NO ACTION"
|
|
1698
|
-
: dbForeignKey["DELETE_RULE"],
|
|
1699
|
-
onUpdate: dbForeignKey["UPDATE_RULE"] === "RESTRICT"
|
|
1700
|
-
? "NO ACTION"
|
|
1701
|
-
: dbForeignKey["UPDATE_RULE"],
|
|
1702
|
-
deferrable: dbForeignKey["CHECK_TIME"].replace("_", " "),
|
|
1703
|
-
});
|
|
1704
|
-
});
|
|
1705
|
-
// drop referenced foreign keys
|
|
1706
|
-
referencedForeignKeys.forEach(function (foreignKey) {
|
|
1707
|
-
var mapping = referencedForeignKeyTableMapping.find(function (it) { return it.fkName === foreignKey.name; });
|
|
1708
|
-
upQueries.push(_this.dropForeignKeySql(mapping.tableName, foreignKey));
|
|
1709
|
-
downQueries.push(_this.createForeignKeySql(mapping.tableName, foreignKey));
|
|
1710
|
-
});
|
|
1711
|
-
}
|
|
1712
|
-
upQueries.push(this.dropPrimaryKeySql(table));
|
|
1713
|
-
downQueries.push(this.createPrimaryKeySql(table, table.primaryColumns.map(function (column) { return column.name; })));
|
|
1714
|
-
// restore referenced foreign keys
|
|
1715
|
-
referencedForeignKeys.forEach(function (foreignKey) {
|
|
1716
|
-
var mapping = referencedForeignKeyTableMapping.find(function (it) { return it.fkName === foreignKey.name; });
|
|
1717
|
-
upQueries.push(_this.createForeignKeySql(mapping.tableName, foreignKey));
|
|
1718
|
-
downQueries.push(_this.dropForeignKeySql(mapping.tableName, foreignKey));
|
|
1719
|
-
});
|
|
1720
|
-
return [4 /*yield*/, this.executeQueries(upQueries, downQueries)];
|
|
1721
|
-
case 7:
|
|
1722
|
-
_c.sent();
|
|
1723
|
-
table.primaryColumns.forEach(function (column) {
|
|
1724
|
-
column.isPrimary = false;
|
|
1725
|
-
});
|
|
1726
|
-
return [2 /*return*/];
|
|
1727
|
-
}
|
|
1105
|
+
async dropPrimaryKey(tableOrName) {
|
|
1106
|
+
const table = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
|
|
1107
|
+
? tableOrName
|
|
1108
|
+
: await this.getCachedTable(tableOrName);
|
|
1109
|
+
const parsedTableName = this.driver.parseTableName(table);
|
|
1110
|
+
if (!parsedTableName.schema) {
|
|
1111
|
+
parsedTableName.schema = await this.getCurrentSchema();
|
|
1112
|
+
}
|
|
1113
|
+
const upQueries = [];
|
|
1114
|
+
const downQueries = [];
|
|
1115
|
+
// SAP HANA does not allow to drop PK's which is referenced by foreign keys.
|
|
1116
|
+
// To avoid this, we must drop all referential foreign keys and recreate them later
|
|
1117
|
+
const referencedForeignKeySql = `SELECT * FROM "SYS"."REFERENTIAL_CONSTRAINTS" WHERE "REFERENCED_SCHEMA_NAME" = '${parsedTableName.schema}' AND "REFERENCED_TABLE_NAME" = '${parsedTableName.tableName}'`;
|
|
1118
|
+
const dbForeignKeys = await this.query(referencedForeignKeySql);
|
|
1119
|
+
let referencedForeignKeys = [];
|
|
1120
|
+
const referencedForeignKeyTableMapping = [];
|
|
1121
|
+
if (dbForeignKeys.length > 0) {
|
|
1122
|
+
referencedForeignKeys = dbForeignKeys.map((dbForeignKey) => {
|
|
1123
|
+
const foreignKeys = dbForeignKeys.filter((dbFk) => dbFk["CONSTRAINT_NAME"] ===
|
|
1124
|
+
dbForeignKey["CONSTRAINT_NAME"]);
|
|
1125
|
+
referencedForeignKeyTableMapping.push({
|
|
1126
|
+
tableName: `${dbForeignKey["SCHEMA_NAME"]}.${dbForeignKey["TABLE_NAME"]}`,
|
|
1127
|
+
fkName: dbForeignKey["CONSTRAINT_NAME"],
|
|
1128
|
+
});
|
|
1129
|
+
return new TableForeignKey_1.TableForeignKey({
|
|
1130
|
+
name: dbForeignKey["CONSTRAINT_NAME"],
|
|
1131
|
+
columnNames: foreignKeys.map((dbFk) => dbFk["COLUMN_NAME"]),
|
|
1132
|
+
referencedDatabase: table.database,
|
|
1133
|
+
referencedSchema: table.schema,
|
|
1134
|
+
referencedTableName: table.name,
|
|
1135
|
+
referencedColumnNames: foreignKeys.map((dbFk) => dbFk["REFERENCED_COLUMN_NAME"]),
|
|
1136
|
+
onDelete: dbForeignKey["DELETE_RULE"] === "RESTRICT"
|
|
1137
|
+
? "NO ACTION"
|
|
1138
|
+
: dbForeignKey["DELETE_RULE"],
|
|
1139
|
+
onUpdate: dbForeignKey["UPDATE_RULE"] === "RESTRICT"
|
|
1140
|
+
? "NO ACTION"
|
|
1141
|
+
: dbForeignKey["UPDATE_RULE"],
|
|
1142
|
+
deferrable: dbForeignKey["CHECK_TIME"].replace("_", " "),
|
|
1143
|
+
});
|
|
1728
1144
|
});
|
|
1145
|
+
// drop referenced foreign keys
|
|
1146
|
+
referencedForeignKeys.forEach((foreignKey) => {
|
|
1147
|
+
const mapping = referencedForeignKeyTableMapping.find((it) => it.fkName === foreignKey.name);
|
|
1148
|
+
upQueries.push(this.dropForeignKeySql(mapping.tableName, foreignKey));
|
|
1149
|
+
downQueries.push(this.createForeignKeySql(mapping.tableName, foreignKey));
|
|
1150
|
+
});
|
|
1151
|
+
}
|
|
1152
|
+
upQueries.push(this.dropPrimaryKeySql(table));
|
|
1153
|
+
downQueries.push(this.createPrimaryKeySql(table, table.primaryColumns.map((column) => column.name)));
|
|
1154
|
+
// restore referenced foreign keys
|
|
1155
|
+
referencedForeignKeys.forEach((foreignKey) => {
|
|
1156
|
+
const mapping = referencedForeignKeyTableMapping.find((it) => it.fkName === foreignKey.name);
|
|
1157
|
+
upQueries.push(this.createForeignKeySql(mapping.tableName, foreignKey));
|
|
1158
|
+
downQueries.push(this.dropForeignKeySql(mapping.tableName, foreignKey));
|
|
1159
|
+
});
|
|
1160
|
+
await this.executeQueries(upQueries, downQueries);
|
|
1161
|
+
table.primaryColumns.forEach((column) => {
|
|
1162
|
+
column.isPrimary = false;
|
|
1729
1163
|
});
|
|
1730
|
-
}
|
|
1164
|
+
}
|
|
1731
1165
|
/**
|
|
1732
1166
|
* Creates a new unique constraint.
|
|
1733
1167
|
*/
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
throw new error_1.TypeORMError("SAP HANA does not support unique constraints. Use unique index instead.");
|
|
1738
|
-
});
|
|
1739
|
-
});
|
|
1740
|
-
};
|
|
1168
|
+
async createUniqueConstraint(tableOrName, uniqueConstraint) {
|
|
1169
|
+
throw new error_1.TypeORMError(`SAP HANA does not support unique constraints. Use unique index instead.`);
|
|
1170
|
+
}
|
|
1741
1171
|
/**
|
|
1742
1172
|
* Creates a new unique constraints.
|
|
1743
1173
|
*/
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
throw new error_1.TypeORMError("SAP HANA does not support unique constraints. Use unique index instead.");
|
|
1748
|
-
});
|
|
1749
|
-
});
|
|
1750
|
-
};
|
|
1174
|
+
async createUniqueConstraints(tableOrName, uniqueConstraints) {
|
|
1175
|
+
throw new error_1.TypeORMError(`SAP HANA does not support unique constraints. Use unique index instead.`);
|
|
1176
|
+
}
|
|
1751
1177
|
/**
|
|
1752
1178
|
* Drops unique constraint.
|
|
1753
1179
|
*/
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
throw new error_1.TypeORMError("SAP HANA does not support unique constraints. Use unique index instead.");
|
|
1758
|
-
});
|
|
1759
|
-
});
|
|
1760
|
-
};
|
|
1180
|
+
async dropUniqueConstraint(tableOrName, uniqueOrName) {
|
|
1181
|
+
throw new error_1.TypeORMError(`SAP HANA does not support unique constraints. Use unique index instead.`);
|
|
1182
|
+
}
|
|
1761
1183
|
/**
|
|
1762
1184
|
* Drops an unique constraints.
|
|
1763
1185
|
*/
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
throw new error_1.TypeORMError("SAP HANA does not support unique constraints. Use unique index instead.");
|
|
1768
|
-
});
|
|
1769
|
-
});
|
|
1770
|
-
};
|
|
1186
|
+
async dropUniqueConstraints(tableOrName, uniqueConstraints) {
|
|
1187
|
+
throw new error_1.TypeORMError(`SAP HANA does not support unique constraints. Use unique index instead.`);
|
|
1188
|
+
}
|
|
1771
1189
|
/**
|
|
1772
1190
|
* Creates a new check constraint.
|
|
1773
1191
|
*/
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
_a = _b.sent();
|
|
1788
|
-
_b.label = 3;
|
|
1789
|
-
case 3:
|
|
1790
|
-
table = _a;
|
|
1791
|
-
// new unique constraint may be passed without name. In this case we generate unique name manually.
|
|
1792
|
-
if (!checkConstraint.name)
|
|
1793
|
-
checkConstraint.name =
|
|
1794
|
-
this.connection.namingStrategy.checkConstraintName(table, checkConstraint.expression);
|
|
1795
|
-
up = this.createCheckConstraintSql(table, checkConstraint);
|
|
1796
|
-
down = this.dropCheckConstraintSql(table, checkConstraint);
|
|
1797
|
-
return [4 /*yield*/, this.executeQueries(up, down)];
|
|
1798
|
-
case 4:
|
|
1799
|
-
_b.sent();
|
|
1800
|
-
table.addCheckConstraint(checkConstraint);
|
|
1801
|
-
return [2 /*return*/];
|
|
1802
|
-
}
|
|
1803
|
-
});
|
|
1804
|
-
});
|
|
1805
|
-
};
|
|
1192
|
+
async createCheckConstraint(tableOrName, checkConstraint) {
|
|
1193
|
+
const table = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
|
|
1194
|
+
? tableOrName
|
|
1195
|
+
: await this.getCachedTable(tableOrName);
|
|
1196
|
+
// new unique constraint may be passed without name. In this case we generate unique name manually.
|
|
1197
|
+
if (!checkConstraint.name)
|
|
1198
|
+
checkConstraint.name =
|
|
1199
|
+
this.connection.namingStrategy.checkConstraintName(table, checkConstraint.expression);
|
|
1200
|
+
const up = this.createCheckConstraintSql(table, checkConstraint);
|
|
1201
|
+
const down = this.dropCheckConstraintSql(table, checkConstraint);
|
|
1202
|
+
await this.executeQueries(up, down);
|
|
1203
|
+
table.addCheckConstraint(checkConstraint);
|
|
1204
|
+
}
|
|
1806
1205
|
/**
|
|
1807
1206
|
* Creates a new check constraints.
|
|
1808
1207
|
*/
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
return tslib_1.__generator(this, function (_a) {
|
|
1814
|
-
switch (_a.label) {
|
|
1815
|
-
case 0:
|
|
1816
|
-
promises = checkConstraints.map(function (checkConstraint) {
|
|
1817
|
-
return _this.createCheckConstraint(tableOrName, checkConstraint);
|
|
1818
|
-
});
|
|
1819
|
-
return [4 /*yield*/, Promise.all(promises)];
|
|
1820
|
-
case 1:
|
|
1821
|
-
_a.sent();
|
|
1822
|
-
return [2 /*return*/];
|
|
1823
|
-
}
|
|
1824
|
-
});
|
|
1825
|
-
});
|
|
1826
|
-
};
|
|
1208
|
+
async createCheckConstraints(tableOrName, checkConstraints) {
|
|
1209
|
+
const promises = checkConstraints.map((checkConstraint) => this.createCheckConstraint(tableOrName, checkConstraint));
|
|
1210
|
+
await Promise.all(promises);
|
|
1211
|
+
}
|
|
1827
1212
|
/**
|
|
1828
1213
|
* Drops check constraint.
|
|
1829
1214
|
*/
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
table = _a;
|
|
1845
|
-
checkConstraint = InstanceChecker_1.InstanceChecker.isTableCheck(checkOrName)
|
|
1846
|
-
? checkOrName
|
|
1847
|
-
: table.checks.find(function (c) { return c.name === checkOrName; });
|
|
1848
|
-
if (!checkConstraint)
|
|
1849
|
-
throw new error_1.TypeORMError("Supplied check constraint was not found in table ".concat(table.name));
|
|
1850
|
-
up = this.dropCheckConstraintSql(table, checkConstraint);
|
|
1851
|
-
down = this.createCheckConstraintSql(table, checkConstraint);
|
|
1852
|
-
return [4 /*yield*/, this.executeQueries(up, down)];
|
|
1853
|
-
case 4:
|
|
1854
|
-
_b.sent();
|
|
1855
|
-
table.removeCheckConstraint(checkConstraint);
|
|
1856
|
-
return [2 /*return*/];
|
|
1857
|
-
}
|
|
1858
|
-
});
|
|
1859
|
-
});
|
|
1860
|
-
};
|
|
1215
|
+
async dropCheckConstraint(tableOrName, checkOrName) {
|
|
1216
|
+
const table = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
|
|
1217
|
+
? tableOrName
|
|
1218
|
+
: await this.getCachedTable(tableOrName);
|
|
1219
|
+
const checkConstraint = InstanceChecker_1.InstanceChecker.isTableCheck(checkOrName)
|
|
1220
|
+
? checkOrName
|
|
1221
|
+
: table.checks.find((c) => c.name === checkOrName);
|
|
1222
|
+
if (!checkConstraint)
|
|
1223
|
+
throw new error_1.TypeORMError(`Supplied check constraint was not found in table ${table.name}`);
|
|
1224
|
+
const up = this.dropCheckConstraintSql(table, checkConstraint);
|
|
1225
|
+
const down = this.createCheckConstraintSql(table, checkConstraint);
|
|
1226
|
+
await this.executeQueries(up, down);
|
|
1227
|
+
table.removeCheckConstraint(checkConstraint);
|
|
1228
|
+
}
|
|
1861
1229
|
/**
|
|
1862
1230
|
* Drops check constraints.
|
|
1863
1231
|
*/
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
return tslib_1.__generator(this, function (_a) {
|
|
1869
|
-
switch (_a.label) {
|
|
1870
|
-
case 0:
|
|
1871
|
-
promises = checkConstraints.map(function (checkConstraint) {
|
|
1872
|
-
return _this.dropCheckConstraint(tableOrName, checkConstraint);
|
|
1873
|
-
});
|
|
1874
|
-
return [4 /*yield*/, Promise.all(promises)];
|
|
1875
|
-
case 1:
|
|
1876
|
-
_a.sent();
|
|
1877
|
-
return [2 /*return*/];
|
|
1878
|
-
}
|
|
1879
|
-
});
|
|
1880
|
-
});
|
|
1881
|
-
};
|
|
1232
|
+
async dropCheckConstraints(tableOrName, checkConstraints) {
|
|
1233
|
+
const promises = checkConstraints.map((checkConstraint) => this.dropCheckConstraint(tableOrName, checkConstraint));
|
|
1234
|
+
await Promise.all(promises);
|
|
1235
|
+
}
|
|
1882
1236
|
/**
|
|
1883
1237
|
* Creates a new exclusion constraint.
|
|
1884
1238
|
*/
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
throw new error_1.TypeORMError("SAP HANA does not support exclusion constraints.");
|
|
1889
|
-
});
|
|
1890
|
-
});
|
|
1891
|
-
};
|
|
1239
|
+
async createExclusionConstraint(tableOrName, exclusionConstraint) {
|
|
1240
|
+
throw new error_1.TypeORMError(`SAP HANA does not support exclusion constraints.`);
|
|
1241
|
+
}
|
|
1892
1242
|
/**
|
|
1893
1243
|
* Creates a new exclusion constraints.
|
|
1894
1244
|
*/
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
throw new error_1.TypeORMError("SAP HANA does not support exclusion constraints.");
|
|
1899
|
-
});
|
|
1900
|
-
});
|
|
1901
|
-
};
|
|
1245
|
+
async createExclusionConstraints(tableOrName, exclusionConstraints) {
|
|
1246
|
+
throw new error_1.TypeORMError(`SAP HANA does not support exclusion constraints.`);
|
|
1247
|
+
}
|
|
1902
1248
|
/**
|
|
1903
1249
|
* Drops exclusion constraint.
|
|
1904
1250
|
*/
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
throw new error_1.TypeORMError("SAP HANA does not support exclusion constraints.");
|
|
1909
|
-
});
|
|
1910
|
-
});
|
|
1911
|
-
};
|
|
1251
|
+
async dropExclusionConstraint(tableOrName, exclusionOrName) {
|
|
1252
|
+
throw new error_1.TypeORMError(`SAP HANA does not support exclusion constraints.`);
|
|
1253
|
+
}
|
|
1912
1254
|
/**
|
|
1913
1255
|
* Drops exclusion constraints.
|
|
1914
1256
|
*/
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
throw new error_1.TypeORMError("SAP HANA does not support exclusion constraints.");
|
|
1919
|
-
});
|
|
1920
|
-
});
|
|
1921
|
-
};
|
|
1257
|
+
async dropExclusionConstraints(tableOrName, exclusionConstraints) {
|
|
1258
|
+
throw new error_1.TypeORMError(`SAP HANA does not support exclusion constraints.`);
|
|
1259
|
+
}
|
|
1922
1260
|
/**
|
|
1923
1261
|
* Creates a new foreign key.
|
|
1924
1262
|
*/
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
case 2:
|
|
1938
|
-
_a = _b.sent();
|
|
1939
|
-
_b.label = 3;
|
|
1940
|
-
case 3:
|
|
1941
|
-
table = _a;
|
|
1942
|
-
// new FK may be passed without name. In this case we generate FK name manually.
|
|
1943
|
-
if (!foreignKey.name)
|
|
1944
|
-
foreignKey.name = this.connection.namingStrategy.foreignKeyName(table, foreignKey.columnNames, this.getTablePath(foreignKey), foreignKey.referencedColumnNames);
|
|
1945
|
-
up = this.createForeignKeySql(table, foreignKey);
|
|
1946
|
-
down = this.dropForeignKeySql(table, foreignKey);
|
|
1947
|
-
return [4 /*yield*/, this.executeQueries(up, down)];
|
|
1948
|
-
case 4:
|
|
1949
|
-
_b.sent();
|
|
1950
|
-
table.addForeignKey(foreignKey);
|
|
1951
|
-
return [2 /*return*/];
|
|
1952
|
-
}
|
|
1953
|
-
});
|
|
1954
|
-
});
|
|
1955
|
-
};
|
|
1263
|
+
async createForeignKey(tableOrName, foreignKey) {
|
|
1264
|
+
const table = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
|
|
1265
|
+
? tableOrName
|
|
1266
|
+
: await this.getCachedTable(tableOrName);
|
|
1267
|
+
// new FK may be passed without name. In this case we generate FK name manually.
|
|
1268
|
+
if (!foreignKey.name)
|
|
1269
|
+
foreignKey.name = this.connection.namingStrategy.foreignKeyName(table, foreignKey.columnNames, this.getTablePath(foreignKey), foreignKey.referencedColumnNames);
|
|
1270
|
+
const up = this.createForeignKeySql(table, foreignKey);
|
|
1271
|
+
const down = this.dropForeignKeySql(table, foreignKey);
|
|
1272
|
+
await this.executeQueries(up, down);
|
|
1273
|
+
table.addForeignKey(foreignKey);
|
|
1274
|
+
}
|
|
1956
1275
|
/**
|
|
1957
1276
|
* Creates a new foreign keys.
|
|
1958
1277
|
*/
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
return tslib_1.__generator(this, function (_a) {
|
|
1964
|
-
switch (_a.label) {
|
|
1965
|
-
case 0:
|
|
1966
|
-
promises = foreignKeys.map(function (foreignKey) {
|
|
1967
|
-
return _this.createForeignKey(tableOrName, foreignKey);
|
|
1968
|
-
});
|
|
1969
|
-
return [4 /*yield*/, Promise.all(promises)];
|
|
1970
|
-
case 1:
|
|
1971
|
-
_a.sent();
|
|
1972
|
-
return [2 /*return*/];
|
|
1973
|
-
}
|
|
1974
|
-
});
|
|
1975
|
-
});
|
|
1976
|
-
};
|
|
1278
|
+
async createForeignKeys(tableOrName, foreignKeys) {
|
|
1279
|
+
const promises = foreignKeys.map((foreignKey) => this.createForeignKey(tableOrName, foreignKey));
|
|
1280
|
+
await Promise.all(promises);
|
|
1281
|
+
}
|
|
1977
1282
|
/**
|
|
1978
1283
|
* Drops a foreign key from the table.
|
|
1979
1284
|
*/
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
table = _a;
|
|
1995
|
-
foreignKey = InstanceChecker_1.InstanceChecker.isTableForeignKey(foreignKeyOrName)
|
|
1996
|
-
? foreignKeyOrName
|
|
1997
|
-
: table.foreignKeys.find(function (fk) { return fk.name === foreignKeyOrName; });
|
|
1998
|
-
if (!foreignKey)
|
|
1999
|
-
throw new error_1.TypeORMError("Supplied foreign key was not found in table ".concat(table.name));
|
|
2000
|
-
up = this.dropForeignKeySql(table, foreignKey);
|
|
2001
|
-
down = this.createForeignKeySql(table, foreignKey);
|
|
2002
|
-
return [4 /*yield*/, this.executeQueries(up, down)];
|
|
2003
|
-
case 4:
|
|
2004
|
-
_b.sent();
|
|
2005
|
-
table.removeForeignKey(foreignKey);
|
|
2006
|
-
return [2 /*return*/];
|
|
2007
|
-
}
|
|
2008
|
-
});
|
|
2009
|
-
});
|
|
2010
|
-
};
|
|
1285
|
+
async dropForeignKey(tableOrName, foreignKeyOrName) {
|
|
1286
|
+
const table = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
|
|
1287
|
+
? tableOrName
|
|
1288
|
+
: await this.getCachedTable(tableOrName);
|
|
1289
|
+
const foreignKey = InstanceChecker_1.InstanceChecker.isTableForeignKey(foreignKeyOrName)
|
|
1290
|
+
? foreignKeyOrName
|
|
1291
|
+
: table.foreignKeys.find((fk) => fk.name === foreignKeyOrName);
|
|
1292
|
+
if (!foreignKey)
|
|
1293
|
+
throw new error_1.TypeORMError(`Supplied foreign key was not found in table ${table.name}`);
|
|
1294
|
+
const up = this.dropForeignKeySql(table, foreignKey);
|
|
1295
|
+
const down = this.createForeignKeySql(table, foreignKey);
|
|
1296
|
+
await this.executeQueries(up, down);
|
|
1297
|
+
table.removeForeignKey(foreignKey);
|
|
1298
|
+
}
|
|
2011
1299
|
/**
|
|
2012
1300
|
* Drops a foreign keys from the table.
|
|
2013
1301
|
*/
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
return tslib_1.__generator(this, function (_a) {
|
|
2019
|
-
switch (_a.label) {
|
|
2020
|
-
case 0:
|
|
2021
|
-
promises = foreignKeys.map(function (foreignKey) {
|
|
2022
|
-
return _this.dropForeignKey(tableOrName, foreignKey);
|
|
2023
|
-
});
|
|
2024
|
-
return [4 /*yield*/, Promise.all(promises)];
|
|
2025
|
-
case 1:
|
|
2026
|
-
_a.sent();
|
|
2027
|
-
return [2 /*return*/];
|
|
2028
|
-
}
|
|
2029
|
-
});
|
|
2030
|
-
});
|
|
2031
|
-
};
|
|
1302
|
+
async dropForeignKeys(tableOrName, foreignKeys) {
|
|
1303
|
+
const promises = foreignKeys.map((foreignKey) => this.dropForeignKey(tableOrName, foreignKey));
|
|
1304
|
+
await Promise.all(promises);
|
|
1305
|
+
}
|
|
2032
1306
|
/**
|
|
2033
1307
|
* Creates a new index.
|
|
2034
1308
|
*/
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
case 2:
|
|
2048
|
-
_a = _b.sent();
|
|
2049
|
-
_b.label = 3;
|
|
2050
|
-
case 3:
|
|
2051
|
-
table = _a;
|
|
2052
|
-
// new index may be passed without name. In this case we generate index name manually.
|
|
2053
|
-
if (!index.name)
|
|
2054
|
-
index.name = this.generateIndexName(table, index);
|
|
2055
|
-
up = this.createIndexSql(table, index);
|
|
2056
|
-
down = this.dropIndexSql(table, index);
|
|
2057
|
-
return [4 /*yield*/, this.executeQueries(up, down)];
|
|
2058
|
-
case 4:
|
|
2059
|
-
_b.sent();
|
|
2060
|
-
table.addIndex(index);
|
|
2061
|
-
return [2 /*return*/];
|
|
2062
|
-
}
|
|
2063
|
-
});
|
|
2064
|
-
});
|
|
2065
|
-
};
|
|
1309
|
+
async createIndex(tableOrName, index) {
|
|
1310
|
+
const table = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
|
|
1311
|
+
? tableOrName
|
|
1312
|
+
: await this.getCachedTable(tableOrName);
|
|
1313
|
+
// new index may be passed without name. In this case we generate index name manually.
|
|
1314
|
+
if (!index.name)
|
|
1315
|
+
index.name = this.generateIndexName(table, index);
|
|
1316
|
+
const up = this.createIndexSql(table, index);
|
|
1317
|
+
const down = this.dropIndexSql(table, index);
|
|
1318
|
+
await this.executeQueries(up, down);
|
|
1319
|
+
table.addIndex(index);
|
|
1320
|
+
}
|
|
2066
1321
|
/**
|
|
2067
1322
|
* Creates a new indices
|
|
2068
1323
|
*/
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
return tslib_1.__generator(this, function (_a) {
|
|
2074
|
-
switch (_a.label) {
|
|
2075
|
-
case 0:
|
|
2076
|
-
promises = indices.map(function (index) {
|
|
2077
|
-
return _this.createIndex(tableOrName, index);
|
|
2078
|
-
});
|
|
2079
|
-
return [4 /*yield*/, Promise.all(promises)];
|
|
2080
|
-
case 1:
|
|
2081
|
-
_a.sent();
|
|
2082
|
-
return [2 /*return*/];
|
|
2083
|
-
}
|
|
2084
|
-
});
|
|
2085
|
-
});
|
|
2086
|
-
};
|
|
1324
|
+
async createIndices(tableOrName, indices) {
|
|
1325
|
+
const promises = indices.map((index) => this.createIndex(tableOrName, index));
|
|
1326
|
+
await Promise.all(promises);
|
|
1327
|
+
}
|
|
2087
1328
|
/**
|
|
2088
1329
|
* Drops an index.
|
|
2089
1330
|
*/
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
: table.indices.find(function (i) { return i.name === indexOrName; });
|
|
2108
|
-
if (!index)
|
|
2109
|
-
throw new error_1.TypeORMError("Supplied index ".concat(indexOrName, " was not found in table ").concat(table.name));
|
|
2110
|
-
// old index may be passed without name. In this case we generate index name manually.
|
|
2111
|
-
if (!index.name)
|
|
2112
|
-
index.name = this.generateIndexName(table, index);
|
|
2113
|
-
up = this.dropIndexSql(table, index);
|
|
2114
|
-
down = this.createIndexSql(table, index);
|
|
2115
|
-
return [4 /*yield*/, this.executeQueries(up, down)];
|
|
2116
|
-
case 4:
|
|
2117
|
-
_b.sent();
|
|
2118
|
-
table.removeIndex(index);
|
|
2119
|
-
return [2 /*return*/];
|
|
2120
|
-
}
|
|
2121
|
-
});
|
|
2122
|
-
});
|
|
2123
|
-
};
|
|
1331
|
+
async dropIndex(tableOrName, indexOrName) {
|
|
1332
|
+
const table = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
|
|
1333
|
+
? tableOrName
|
|
1334
|
+
: await this.getCachedTable(tableOrName);
|
|
1335
|
+
const index = InstanceChecker_1.InstanceChecker.isTableIndex(indexOrName)
|
|
1336
|
+
? indexOrName
|
|
1337
|
+
: table.indices.find((i) => i.name === indexOrName);
|
|
1338
|
+
if (!index)
|
|
1339
|
+
throw new error_1.TypeORMError(`Supplied index ${indexOrName} was not found in table ${table.name}`);
|
|
1340
|
+
// old index may be passed without name. In this case we generate index name manually.
|
|
1341
|
+
if (!index.name)
|
|
1342
|
+
index.name = this.generateIndexName(table, index);
|
|
1343
|
+
const up = this.dropIndexSql(table, index);
|
|
1344
|
+
const down = this.createIndexSql(table, index);
|
|
1345
|
+
await this.executeQueries(up, down);
|
|
1346
|
+
table.removeIndex(index);
|
|
1347
|
+
}
|
|
2124
1348
|
/**
|
|
2125
1349
|
* Drops an indices from the table.
|
|
2126
1350
|
*/
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
return tslib_1.__generator(this, function (_a) {
|
|
2132
|
-
switch (_a.label) {
|
|
2133
|
-
case 0:
|
|
2134
|
-
promises = indices.map(function (index) {
|
|
2135
|
-
return _this.dropIndex(tableOrName, index);
|
|
2136
|
-
});
|
|
2137
|
-
return [4 /*yield*/, Promise.all(promises)];
|
|
2138
|
-
case 1:
|
|
2139
|
-
_a.sent();
|
|
2140
|
-
return [2 /*return*/];
|
|
2141
|
-
}
|
|
2142
|
-
});
|
|
2143
|
-
});
|
|
2144
|
-
};
|
|
1351
|
+
async dropIndices(tableOrName, indices) {
|
|
1352
|
+
const promises = indices.map((index) => this.dropIndex(tableOrName, index));
|
|
1353
|
+
await Promise.all(promises);
|
|
1354
|
+
}
|
|
2145
1355
|
/**
|
|
2146
1356
|
* Clears all table contents.
|
|
2147
1357
|
* Note: this operation uses SQL's TRUNCATE query which cannot be reverted in transactions.
|
|
2148
1358
|
*/
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
switch (_a.label) {
|
|
2153
|
-
case 0: return [4 /*yield*/, this.query("TRUNCATE TABLE ".concat(this.escapePath(tablePath)))];
|
|
2154
|
-
case 1:
|
|
2155
|
-
_a.sent();
|
|
2156
|
-
return [2 /*return*/];
|
|
2157
|
-
}
|
|
2158
|
-
});
|
|
2159
|
-
});
|
|
2160
|
-
};
|
|
1359
|
+
async clearTable(tablePath) {
|
|
1360
|
+
await this.query(`TRUNCATE TABLE ${this.escapePath(tablePath)}`);
|
|
1361
|
+
}
|
|
2161
1362
|
/**
|
|
2162
1363
|
* Removes all tables from the currently connected database.
|
|
2163
1364
|
*/
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
this.connection.entityMetadatas
|
|
2173
|
-
.filter(function (metadata) { return metadata.schema; })
|
|
2174
|
-
.forEach(function (metadata) {
|
|
2175
|
-
var isSchemaExist = !!schemas.find(function (schema) { return schema === metadata.schema; });
|
|
2176
|
-
if (!isSchemaExist)
|
|
2177
|
-
schemas.push(metadata.schema);
|
|
2178
|
-
});
|
|
2179
|
-
schemas.push(this.driver.options.schema || "current_schema");
|
|
2180
|
-
schemaNamesString = schemas
|
|
2181
|
-
.map(function (name) {
|
|
2182
|
-
return name === "current_schema" ? name : "'" + name + "'";
|
|
2183
|
-
})
|
|
2184
|
-
.join(", ");
|
|
2185
|
-
isAnotherTransactionActive = this.isTransactionActive;
|
|
2186
|
-
if (!!isAnotherTransactionActive) return [3 /*break*/, 2];
|
|
2187
|
-
return [4 /*yield*/, this.startTransaction()];
|
|
2188
|
-
case 1:
|
|
2189
|
-
_a.sent();
|
|
2190
|
-
_a.label = 2;
|
|
2191
|
-
case 2:
|
|
2192
|
-
_a.trys.push([2, 7, , 13]);
|
|
2193
|
-
selectTableDropsQuery = "SELECT 'DROP TABLE \"' || schema_name || '\".\"' || table_name || '\" CASCADE;' as \"query\" FROM \"SYS\".\"TABLES\" WHERE \"SCHEMA_NAME\" IN (".concat(schemaNamesString, ") AND \"TABLE_NAME\" NOT IN ('SYS_AFL_GENERATOR_PARAMETERS') AND \"IS_COLUMN_TABLE\" = 'TRUE'");
|
|
2194
|
-
return [4 /*yield*/, this.query(selectTableDropsQuery)];
|
|
2195
|
-
case 3:
|
|
2196
|
-
dropTableQueries = _a.sent();
|
|
2197
|
-
return [4 /*yield*/, Promise.all(dropTableQueries.map(function (q) { return _this.query(q["query"]); }))];
|
|
2198
|
-
case 4:
|
|
2199
|
-
_a.sent();
|
|
2200
|
-
if (!!isAnotherTransactionActive) return [3 /*break*/, 6];
|
|
2201
|
-
return [4 /*yield*/, this.commitTransaction()];
|
|
2202
|
-
case 5:
|
|
2203
|
-
_a.sent();
|
|
2204
|
-
_a.label = 6;
|
|
2205
|
-
case 6: return [3 /*break*/, 13];
|
|
2206
|
-
case 7:
|
|
2207
|
-
error_3 = _a.sent();
|
|
2208
|
-
_a.label = 8;
|
|
2209
|
-
case 8:
|
|
2210
|
-
_a.trys.push([8, 11, , 12]);
|
|
2211
|
-
if (!!isAnotherTransactionActive) return [3 /*break*/, 10];
|
|
2212
|
-
return [4 /*yield*/, this.rollbackTransaction()];
|
|
2213
|
-
case 9:
|
|
2214
|
-
_a.sent();
|
|
2215
|
-
_a.label = 10;
|
|
2216
|
-
case 10: return [3 /*break*/, 12];
|
|
2217
|
-
case 11:
|
|
2218
|
-
rollbackError_1 = _a.sent();
|
|
2219
|
-
return [3 /*break*/, 12];
|
|
2220
|
-
case 12: throw error_3;
|
|
2221
|
-
case 13: return [2 /*return*/];
|
|
2222
|
-
}
|
|
2223
|
-
});
|
|
1365
|
+
async clearDatabase() {
|
|
1366
|
+
const schemas = [];
|
|
1367
|
+
this.connection.entityMetadatas
|
|
1368
|
+
.filter((metadata) => metadata.schema)
|
|
1369
|
+
.forEach((metadata) => {
|
|
1370
|
+
const isSchemaExist = !!schemas.find((schema) => schema === metadata.schema);
|
|
1371
|
+
if (!isSchemaExist)
|
|
1372
|
+
schemas.push(metadata.schema);
|
|
2224
1373
|
});
|
|
2225
|
-
|
|
1374
|
+
schemas.push(this.driver.options.schema || "current_schema");
|
|
1375
|
+
const schemaNamesString = schemas
|
|
1376
|
+
.map((name) => {
|
|
1377
|
+
return name === "current_schema" ? name : "'" + name + "'";
|
|
1378
|
+
})
|
|
1379
|
+
.join(", ");
|
|
1380
|
+
const isAnotherTransactionActive = this.isTransactionActive;
|
|
1381
|
+
if (!isAnotherTransactionActive)
|
|
1382
|
+
await this.startTransaction();
|
|
1383
|
+
try {
|
|
1384
|
+
// const selectViewDropsQuery = `SELECT 'DROP VIEW IF EXISTS "' || schemaname || '"."' || viewname || '" CASCADE;' as "query" ` +
|
|
1385
|
+
// `FROM "pg_views" WHERE "schemaname" IN (${schemaNamesString}) AND "viewname" NOT IN ('geography_columns', 'geometry_columns', 'raster_columns', 'raster_overviews')`;
|
|
1386
|
+
// const dropViewQueries: ObjectLiteral[] = await this.query(selectViewDropsQuery);
|
|
1387
|
+
// await Promise.all(dropViewQueries.map(q => this.query(q["query"])));
|
|
1388
|
+
// ignore spatial_ref_sys; it's a special table supporting PostGIS
|
|
1389
|
+
const selectTableDropsQuery = `SELECT 'DROP TABLE "' || schema_name || '"."' || table_name || '" CASCADE;' as "query" FROM "SYS"."TABLES" WHERE "SCHEMA_NAME" IN (${schemaNamesString}) AND "TABLE_NAME" NOT IN ('SYS_AFL_GENERATOR_PARAMETERS') AND "IS_COLUMN_TABLE" = 'TRUE'`;
|
|
1390
|
+
const dropTableQueries = await this.query(selectTableDropsQuery);
|
|
1391
|
+
await Promise.all(dropTableQueries.map((q) => this.query(q["query"])));
|
|
1392
|
+
if (!isAnotherTransactionActive)
|
|
1393
|
+
await this.commitTransaction();
|
|
1394
|
+
}
|
|
1395
|
+
catch (error) {
|
|
1396
|
+
try {
|
|
1397
|
+
// we throw original error even if rollback thrown an error
|
|
1398
|
+
if (!isAnotherTransactionActive)
|
|
1399
|
+
await this.rollbackTransaction();
|
|
1400
|
+
}
|
|
1401
|
+
catch (rollbackError) { }
|
|
1402
|
+
throw error;
|
|
1403
|
+
}
|
|
1404
|
+
}
|
|
2226
1405
|
// -------------------------------------------------------------------------
|
|
2227
1406
|
// Protected Methods
|
|
2228
1407
|
// -------------------------------------------------------------------------
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
case 4:
|
|
2262
|
-
dbViews = _a.sent();
|
|
2263
|
-
return [2 /*return*/, dbViews.map(function (dbView) {
|
|
2264
|
-
var view = new View_1.View();
|
|
2265
|
-
var schema = dbView["schema"] === currentSchema &&
|
|
2266
|
-
!_this.driver.options.schema
|
|
2267
|
-
? undefined
|
|
2268
|
-
: dbView["schema"];
|
|
2269
|
-
view.database = currentDatabase;
|
|
2270
|
-
view.schema = dbView["schema"];
|
|
2271
|
-
view.name = _this.driver.buildTableName(dbView["name"], schema);
|
|
2272
|
-
view.expression = dbView["value"];
|
|
2273
|
-
return view;
|
|
2274
|
-
})];
|
|
2275
|
-
}
|
|
2276
|
-
});
|
|
1408
|
+
async loadViews(viewNames) {
|
|
1409
|
+
const hasTable = await this.hasTable(this.getTypeormMetadataTableName());
|
|
1410
|
+
if (!hasTable) {
|
|
1411
|
+
return [];
|
|
1412
|
+
}
|
|
1413
|
+
if (!viewNames) {
|
|
1414
|
+
viewNames = [];
|
|
1415
|
+
}
|
|
1416
|
+
const currentDatabase = await this.getCurrentDatabase();
|
|
1417
|
+
const currentSchema = await this.getCurrentSchema();
|
|
1418
|
+
const viewsCondition = viewNames
|
|
1419
|
+
.map((viewName) => {
|
|
1420
|
+
let { schema, tableName: name } = this.driver.parseTableName(viewName);
|
|
1421
|
+
if (!schema) {
|
|
1422
|
+
schema = currentSchema;
|
|
1423
|
+
}
|
|
1424
|
+
return `("t"."schema" = '${schema}' AND "t"."name" = '${name}')`;
|
|
1425
|
+
})
|
|
1426
|
+
.join(" OR ");
|
|
1427
|
+
const query = `SELECT "t".* FROM ${this.escapePath(this.getTypeormMetadataTableName())} "t" WHERE "t"."type" = '${MetadataTableType_1.MetadataTableType.VIEW}' ${viewsCondition ? `AND (${viewsCondition})` : ""}`;
|
|
1428
|
+
const dbViews = await this.query(query);
|
|
1429
|
+
return dbViews.map((dbView) => {
|
|
1430
|
+
const view = new View_1.View();
|
|
1431
|
+
const schema = dbView["schema"] === currentSchema &&
|
|
1432
|
+
!this.driver.options.schema
|
|
1433
|
+
? undefined
|
|
1434
|
+
: dbView["schema"];
|
|
1435
|
+
view.database = currentDatabase;
|
|
1436
|
+
view.schema = dbView["schema"];
|
|
1437
|
+
view.name = this.driver.buildTableName(dbView["name"], schema);
|
|
1438
|
+
view.expression = dbView["value"];
|
|
1439
|
+
return view;
|
|
2277
1440
|
});
|
|
2278
|
-
}
|
|
1441
|
+
}
|
|
2279
1442
|
/**
|
|
2280
1443
|
* Loads all tables (with given names) from the database and creates a Table from them.
|
|
2281
1444
|
*/
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
]
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
return dbIndices.some(function (dbIndex) {
|
|
2441
|
-
return dbIndex["INDEX_NAME"] ===
|
|
2442
|
-
uniqueIndex["INDEX_NAME"] &&
|
|
2443
|
-
dbIndex["COLUMN_NAME"] !==
|
|
2444
|
-
dbColumn["COLUMN_NAME"];
|
|
2445
|
-
});
|
|
2446
|
-
});
|
|
2447
|
-
tableColumn = new TableColumn_1.TableColumn();
|
|
2448
|
-
tableColumn.name = dbColumn["COLUMN_NAME"];
|
|
2449
|
-
tableColumn.type =
|
|
2450
|
-
dbColumn["DATA_TYPE_NAME"].toLowerCase();
|
|
2451
|
-
if (tableColumn.type === "dec" ||
|
|
2452
|
-
tableColumn.type === "decimal") {
|
|
2453
|
-
// If one of these properties was set, and another was not, Postgres sets '0' in to unspecified property
|
|
2454
|
-
// we set 'undefined' in to unspecified property to avoid changing column on sync
|
|
2455
|
-
if (dbColumn["LENGTH"] !== null &&
|
|
2456
|
-
!this.isDefaultColumnPrecision(table, tableColumn, dbColumn["LENGTH"])) {
|
|
2457
|
-
tableColumn.precision = dbColumn["LENGTH"];
|
|
2458
|
-
}
|
|
2459
|
-
else if (dbColumn["SCALE"] !== null &&
|
|
2460
|
-
!this.isDefaultColumnScale(table, tableColumn, dbColumn["SCALE"])) {
|
|
2461
|
-
tableColumn.precision = undefined;
|
|
2462
|
-
}
|
|
2463
|
-
if (dbColumn["SCALE"] !== null &&
|
|
2464
|
-
!this.isDefaultColumnScale(table, tableColumn, dbColumn["SCALE"])) {
|
|
2465
|
-
tableColumn.scale = dbColumn["SCALE"];
|
|
2466
|
-
}
|
|
2467
|
-
else if (dbColumn["LENGTH"] !== null &&
|
|
2468
|
-
!this.isDefaultColumnPrecision(table, tableColumn, dbColumn["LENGTH"])) {
|
|
2469
|
-
tableColumn.scale = undefined;
|
|
2470
|
-
}
|
|
2471
|
-
}
|
|
2472
|
-
if (dbColumn["DATA_TYPE_NAME"].toLowerCase() ===
|
|
2473
|
-
"array") {
|
|
2474
|
-
tableColumn.isArray = true;
|
|
2475
|
-
tableColumn.type =
|
|
2476
|
-
dbColumn["CS_DATA_TYPE_NAME"].toLowerCase();
|
|
2477
|
-
}
|
|
2478
|
-
// check only columns that have length property
|
|
2479
|
-
if (this.driver.withLengthColumnTypes.indexOf(tableColumn.type) !== -1 &&
|
|
2480
|
-
dbColumn["LENGTH"]) {
|
|
2481
|
-
length_1 = dbColumn["LENGTH"].toString();
|
|
2482
|
-
tableColumn.length =
|
|
2483
|
-
!this.isDefaultColumnLength(table, tableColumn, length_1)
|
|
2484
|
-
? length_1
|
|
2485
|
-
: "";
|
|
2486
|
-
}
|
|
2487
|
-
tableColumn.isUnique =
|
|
2488
|
-
columnUniqueIndices.length > 0 &&
|
|
2489
|
-
!hasIgnoredIndex &&
|
|
2490
|
-
!isConstraintComposite;
|
|
2491
|
-
tableColumn.isNullable =
|
|
2492
|
-
dbColumn["IS_NULLABLE"] === "TRUE";
|
|
2493
|
-
tableColumn.isPrimary = !!columnConstraints.find(function (constraint) {
|
|
2494
|
-
return constraint["IS_PRIMARY_KEY"] === "TRUE";
|
|
2495
|
-
});
|
|
2496
|
-
tableColumn.isGenerated =
|
|
2497
|
-
dbColumn["GENERATION_TYPE"] ===
|
|
2498
|
-
"ALWAYS AS IDENTITY";
|
|
2499
|
-
if (tableColumn.isGenerated)
|
|
2500
|
-
tableColumn.generationStrategy = "increment";
|
|
2501
|
-
if (dbColumn["DEFAULT_VALUE"] === null ||
|
|
2502
|
-
dbColumn["DEFAULT_VALUE"] === undefined) {
|
|
2503
|
-
tableColumn.default = undefined;
|
|
2504
|
-
}
|
|
2505
|
-
else {
|
|
2506
|
-
if (tableColumn.type === "char" ||
|
|
2507
|
-
tableColumn.type === "nchar" ||
|
|
2508
|
-
tableColumn.type === "varchar" ||
|
|
2509
|
-
tableColumn.type === "nvarchar" ||
|
|
2510
|
-
tableColumn.type === "alphanum" ||
|
|
2511
|
-
tableColumn.type === "shorttext") {
|
|
2512
|
-
tableColumn.default = "'".concat(dbColumn["DEFAULT_VALUE"], "'");
|
|
2513
|
-
}
|
|
2514
|
-
else if (tableColumn.type === "boolean") {
|
|
2515
|
-
tableColumn.default =
|
|
2516
|
-
dbColumn["DEFAULT_VALUE"] === "1"
|
|
2517
|
-
? "true"
|
|
2518
|
-
: "false";
|
|
2519
|
-
}
|
|
2520
|
-
else {
|
|
2521
|
-
tableColumn.default =
|
|
2522
|
-
dbColumn["DEFAULT_VALUE"];
|
|
2523
|
-
}
|
|
2524
|
-
}
|
|
2525
|
-
tableColumn.comment = ""; // dbColumn["COLUMN_COMMENT"];
|
|
2526
|
-
if (dbColumn["character_set_name"])
|
|
2527
|
-
tableColumn.charset =
|
|
2528
|
-
dbColumn["character_set_name"];
|
|
2529
|
-
if (dbColumn["collation_name"])
|
|
2530
|
-
tableColumn.collation =
|
|
2531
|
-
dbColumn["collation_name"];
|
|
2532
|
-
return [2 /*return*/, tableColumn];
|
|
2533
|
-
});
|
|
2534
|
-
}); }))
|
|
2535
|
-
// find check constraints of table, group them by constraint name and build TableCheck.
|
|
2536
|
-
];
|
|
2537
|
-
case 1:
|
|
2538
|
-
// create columns from the loaded columns
|
|
2539
|
-
_a.columns = _b.sent();
|
|
2540
|
-
tableCheckConstraints = OrmUtils_1.OrmUtils.uniq(dbConstraints.filter(function (dbConstraint) {
|
|
2541
|
-
return dbConstraint["TABLE_NAME"] ===
|
|
2542
|
-
dbTable["TABLE_NAME"] &&
|
|
2543
|
-
dbConstraint["SCHEMA_NAME"] ===
|
|
2544
|
-
dbTable["SCHEMA_NAME"] &&
|
|
2545
|
-
dbConstraint["CHECK_CONDITION"] !== null &&
|
|
2546
|
-
dbConstraint["CHECK_CONDITION"] !== undefined;
|
|
2547
|
-
}), function (dbConstraint) { return dbConstraint["CONSTRAINT_NAME"]; });
|
|
2548
|
-
table.checks = tableCheckConstraints.map(function (constraint) {
|
|
2549
|
-
var checks = dbConstraints.filter(function (dbC) {
|
|
2550
|
-
return dbC["CONSTRAINT_NAME"] ===
|
|
2551
|
-
constraint["CONSTRAINT_NAME"];
|
|
2552
|
-
});
|
|
2553
|
-
return new TableCheck_1.TableCheck({
|
|
2554
|
-
name: constraint["CONSTRAINT_NAME"],
|
|
2555
|
-
columnNames: checks.map(function (c) { return c["COLUMN_NAME"]; }),
|
|
2556
|
-
expression: constraint["CHECK_CONDITION"],
|
|
2557
|
-
});
|
|
2558
|
-
});
|
|
2559
|
-
tableForeignKeyConstraints = OrmUtils_1.OrmUtils.uniq(dbForeignKeys.filter(function (dbForeignKey) {
|
|
2560
|
-
return dbForeignKey["TABLE_NAME"] ===
|
|
2561
|
-
dbTable["TABLE_NAME"] &&
|
|
2562
|
-
dbForeignKey["SCHEMA_NAME"] ===
|
|
2563
|
-
dbTable["SCHEMA_NAME"];
|
|
2564
|
-
}), function (dbForeignKey) { return dbForeignKey["CONSTRAINT_NAME"]; });
|
|
2565
|
-
table.foreignKeys = tableForeignKeyConstraints.map(function (dbForeignKey) {
|
|
2566
|
-
var foreignKeys = dbForeignKeys.filter(function (dbFk) {
|
|
2567
|
-
return dbFk["CONSTRAINT_NAME"] ===
|
|
2568
|
-
dbForeignKey["CONSTRAINT_NAME"];
|
|
2569
|
-
});
|
|
2570
|
-
// if referenced table located in currently used schema, we don't need to concat schema name to table name.
|
|
2571
|
-
var schema = getSchemaFromKey(dbForeignKey, "REFERENCED_SCHEMA_NAME");
|
|
2572
|
-
var referencedTableName = _this.driver.buildTableName(dbForeignKey["REFERENCED_TABLE_NAME"], schema);
|
|
2573
|
-
return new TableForeignKey_1.TableForeignKey({
|
|
2574
|
-
name: dbForeignKey["CONSTRAINT_NAME"],
|
|
2575
|
-
columnNames: foreignKeys.map(function (dbFk) { return dbFk["COLUMN_NAME"]; }),
|
|
2576
|
-
referencedDatabase: table.database,
|
|
2577
|
-
referencedSchema: dbForeignKey["REFERENCED_SCHEMA_NAME"],
|
|
2578
|
-
referencedTableName: referencedTableName,
|
|
2579
|
-
referencedColumnNames: foreignKeys.map(function (dbFk) { return dbFk["REFERENCED_COLUMN_NAME"]; }),
|
|
2580
|
-
onDelete: dbForeignKey["DELETE_RULE"] === "RESTRICT"
|
|
2581
|
-
? "NO ACTION"
|
|
2582
|
-
: dbForeignKey["DELETE_RULE"],
|
|
2583
|
-
onUpdate: dbForeignKey["UPDATE_RULE"] === "RESTRICT"
|
|
2584
|
-
? "NO ACTION"
|
|
2585
|
-
: dbForeignKey["UPDATE_RULE"],
|
|
2586
|
-
deferrable: dbForeignKey["CHECK_TIME"].replace("_", " "),
|
|
2587
|
-
});
|
|
2588
|
-
});
|
|
2589
|
-
tableIndexConstraints = OrmUtils_1.OrmUtils.uniq(dbIndices.filter(function (dbIndex) {
|
|
2590
|
-
return dbIndex["TABLE_NAME"] === dbTable["TABLE_NAME"] &&
|
|
2591
|
-
dbIndex["SCHEMA_NAME"] === dbTable["SCHEMA_NAME"];
|
|
2592
|
-
}), function (dbIndex) { return dbIndex["INDEX_NAME"]; });
|
|
2593
|
-
table.indices = tableIndexConstraints.map(function (constraint) {
|
|
2594
|
-
var indices = dbIndices.filter(function (index) {
|
|
2595
|
-
return (index["SCHEMA_NAME"] ===
|
|
2596
|
-
constraint["SCHEMA_NAME"] &&
|
|
2597
|
-
index["TABLE_NAME"] === constraint["TABLE_NAME"] &&
|
|
2598
|
-
index["INDEX_NAME"] === constraint["INDEX_NAME"]);
|
|
2599
|
-
});
|
|
2600
|
-
return new TableIndex_1.TableIndex({
|
|
2601
|
-
table: table,
|
|
2602
|
-
name: constraint["INDEX_NAME"],
|
|
2603
|
-
columnNames: indices.map(function (i) { return i["COLUMN_NAME"]; }),
|
|
2604
|
-
isUnique: constraint["CONSTRAINT"] &&
|
|
2605
|
-
constraint["CONSTRAINT"].indexOf("UNIQUE") !== -1,
|
|
2606
|
-
isFulltext: constraint["INDEX_TYPE"] === "FULLTEXT",
|
|
2607
|
-
});
|
|
2608
|
-
});
|
|
2609
|
-
return [2 /*return*/, table];
|
|
2610
|
-
}
|
|
2611
|
-
});
|
|
2612
|
-
}); }))];
|
|
1445
|
+
async loadTables(tableNames) {
|
|
1446
|
+
if (tableNames && tableNames.length === 0) {
|
|
1447
|
+
return [];
|
|
1448
|
+
}
|
|
1449
|
+
const currentSchema = await this.getCurrentSchema();
|
|
1450
|
+
const currentDatabase = await this.getCurrentDatabase();
|
|
1451
|
+
const dbTables = [];
|
|
1452
|
+
if (!tableNames) {
|
|
1453
|
+
const tablesSql = `SELECT "SCHEMA_NAME", "TABLE_NAME" FROM "SYS"."TABLES"`;
|
|
1454
|
+
dbTables.push(...(await this.query(tablesSql)));
|
|
1455
|
+
}
|
|
1456
|
+
else {
|
|
1457
|
+
const tablesCondition = tableNames
|
|
1458
|
+
.map((tableName) => {
|
|
1459
|
+
let [schema, name] = tableName.split(".");
|
|
1460
|
+
if (!name) {
|
|
1461
|
+
name = schema;
|
|
1462
|
+
schema = this.driver.options.schema || currentSchema;
|
|
1463
|
+
}
|
|
1464
|
+
return `("SCHEMA_NAME" = '${schema}' AND "TABLE_NAME" = '${name}')`;
|
|
1465
|
+
})
|
|
1466
|
+
.join(" OR ");
|
|
1467
|
+
const tablesSql = `SELECT "SCHEMA_NAME", "TABLE_NAME" FROM "SYS"."TABLES" WHERE ` +
|
|
1468
|
+
tablesCondition;
|
|
1469
|
+
dbTables.push(...(await this.query(tablesSql)));
|
|
1470
|
+
}
|
|
1471
|
+
// if tables were not found in the db, no need to proceed
|
|
1472
|
+
if (dbTables.length === 0)
|
|
1473
|
+
return [];
|
|
1474
|
+
const columnsCondition = dbTables
|
|
1475
|
+
.map(({ SCHEMA_NAME, TABLE_NAME }) => {
|
|
1476
|
+
return `("SCHEMA_NAME" = '${SCHEMA_NAME}' AND "TABLE_NAME" = '${TABLE_NAME}')`;
|
|
1477
|
+
})
|
|
1478
|
+
.join(" OR ");
|
|
1479
|
+
const columnsSql = `SELECT * FROM "SYS"."TABLE_COLUMNS" WHERE ` +
|
|
1480
|
+
columnsCondition +
|
|
1481
|
+
` ORDER BY "POSITION"`;
|
|
1482
|
+
const constraintsCondition = dbTables
|
|
1483
|
+
.map(({ SCHEMA_NAME, TABLE_NAME }) => {
|
|
1484
|
+
return `("SCHEMA_NAME" = '${SCHEMA_NAME}' AND "TABLE_NAME" = '${TABLE_NAME}')`;
|
|
1485
|
+
})
|
|
1486
|
+
.join(" OR ");
|
|
1487
|
+
const constraintsSql = `SELECT * FROM "SYS"."CONSTRAINTS" WHERE (${constraintsCondition}) ORDER BY "POSITION"`;
|
|
1488
|
+
const indicesCondition = dbTables
|
|
1489
|
+
.map(({ SCHEMA_NAME, TABLE_NAME }) => {
|
|
1490
|
+
return `("I"."SCHEMA_NAME" = '${SCHEMA_NAME}' AND "I"."TABLE_NAME" = '${TABLE_NAME}')`;
|
|
1491
|
+
})
|
|
1492
|
+
.join(" OR ");
|
|
1493
|
+
// excluding primary key and autogenerated fulltext indices
|
|
1494
|
+
const indicesSql = `SELECT "I"."INDEX_TYPE", "I"."SCHEMA_NAME", "I"."TABLE_NAME", "I"."INDEX_NAME", "IC"."COLUMN_NAME", "I"."CONSTRAINT" ` +
|
|
1495
|
+
`FROM "SYS"."INDEXES" "I" INNER JOIN "SYS"."INDEX_COLUMNS" "IC" ON "IC"."INDEX_OID" = "I"."INDEX_OID" ` +
|
|
1496
|
+
`WHERE (${indicesCondition}) AND ("I"."CONSTRAINT" IS NULL OR "I"."CONSTRAINT" != 'PRIMARY KEY') AND "I"."INDEX_NAME" NOT LIKE '%_SYS_FULLTEXT_%' ORDER BY "IC"."POSITION"`;
|
|
1497
|
+
const foreignKeysCondition = dbTables
|
|
1498
|
+
.map(({ SCHEMA_NAME, TABLE_NAME }) => {
|
|
1499
|
+
return `("SCHEMA_NAME" = '${SCHEMA_NAME}' AND "TABLE_NAME" = '${TABLE_NAME}')`;
|
|
1500
|
+
})
|
|
1501
|
+
.join(" OR ");
|
|
1502
|
+
const foreignKeysSql = `SELECT * FROM "SYS"."REFERENTIAL_CONSTRAINTS" WHERE (${foreignKeysCondition}) ORDER BY "POSITION"`;
|
|
1503
|
+
const [dbColumns, dbConstraints, dbIndices, dbForeignKeys,] = await Promise.all([
|
|
1504
|
+
this.query(columnsSql),
|
|
1505
|
+
this.query(constraintsSql),
|
|
1506
|
+
this.query(indicesSql),
|
|
1507
|
+
this.query(foreignKeysSql),
|
|
1508
|
+
]);
|
|
1509
|
+
// create tables for loaded tables
|
|
1510
|
+
return Promise.all(dbTables.map(async (dbTable) => {
|
|
1511
|
+
const table = new Table_1.Table();
|
|
1512
|
+
const getSchemaFromKey = (dbObject, key) => {
|
|
1513
|
+
return dbObject[key] === currentSchema &&
|
|
1514
|
+
(!this.driver.options.schema ||
|
|
1515
|
+
this.driver.options.schema === currentSchema)
|
|
1516
|
+
? undefined
|
|
1517
|
+
: dbObject[key];
|
|
1518
|
+
};
|
|
1519
|
+
// We do not need to join schema name, when database is by default.
|
|
1520
|
+
const schema = getSchemaFromKey(dbTable, "SCHEMA_NAME");
|
|
1521
|
+
table.database = currentDatabase;
|
|
1522
|
+
table.schema = dbTable["SCHEMA_NAME"];
|
|
1523
|
+
table.name = this.driver.buildTableName(dbTable["TABLE_NAME"], schema);
|
|
1524
|
+
// create columns from the loaded columns
|
|
1525
|
+
table.columns = await Promise.all(dbColumns
|
|
1526
|
+
.filter((dbColumn) => dbColumn["TABLE_NAME"] ===
|
|
1527
|
+
dbTable["TABLE_NAME"] &&
|
|
1528
|
+
dbColumn["SCHEMA_NAME"] ===
|
|
1529
|
+
dbTable["SCHEMA_NAME"])
|
|
1530
|
+
.map(async (dbColumn) => {
|
|
1531
|
+
const columnConstraints = dbConstraints.filter((dbConstraint) => dbConstraint["TABLE_NAME"] ===
|
|
1532
|
+
dbColumn["TABLE_NAME"] &&
|
|
1533
|
+
dbConstraint["SCHEMA_NAME"] ===
|
|
1534
|
+
dbColumn["SCHEMA_NAME"] &&
|
|
1535
|
+
dbConstraint["COLUMN_NAME"] ===
|
|
1536
|
+
dbColumn["COLUMN_NAME"]);
|
|
1537
|
+
const columnUniqueIndices = dbIndices.filter((dbIndex) => {
|
|
1538
|
+
return (dbIndex["TABLE_NAME"] ===
|
|
1539
|
+
dbTable["TABLE_NAME"] &&
|
|
1540
|
+
dbIndex["SCHEMA_NAME"] ===
|
|
1541
|
+
dbTable["SCHEMA_NAME"] &&
|
|
1542
|
+
dbIndex["COLUMN_NAME"] ===
|
|
1543
|
+
dbColumn["COLUMN_NAME"] &&
|
|
1544
|
+
dbIndex["CONSTRAINT"] &&
|
|
1545
|
+
dbIndex["CONSTRAINT"].indexOf("UNIQUE") !== -1);
|
|
1546
|
+
});
|
|
1547
|
+
const tableMetadata = this.connection.entityMetadatas.find((metadata) => this.getTablePath(table) ===
|
|
1548
|
+
this.getTablePath(metadata));
|
|
1549
|
+
const hasIgnoredIndex = columnUniqueIndices.length > 0 &&
|
|
1550
|
+
tableMetadata &&
|
|
1551
|
+
tableMetadata.indices.some((index) => {
|
|
1552
|
+
return columnUniqueIndices.some((uniqueIndex) => {
|
|
1553
|
+
return (index.name ===
|
|
1554
|
+
uniqueIndex["INDEX_NAME"] &&
|
|
1555
|
+
index.synchronize === false);
|
|
1556
|
+
});
|
|
1557
|
+
});
|
|
1558
|
+
const isConstraintComposite = columnUniqueIndices.every((uniqueIndex) => {
|
|
1559
|
+
return dbIndices.some((dbIndex) => dbIndex["INDEX_NAME"] ===
|
|
1560
|
+
uniqueIndex["INDEX_NAME"] &&
|
|
1561
|
+
dbIndex["COLUMN_NAME"] !==
|
|
1562
|
+
dbColumn["COLUMN_NAME"]);
|
|
1563
|
+
});
|
|
1564
|
+
const tableColumn = new TableColumn_1.TableColumn();
|
|
1565
|
+
tableColumn.name = dbColumn["COLUMN_NAME"];
|
|
1566
|
+
tableColumn.type =
|
|
1567
|
+
dbColumn["DATA_TYPE_NAME"].toLowerCase();
|
|
1568
|
+
if (tableColumn.type === "dec" ||
|
|
1569
|
+
tableColumn.type === "decimal") {
|
|
1570
|
+
// If one of these properties was set, and another was not, Postgres sets '0' in to unspecified property
|
|
1571
|
+
// we set 'undefined' in to unspecified property to avoid changing column on sync
|
|
1572
|
+
if (dbColumn["LENGTH"] !== null &&
|
|
1573
|
+
!this.isDefaultColumnPrecision(table, tableColumn, dbColumn["LENGTH"])) {
|
|
1574
|
+
tableColumn.precision = dbColumn["LENGTH"];
|
|
1575
|
+
}
|
|
1576
|
+
else if (dbColumn["SCALE"] !== null &&
|
|
1577
|
+
!this.isDefaultColumnScale(table, tableColumn, dbColumn["SCALE"])) {
|
|
1578
|
+
tableColumn.precision = undefined;
|
|
1579
|
+
}
|
|
1580
|
+
if (dbColumn["SCALE"] !== null &&
|
|
1581
|
+
!this.isDefaultColumnScale(table, tableColumn, dbColumn["SCALE"])) {
|
|
1582
|
+
tableColumn.scale = dbColumn["SCALE"];
|
|
1583
|
+
}
|
|
1584
|
+
else if (dbColumn["LENGTH"] !== null &&
|
|
1585
|
+
!this.isDefaultColumnPrecision(table, tableColumn, dbColumn["LENGTH"])) {
|
|
1586
|
+
tableColumn.scale = undefined;
|
|
1587
|
+
}
|
|
1588
|
+
}
|
|
1589
|
+
if (dbColumn["DATA_TYPE_NAME"].toLowerCase() ===
|
|
1590
|
+
"array") {
|
|
1591
|
+
tableColumn.isArray = true;
|
|
1592
|
+
tableColumn.type =
|
|
1593
|
+
dbColumn["CS_DATA_TYPE_NAME"].toLowerCase();
|
|
1594
|
+
}
|
|
1595
|
+
// check only columns that have length property
|
|
1596
|
+
if (this.driver.withLengthColumnTypes.indexOf(tableColumn.type) !== -1 &&
|
|
1597
|
+
dbColumn["LENGTH"]) {
|
|
1598
|
+
const length = dbColumn["LENGTH"].toString();
|
|
1599
|
+
tableColumn.length =
|
|
1600
|
+
!this.isDefaultColumnLength(table, tableColumn, length)
|
|
1601
|
+
? length
|
|
1602
|
+
: "";
|
|
2613
1603
|
}
|
|
1604
|
+
tableColumn.isUnique =
|
|
1605
|
+
columnUniqueIndices.length > 0 &&
|
|
1606
|
+
!hasIgnoredIndex &&
|
|
1607
|
+
!isConstraintComposite;
|
|
1608
|
+
tableColumn.isNullable =
|
|
1609
|
+
dbColumn["IS_NULLABLE"] === "TRUE";
|
|
1610
|
+
tableColumn.isPrimary = !!columnConstraints.find((constraint) => constraint["IS_PRIMARY_KEY"] === "TRUE");
|
|
1611
|
+
tableColumn.isGenerated =
|
|
1612
|
+
dbColumn["GENERATION_TYPE"] ===
|
|
1613
|
+
"ALWAYS AS IDENTITY";
|
|
1614
|
+
if (tableColumn.isGenerated)
|
|
1615
|
+
tableColumn.generationStrategy = "increment";
|
|
1616
|
+
if (dbColumn["DEFAULT_VALUE"] === null ||
|
|
1617
|
+
dbColumn["DEFAULT_VALUE"] === undefined) {
|
|
1618
|
+
tableColumn.default = undefined;
|
|
1619
|
+
}
|
|
1620
|
+
else {
|
|
1621
|
+
if (tableColumn.type === "char" ||
|
|
1622
|
+
tableColumn.type === "nchar" ||
|
|
1623
|
+
tableColumn.type === "varchar" ||
|
|
1624
|
+
tableColumn.type === "nvarchar" ||
|
|
1625
|
+
tableColumn.type === "alphanum" ||
|
|
1626
|
+
tableColumn.type === "shorttext") {
|
|
1627
|
+
tableColumn.default = `'${dbColumn["DEFAULT_VALUE"]}'`;
|
|
1628
|
+
}
|
|
1629
|
+
else if (tableColumn.type === "boolean") {
|
|
1630
|
+
tableColumn.default =
|
|
1631
|
+
dbColumn["DEFAULT_VALUE"] === "1"
|
|
1632
|
+
? "true"
|
|
1633
|
+
: "false";
|
|
1634
|
+
}
|
|
1635
|
+
else {
|
|
1636
|
+
tableColumn.default =
|
|
1637
|
+
dbColumn["DEFAULT_VALUE"];
|
|
1638
|
+
}
|
|
1639
|
+
}
|
|
1640
|
+
tableColumn.comment = ""; // dbColumn["COLUMN_COMMENT"];
|
|
1641
|
+
if (dbColumn["character_set_name"])
|
|
1642
|
+
tableColumn.charset =
|
|
1643
|
+
dbColumn["character_set_name"];
|
|
1644
|
+
if (dbColumn["collation_name"])
|
|
1645
|
+
tableColumn.collation =
|
|
1646
|
+
dbColumn["collation_name"];
|
|
1647
|
+
return tableColumn;
|
|
1648
|
+
}));
|
|
1649
|
+
// find check constraints of table, group them by constraint name and build TableCheck.
|
|
1650
|
+
const tableCheckConstraints = OrmUtils_1.OrmUtils.uniq(dbConstraints.filter((dbConstraint) => dbConstraint["TABLE_NAME"] ===
|
|
1651
|
+
dbTable["TABLE_NAME"] &&
|
|
1652
|
+
dbConstraint["SCHEMA_NAME"] ===
|
|
1653
|
+
dbTable["SCHEMA_NAME"] &&
|
|
1654
|
+
dbConstraint["CHECK_CONDITION"] !== null &&
|
|
1655
|
+
dbConstraint["CHECK_CONDITION"] !== undefined), (dbConstraint) => dbConstraint["CONSTRAINT_NAME"]);
|
|
1656
|
+
table.checks = tableCheckConstraints.map((constraint) => {
|
|
1657
|
+
const checks = dbConstraints.filter((dbC) => dbC["CONSTRAINT_NAME"] ===
|
|
1658
|
+
constraint["CONSTRAINT_NAME"]);
|
|
1659
|
+
return new TableCheck_1.TableCheck({
|
|
1660
|
+
name: constraint["CONSTRAINT_NAME"],
|
|
1661
|
+
columnNames: checks.map((c) => c["COLUMN_NAME"]),
|
|
1662
|
+
expression: constraint["CHECK_CONDITION"],
|
|
1663
|
+
});
|
|
2614
1664
|
});
|
|
2615
|
-
|
|
2616
|
-
|
|
1665
|
+
// find foreign key constraints of table, group them by constraint name and build TableForeignKey.
|
|
1666
|
+
const tableForeignKeyConstraints = OrmUtils_1.OrmUtils.uniq(dbForeignKeys.filter((dbForeignKey) => dbForeignKey["TABLE_NAME"] ===
|
|
1667
|
+
dbTable["TABLE_NAME"] &&
|
|
1668
|
+
dbForeignKey["SCHEMA_NAME"] ===
|
|
1669
|
+
dbTable["SCHEMA_NAME"]), (dbForeignKey) => dbForeignKey["CONSTRAINT_NAME"]);
|
|
1670
|
+
table.foreignKeys = tableForeignKeyConstraints.map((dbForeignKey) => {
|
|
1671
|
+
const foreignKeys = dbForeignKeys.filter((dbFk) => dbFk["CONSTRAINT_NAME"] ===
|
|
1672
|
+
dbForeignKey["CONSTRAINT_NAME"]);
|
|
1673
|
+
// if referenced table located in currently used schema, we don't need to concat schema name to table name.
|
|
1674
|
+
const schema = getSchemaFromKey(dbForeignKey, "REFERENCED_SCHEMA_NAME");
|
|
1675
|
+
const referencedTableName = this.driver.buildTableName(dbForeignKey["REFERENCED_TABLE_NAME"], schema);
|
|
1676
|
+
return new TableForeignKey_1.TableForeignKey({
|
|
1677
|
+
name: dbForeignKey["CONSTRAINT_NAME"],
|
|
1678
|
+
columnNames: foreignKeys.map((dbFk) => dbFk["COLUMN_NAME"]),
|
|
1679
|
+
referencedDatabase: table.database,
|
|
1680
|
+
referencedSchema: dbForeignKey["REFERENCED_SCHEMA_NAME"],
|
|
1681
|
+
referencedTableName: referencedTableName,
|
|
1682
|
+
referencedColumnNames: foreignKeys.map((dbFk) => dbFk["REFERENCED_COLUMN_NAME"]),
|
|
1683
|
+
onDelete: dbForeignKey["DELETE_RULE"] === "RESTRICT"
|
|
1684
|
+
? "NO ACTION"
|
|
1685
|
+
: dbForeignKey["DELETE_RULE"],
|
|
1686
|
+
onUpdate: dbForeignKey["UPDATE_RULE"] === "RESTRICT"
|
|
1687
|
+
? "NO ACTION"
|
|
1688
|
+
: dbForeignKey["UPDATE_RULE"],
|
|
1689
|
+
deferrable: dbForeignKey["CHECK_TIME"].replace("_", " "),
|
|
1690
|
+
});
|
|
1691
|
+
});
|
|
1692
|
+
// find index constraints of table, group them by constraint name and build TableIndex.
|
|
1693
|
+
const tableIndexConstraints = OrmUtils_1.OrmUtils.uniq(dbIndices.filter((dbIndex) => dbIndex["TABLE_NAME"] === dbTable["TABLE_NAME"] &&
|
|
1694
|
+
dbIndex["SCHEMA_NAME"] === dbTable["SCHEMA_NAME"]), (dbIndex) => dbIndex["INDEX_NAME"]);
|
|
1695
|
+
table.indices = tableIndexConstraints.map((constraint) => {
|
|
1696
|
+
const indices = dbIndices.filter((index) => {
|
|
1697
|
+
return (index["SCHEMA_NAME"] ===
|
|
1698
|
+
constraint["SCHEMA_NAME"] &&
|
|
1699
|
+
index["TABLE_NAME"] === constraint["TABLE_NAME"] &&
|
|
1700
|
+
index["INDEX_NAME"] === constraint["INDEX_NAME"]);
|
|
1701
|
+
});
|
|
1702
|
+
return new TableIndex_1.TableIndex({
|
|
1703
|
+
table: table,
|
|
1704
|
+
name: constraint["INDEX_NAME"],
|
|
1705
|
+
columnNames: indices.map((i) => i["COLUMN_NAME"]),
|
|
1706
|
+
isUnique: constraint["CONSTRAINT"] &&
|
|
1707
|
+
constraint["CONSTRAINT"].indexOf("UNIQUE") !== -1,
|
|
1708
|
+
isFulltext: constraint["INDEX_TYPE"] === "FULLTEXT",
|
|
1709
|
+
});
|
|
1710
|
+
});
|
|
1711
|
+
return table;
|
|
1712
|
+
}));
|
|
1713
|
+
}
|
|
2617
1714
|
/**
|
|
2618
1715
|
* Builds and returns SQL for create table.
|
|
2619
1716
|
*/
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
.map(function (column) { return _this.buildCreateColumnSql(column); })
|
|
1717
|
+
createTableSql(table, createForeignKeys) {
|
|
1718
|
+
const columnDefinitions = table.columns
|
|
1719
|
+
.map((column) => this.buildCreateColumnSql(column))
|
|
2624
1720
|
.join(", ");
|
|
2625
|
-
|
|
1721
|
+
let sql = `CREATE TABLE ${this.escapePath(table)} (${columnDefinitions}`;
|
|
2626
1722
|
// we create unique indexes instead of unique constraints, because SAP HANA does not have unique constraints.
|
|
2627
1723
|
// if we mark column as Unique, it means that we create UNIQUE INDEX.
|
|
2628
1724
|
table.columns
|
|
2629
|
-
.filter(
|
|
2630
|
-
.forEach(
|
|
2631
|
-
|
|
1725
|
+
.filter((column) => column.isUnique)
|
|
1726
|
+
.forEach((column) => {
|
|
1727
|
+
const isUniqueIndexExist = table.indices.some((index) => {
|
|
2632
1728
|
return (index.columnNames.length === 1 &&
|
|
2633
1729
|
!!index.isUnique &&
|
|
2634
1730
|
index.columnNames.indexOf(column.name) !== -1);
|
|
2635
1731
|
});
|
|
2636
|
-
|
|
1732
|
+
const isUniqueConstraintExist = table.uniques.some((unique) => {
|
|
2637
1733
|
return (unique.columnNames.length === 1 &&
|
|
2638
1734
|
unique.columnNames.indexOf(column.name) !== -1);
|
|
2639
1735
|
});
|
|
2640
1736
|
if (!isUniqueIndexExist && !isUniqueConstraintExist)
|
|
2641
1737
|
table.indices.push(new TableIndex_1.TableIndex({
|
|
2642
|
-
name:
|
|
1738
|
+
name: this.connection.namingStrategy.uniqueConstraintName(table, [column.name]),
|
|
2643
1739
|
columnNames: [column.name],
|
|
2644
1740
|
isUnique: true,
|
|
2645
1741
|
}));
|
|
2646
1742
|
});
|
|
2647
1743
|
// as SAP HANA does not have unique constraints, we must create table indices from table uniques and mark them as unique.
|
|
2648
1744
|
if (table.uniques.length > 0) {
|
|
2649
|
-
table.uniques.forEach(
|
|
2650
|
-
|
|
1745
|
+
table.uniques.forEach((unique) => {
|
|
1746
|
+
const uniqueExist = table.indices.some((index) => index.name === unique.name);
|
|
2651
1747
|
if (!uniqueExist) {
|
|
2652
1748
|
table.indices.push(new TableIndex_1.TableIndex({
|
|
2653
1749
|
name: unique.name,
|
|
@@ -2658,266 +1754,245 @@ var SapQueryRunner = /** @class */ (function (_super) {
|
|
|
2658
1754
|
});
|
|
2659
1755
|
}
|
|
2660
1756
|
if (table.checks.length > 0) {
|
|
2661
|
-
|
|
2662
|
-
.map(
|
|
2663
|
-
|
|
1757
|
+
const checksSql = table.checks
|
|
1758
|
+
.map((check) => {
|
|
1759
|
+
const checkName = check.name
|
|
2664
1760
|
? check.name
|
|
2665
|
-
:
|
|
2666
|
-
return
|
|
1761
|
+
: this.connection.namingStrategy.checkConstraintName(table, check.expression);
|
|
1762
|
+
return `CONSTRAINT "${checkName}" CHECK (${check.expression})`;
|
|
2667
1763
|
})
|
|
2668
1764
|
.join(", ");
|
|
2669
|
-
sql +=
|
|
1765
|
+
sql += `, ${checksSql}`;
|
|
2670
1766
|
}
|
|
2671
1767
|
if (table.foreignKeys.length > 0 && createForeignKeys) {
|
|
2672
|
-
|
|
2673
|
-
.map(
|
|
2674
|
-
|
|
2675
|
-
.map(
|
|
1768
|
+
const foreignKeysSql = table.foreignKeys
|
|
1769
|
+
.map((fk) => {
|
|
1770
|
+
const columnNames = fk.columnNames
|
|
1771
|
+
.map((columnName) => `"${columnName}"`)
|
|
2676
1772
|
.join(", ");
|
|
2677
1773
|
if (!fk.name)
|
|
2678
|
-
fk.name =
|
|
2679
|
-
|
|
2680
|
-
.map(
|
|
1774
|
+
fk.name = this.connection.namingStrategy.foreignKeyName(table, fk.columnNames, this.getTablePath(fk), fk.referencedColumnNames);
|
|
1775
|
+
const referencedColumnNames = fk.referencedColumnNames
|
|
1776
|
+
.map((columnName) => `"${columnName}"`)
|
|
2681
1777
|
.join(", ");
|
|
2682
|
-
|
|
1778
|
+
let constraint = `CONSTRAINT "${fk.name}" FOREIGN KEY (${columnNames}) REFERENCES ${this.escapePath(this.getTablePath(fk))} (${referencedColumnNames})`;
|
|
2683
1779
|
// SAP HANA does not have "NO ACTION" option for FK's
|
|
2684
1780
|
if (fk.onDelete) {
|
|
2685
|
-
|
|
1781
|
+
const onDelete = fk.onDelete === "NO ACTION"
|
|
2686
1782
|
? "RESTRICT"
|
|
2687
1783
|
: fk.onDelete;
|
|
2688
|
-
constraint +=
|
|
1784
|
+
constraint += ` ON DELETE ${onDelete}`;
|
|
2689
1785
|
}
|
|
2690
1786
|
if (fk.onUpdate) {
|
|
2691
|
-
|
|
1787
|
+
const onUpdate = fk.onUpdate === "NO ACTION"
|
|
2692
1788
|
? "RESTRICT"
|
|
2693
1789
|
: fk.onUpdate;
|
|
2694
|
-
constraint +=
|
|
1790
|
+
constraint += ` ON UPDATE ${onUpdate}`;
|
|
2695
1791
|
}
|
|
2696
1792
|
if (fk.deferrable) {
|
|
2697
|
-
constraint +=
|
|
1793
|
+
constraint += ` ${fk.deferrable}`;
|
|
2698
1794
|
}
|
|
2699
1795
|
return constraint;
|
|
2700
1796
|
})
|
|
2701
1797
|
.join(", ");
|
|
2702
|
-
sql +=
|
|
1798
|
+
sql += `, ${foreignKeysSql}`;
|
|
2703
1799
|
}
|
|
2704
|
-
|
|
1800
|
+
const primaryColumns = table.columns.filter((column) => column.isPrimary);
|
|
2705
1801
|
if (primaryColumns.length > 0) {
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
.map(
|
|
1802
|
+
const primaryKeyName = this.connection.namingStrategy.primaryKeyName(table, primaryColumns.map((column) => column.name));
|
|
1803
|
+
const columnNames = primaryColumns
|
|
1804
|
+
.map((column) => `"${column.name}"`)
|
|
2709
1805
|
.join(", ");
|
|
2710
|
-
sql +=
|
|
1806
|
+
sql += `, CONSTRAINT "${primaryKeyName}" PRIMARY KEY (${columnNames})`;
|
|
2711
1807
|
}
|
|
2712
|
-
sql +=
|
|
1808
|
+
sql += `)`;
|
|
2713
1809
|
return new Query_1.Query(sql);
|
|
2714
|
-
}
|
|
1810
|
+
}
|
|
2715
1811
|
/**
|
|
2716
1812
|
* Builds drop table sql.
|
|
2717
1813
|
*/
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
?
|
|
2721
|
-
:
|
|
1814
|
+
dropTableSql(tableOrName, ifExist) {
|
|
1815
|
+
const query = ifExist
|
|
1816
|
+
? `DROP TABLE IF EXISTS ${this.escapePath(tableOrName)}`
|
|
1817
|
+
: `DROP TABLE ${this.escapePath(tableOrName)}`;
|
|
2722
1818
|
return new Query_1.Query(query);
|
|
2723
|
-
}
|
|
2724
|
-
|
|
1819
|
+
}
|
|
1820
|
+
createViewSql(view) {
|
|
2725
1821
|
if (typeof view.expression === "string") {
|
|
2726
|
-
return new Query_1.Query(
|
|
1822
|
+
return new Query_1.Query(`CREATE VIEW ${this.escapePath(view)} AS ${view.expression}`);
|
|
2727
1823
|
}
|
|
2728
1824
|
else {
|
|
2729
|
-
return new Query_1.Query(
|
|
1825
|
+
return new Query_1.Query(`CREATE VIEW ${this.escapePath(view)} AS ${view
|
|
2730
1826
|
.expression(this.connection)
|
|
2731
|
-
.getQuery())
|
|
2732
|
-
}
|
|
2733
|
-
}
|
|
2734
|
-
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
expression = typeof view.expression === "string"
|
|
2748
|
-
? view.expression.trim()
|
|
2749
|
-
: view.expression(this.connection).getQuery();
|
|
2750
|
-
return [2 /*return*/, this.insertTypeormMetadataSql({
|
|
2751
|
-
type: MetadataTableType_1.MetadataTableType.VIEW,
|
|
2752
|
-
schema: schema,
|
|
2753
|
-
name: name,
|
|
2754
|
-
value: expression,
|
|
2755
|
-
})];
|
|
2756
|
-
}
|
|
2757
|
-
});
|
|
1827
|
+
.getQuery()}`);
|
|
1828
|
+
}
|
|
1829
|
+
}
|
|
1830
|
+
async insertViewDefinitionSql(view) {
|
|
1831
|
+
let { schema, tableName: name } = this.driver.parseTableName(view);
|
|
1832
|
+
if (!schema) {
|
|
1833
|
+
schema = await this.getCurrentSchema();
|
|
1834
|
+
}
|
|
1835
|
+
const expression = typeof view.expression === "string"
|
|
1836
|
+
? view.expression.trim()
|
|
1837
|
+
: view.expression(this.connection).getQuery();
|
|
1838
|
+
return this.insertTypeormMetadataSql({
|
|
1839
|
+
type: MetadataTableType_1.MetadataTableType.VIEW,
|
|
1840
|
+
schema: schema,
|
|
1841
|
+
name: name,
|
|
1842
|
+
value: expression,
|
|
2758
1843
|
});
|
|
2759
|
-
}
|
|
1844
|
+
}
|
|
2760
1845
|
/**
|
|
2761
1846
|
* Builds drop view sql.
|
|
2762
1847
|
*/
|
|
2763
|
-
|
|
2764
|
-
return new Query_1.Query(
|
|
2765
|
-
}
|
|
1848
|
+
dropViewSql(viewOrPath) {
|
|
1849
|
+
return new Query_1.Query(`DROP VIEW ${this.escapePath(viewOrPath)}`);
|
|
1850
|
+
}
|
|
2766
1851
|
/**
|
|
2767
1852
|
* Builds remove view sql.
|
|
2768
1853
|
*/
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
case 1:
|
|
2779
|
-
schema = _b.sent();
|
|
2780
|
-
_b.label = 2;
|
|
2781
|
-
case 2: return [2 /*return*/, this.deleteTypeormMetadataSql({
|
|
2782
|
-
type: MetadataTableType_1.MetadataTableType.VIEW,
|
|
2783
|
-
schema: schema,
|
|
2784
|
-
name: name,
|
|
2785
|
-
})];
|
|
2786
|
-
}
|
|
2787
|
-
});
|
|
1854
|
+
async deleteViewDefinitionSql(viewOrPath) {
|
|
1855
|
+
let { schema, tableName: name } = this.driver.parseTableName(viewOrPath);
|
|
1856
|
+
if (!schema) {
|
|
1857
|
+
schema = await this.getCurrentSchema();
|
|
1858
|
+
}
|
|
1859
|
+
return this.deleteTypeormMetadataSql({
|
|
1860
|
+
type: MetadataTableType_1.MetadataTableType.VIEW,
|
|
1861
|
+
schema,
|
|
1862
|
+
name,
|
|
2788
1863
|
});
|
|
2789
|
-
}
|
|
2790
|
-
|
|
2791
|
-
return
|
|
2792
|
-
}
|
|
2793
|
-
|
|
2794
|
-
return
|
|
2795
|
-
}
|
|
1864
|
+
}
|
|
1865
|
+
addColumnSql(table, column) {
|
|
1866
|
+
return `ALTER TABLE ${this.escapePath(table)} ADD (${this.buildCreateColumnSql(column)})`;
|
|
1867
|
+
}
|
|
1868
|
+
dropColumnSql(table, column) {
|
|
1869
|
+
return `ALTER TABLE ${this.escapePath(table)} DROP ("${column.name}")`;
|
|
1870
|
+
}
|
|
2796
1871
|
/**
|
|
2797
1872
|
* Builds create index sql.
|
|
2798
1873
|
*/
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
.map(
|
|
1874
|
+
createIndexSql(table, index) {
|
|
1875
|
+
const columns = index.columnNames
|
|
1876
|
+
.map((columnName) => `"${columnName}"`)
|
|
2802
1877
|
.join(", ");
|
|
2803
|
-
|
|
1878
|
+
let indexType = "";
|
|
2804
1879
|
if (index.isUnique) {
|
|
2805
1880
|
indexType += "UNIQUE ";
|
|
2806
1881
|
}
|
|
2807
1882
|
if (index.isFulltext) {
|
|
2808
1883
|
indexType += "FULLTEXT ";
|
|
2809
1884
|
}
|
|
2810
|
-
return new Query_1.Query(
|
|
2811
|
-
}
|
|
1885
|
+
return new Query_1.Query(`CREATE ${indexType}INDEX "${index.name}" ON ${this.escapePath(table)} (${columns}) ${index.where ? "WHERE " + index.where : ""}`);
|
|
1886
|
+
}
|
|
2812
1887
|
/**
|
|
2813
1888
|
* Builds drop index sql.
|
|
2814
1889
|
*/
|
|
2815
|
-
|
|
2816
|
-
|
|
1890
|
+
dropIndexSql(table, indexOrName) {
|
|
1891
|
+
let indexName = InstanceChecker_1.InstanceChecker.isTableIndex(indexOrName)
|
|
2817
1892
|
? indexOrName.name
|
|
2818
1893
|
: indexOrName;
|
|
2819
|
-
|
|
1894
|
+
const parsedTableName = this.driver.parseTableName(table);
|
|
2820
1895
|
if (!parsedTableName.schema) {
|
|
2821
|
-
return new Query_1.Query(
|
|
1896
|
+
return new Query_1.Query(`DROP INDEX "${indexName}"`);
|
|
2822
1897
|
}
|
|
2823
1898
|
else {
|
|
2824
|
-
return new Query_1.Query(
|
|
1899
|
+
return new Query_1.Query(`DROP INDEX "${parsedTableName.schema}"."${indexName}"`);
|
|
2825
1900
|
}
|
|
2826
|
-
}
|
|
1901
|
+
}
|
|
2827
1902
|
/**
|
|
2828
1903
|
* Builds create primary key sql.
|
|
2829
1904
|
*/
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
.map(
|
|
1905
|
+
createPrimaryKeySql(table, columnNames) {
|
|
1906
|
+
const primaryKeyName = this.connection.namingStrategy.primaryKeyName(table, columnNames);
|
|
1907
|
+
const columnNamesString = columnNames
|
|
1908
|
+
.map((columnName) => `"${columnName}"`)
|
|
2834
1909
|
.join(", ");
|
|
2835
|
-
return new Query_1.Query(
|
|
2836
|
-
}
|
|
1910
|
+
return new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} ADD CONSTRAINT "${primaryKeyName}" PRIMARY KEY (${columnNamesString})`);
|
|
1911
|
+
}
|
|
2837
1912
|
/**
|
|
2838
1913
|
* Builds drop primary key sql.
|
|
2839
1914
|
*/
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
return new Query_1.Query(
|
|
2844
|
-
}
|
|
1915
|
+
dropPrimaryKeySql(table) {
|
|
1916
|
+
const columnNames = table.primaryColumns.map((column) => column.name);
|
|
1917
|
+
const primaryKeyName = this.connection.namingStrategy.primaryKeyName(table, columnNames);
|
|
1918
|
+
return new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} DROP CONSTRAINT "${primaryKeyName}"`);
|
|
1919
|
+
}
|
|
2845
1920
|
/**
|
|
2846
1921
|
* Builds create check constraint sql.
|
|
2847
1922
|
*/
|
|
2848
|
-
|
|
2849
|
-
return new Query_1.Query(
|
|
2850
|
-
}
|
|
1923
|
+
createCheckConstraintSql(table, checkConstraint) {
|
|
1924
|
+
return new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} ADD CONSTRAINT "${checkConstraint.name}" CHECK (${checkConstraint.expression})`);
|
|
1925
|
+
}
|
|
2851
1926
|
/**
|
|
2852
1927
|
* Builds drop check constraint sql.
|
|
2853
1928
|
*/
|
|
2854
|
-
|
|
2855
|
-
|
|
1929
|
+
dropCheckConstraintSql(table, checkOrName) {
|
|
1930
|
+
const checkName = InstanceChecker_1.InstanceChecker.isTableCheck(checkOrName)
|
|
2856
1931
|
? checkOrName.name
|
|
2857
1932
|
: checkOrName;
|
|
2858
|
-
return new Query_1.Query(
|
|
2859
|
-
}
|
|
1933
|
+
return new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} DROP CONSTRAINT "${checkName}"`);
|
|
1934
|
+
}
|
|
2860
1935
|
/**
|
|
2861
1936
|
* Builds create foreign key sql.
|
|
2862
1937
|
*/
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
.map(
|
|
1938
|
+
createForeignKeySql(tableOrName, foreignKey) {
|
|
1939
|
+
const columnNames = foreignKey.columnNames
|
|
1940
|
+
.map((column) => `"` + column + `"`)
|
|
2866
1941
|
.join(", ");
|
|
2867
|
-
|
|
2868
|
-
.map(
|
|
1942
|
+
const referencedColumnNames = foreignKey.referencedColumnNames
|
|
1943
|
+
.map((column) => `"` + column + `"`)
|
|
2869
1944
|
.join(",");
|
|
2870
|
-
|
|
2871
|
-
|
|
1945
|
+
let sql = `ALTER TABLE ${this.escapePath(tableOrName)} ADD CONSTRAINT "${foreignKey.name}" FOREIGN KEY (${columnNames}) ` +
|
|
1946
|
+
`REFERENCES ${this.escapePath(this.getTablePath(foreignKey))}(${referencedColumnNames})`;
|
|
2872
1947
|
// SAP HANA does not have "NO ACTION" option for FK's
|
|
2873
1948
|
if (foreignKey.onDelete) {
|
|
2874
|
-
|
|
1949
|
+
const onDelete = foreignKey.onDelete === "NO ACTION"
|
|
2875
1950
|
? "RESTRICT"
|
|
2876
1951
|
: foreignKey.onDelete;
|
|
2877
|
-
sql +=
|
|
1952
|
+
sql += ` ON DELETE ${onDelete}`;
|
|
2878
1953
|
}
|
|
2879
1954
|
if (foreignKey.onUpdate) {
|
|
2880
|
-
|
|
1955
|
+
const onUpdate = foreignKey.onUpdate === "NO ACTION"
|
|
2881
1956
|
? "RESTRICT"
|
|
2882
1957
|
: foreignKey.onUpdate;
|
|
2883
|
-
sql +=
|
|
1958
|
+
sql += ` ON UPDATE ${onUpdate}`;
|
|
2884
1959
|
}
|
|
2885
1960
|
if (foreignKey.deferrable) {
|
|
2886
|
-
sql +=
|
|
1961
|
+
sql += ` ${foreignKey.deferrable}`;
|
|
2887
1962
|
}
|
|
2888
1963
|
return new Query_1.Query(sql);
|
|
2889
|
-
}
|
|
1964
|
+
}
|
|
2890
1965
|
/**
|
|
2891
1966
|
* Builds drop foreign key sql.
|
|
2892
1967
|
*/
|
|
2893
|
-
|
|
2894
|
-
|
|
1968
|
+
dropForeignKeySql(tableOrName, foreignKeyOrName) {
|
|
1969
|
+
const foreignKeyName = InstanceChecker_1.InstanceChecker.isTableForeignKey(foreignKeyOrName)
|
|
2895
1970
|
? foreignKeyOrName.name
|
|
2896
1971
|
: foreignKeyOrName;
|
|
2897
|
-
return new Query_1.Query(
|
|
2898
|
-
}
|
|
1972
|
+
return new Query_1.Query(`ALTER TABLE ${this.escapePath(tableOrName)} DROP CONSTRAINT "${foreignKeyName}"`);
|
|
1973
|
+
}
|
|
2899
1974
|
/**
|
|
2900
1975
|
* Escapes given table or view path.
|
|
2901
1976
|
*/
|
|
2902
|
-
|
|
2903
|
-
|
|
1977
|
+
escapePath(target) {
|
|
1978
|
+
const { schema, tableName } = this.driver.parseTableName(target);
|
|
2904
1979
|
if (schema) {
|
|
2905
|
-
return "
|
|
1980
|
+
return `"${schema}"."${tableName}"`;
|
|
2906
1981
|
}
|
|
2907
|
-
return "
|
|
2908
|
-
}
|
|
1982
|
+
return `"${tableName}"`;
|
|
1983
|
+
}
|
|
2909
1984
|
/**
|
|
2910
1985
|
* Concat database name and schema name to the foreign key name.
|
|
2911
1986
|
* Needs because FK name is relevant to the schema and database.
|
|
2912
1987
|
*/
|
|
2913
|
-
|
|
2914
|
-
|
|
1988
|
+
buildForeignKeyName(fkName, schemaName, dbName) {
|
|
1989
|
+
let joinedFkName = fkName;
|
|
2915
1990
|
if (schemaName)
|
|
2916
1991
|
joinedFkName = schemaName + "." + joinedFkName;
|
|
2917
1992
|
if (dbName)
|
|
2918
1993
|
joinedFkName = dbName + "." + joinedFkName;
|
|
2919
1994
|
return joinedFkName;
|
|
2920
|
-
}
|
|
1995
|
+
}
|
|
2921
1996
|
/**
|
|
2922
1997
|
* Removes parenthesis around default value.
|
|
2923
1998
|
* Sql server returns default value with parenthesis around, e.g.
|
|
@@ -2925,17 +2000,17 @@ var SapQueryRunner = /** @class */ (function (_super) {
|
|
|
2925
2000
|
* ((1)) - for number
|
|
2926
2001
|
* (newsequentialId()) - for function
|
|
2927
2002
|
*/
|
|
2928
|
-
|
|
2003
|
+
removeParenthesisFromDefault(defaultValue) {
|
|
2929
2004
|
if (defaultValue.substr(0, 1) !== "(")
|
|
2930
2005
|
return defaultValue;
|
|
2931
|
-
|
|
2006
|
+
const normalizedDefault = defaultValue.substr(1, defaultValue.lastIndexOf(")") - 1);
|
|
2932
2007
|
return this.removeParenthesisFromDefault(normalizedDefault);
|
|
2933
|
-
}
|
|
2008
|
+
}
|
|
2934
2009
|
/**
|
|
2935
2010
|
* Builds a query for create column.
|
|
2936
2011
|
*/
|
|
2937
|
-
|
|
2938
|
-
|
|
2012
|
+
buildCreateColumnSql(column) {
|
|
2013
|
+
let c = `"${column.name}" ` + this.connection.driver.createFullType(column);
|
|
2939
2014
|
if (column.charset)
|
|
2940
2015
|
c += " CHARACTER SET " + column.charset;
|
|
2941
2016
|
if (column.collation)
|
|
@@ -2950,8 +2025,7 @@ var SapQueryRunner = /** @class */ (function (_super) {
|
|
|
2950
2025
|
column.generationStrategy === "increment")
|
|
2951
2026
|
c += " GENERATED ALWAYS AS IDENTITY";
|
|
2952
2027
|
return c;
|
|
2953
|
-
}
|
|
2954
|
-
|
|
2955
|
-
}(BaseQueryRunner_1.BaseQueryRunner));
|
|
2028
|
+
}
|
|
2029
|
+
}
|
|
2956
2030
|
exports.SapQueryRunner = SapQueryRunner;
|
|
2957
2031
|
//# sourceMappingURL=SapQueryRunner.js.map
|