taon-typeorm 18.0.18 → 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/assets/shared/shared_folder_info.txt +1 -1
- package/browser/README.md +24 -24
- 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/README.md +24 -24
- 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 +7 -34
- package/tmp-environment.json +8 -370
- package/websql/README.md +24 -24
- 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,40 +1,51 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.OracleQueryRunner = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
var InstanceChecker_1 = require("../../util/InstanceChecker");
|
|
4
|
+
const TransactionNotStartedError_1 = require("../../error/TransactionNotStartedError");
|
|
5
|
+
const TableColumn_1 = require("../../schema-builder/table/TableColumn");
|
|
6
|
+
const Table_1 = require("../../schema-builder/table/Table");
|
|
7
|
+
const TableForeignKey_1 = require("../../schema-builder/table/TableForeignKey");
|
|
8
|
+
const TableIndex_1 = require("../../schema-builder/table/TableIndex");
|
|
9
|
+
const QueryRunnerAlreadyReleasedError_1 = require("../../error/QueryRunnerAlreadyReleasedError");
|
|
10
|
+
const View_1 = require("../../schema-builder/view/View");
|
|
11
|
+
const Query_1 = require("../Query");
|
|
12
|
+
const QueryFailedError_1 = require("../../error/QueryFailedError");
|
|
13
|
+
const TableUnique_1 = require("../../schema-builder/table/TableUnique");
|
|
14
|
+
const Broadcaster_1 = require("../../subscriber/Broadcaster");
|
|
15
|
+
const BaseQueryRunner_1 = require("../../query-runner/BaseQueryRunner");
|
|
16
|
+
const OrmUtils_1 = require("../../util/OrmUtils");
|
|
17
|
+
const TableCheck_1 = require("../../schema-builder/table/TableCheck");
|
|
18
|
+
const error_1 = require("../../error");
|
|
19
|
+
const QueryResult_1 = require("../../query-runner/QueryResult");
|
|
20
|
+
const MetadataTableType_1 = require("../types/MetadataTableType");
|
|
21
|
+
const InstanceChecker_1 = require("../../util/InstanceChecker");
|
|
23
22
|
/**
|
|
24
23
|
* Runs queries on a single oracle database connection.
|
|
25
24
|
*/
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
class OracleQueryRunner extends BaseQueryRunner_1.BaseQueryRunner {
|
|
26
|
+
// -------------------------------------------------------------------------
|
|
27
|
+
// Public Implemented Properties
|
|
28
|
+
// -------------------------------------------------------------------------
|
|
29
|
+
/**
|
|
30
|
+
* Database driver used by connection.
|
|
31
|
+
*/
|
|
32
|
+
driver;
|
|
33
|
+
// -------------------------------------------------------------------------
|
|
34
|
+
// Protected Properties
|
|
35
|
+
// -------------------------------------------------------------------------
|
|
36
|
+
/**
|
|
37
|
+
* Promise used to obtain a database connection for a first time.
|
|
38
|
+
*/
|
|
39
|
+
databaseConnectionPromise;
|
|
28
40
|
// -------------------------------------------------------------------------
|
|
29
41
|
// Constructor
|
|
30
42
|
// -------------------------------------------------------------------------
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return _this;
|
|
43
|
+
constructor(driver, mode) {
|
|
44
|
+
super();
|
|
45
|
+
this.driver = driver;
|
|
46
|
+
this.connection = driver.connection;
|
|
47
|
+
this.broadcaster = new Broadcaster_1.Broadcaster(this);
|
|
48
|
+
this.mode = mode;
|
|
38
49
|
}
|
|
39
50
|
// -------------------------------------------------------------------------
|
|
40
51
|
// Public Methods
|
|
@@ -43,8 +54,7 @@ var OracleQueryRunner = /** @class */ (function (_super) {
|
|
|
43
54
|
* Creates/uses database connection from the connection pool to perform further operations.
|
|
44
55
|
* Returns obtained database connection.
|
|
45
56
|
*/
|
|
46
|
-
|
|
47
|
-
var _this = this;
|
|
57
|
+
connect() {
|
|
48
58
|
if (this.databaseConnection)
|
|
49
59
|
return Promise.resolve(this.databaseConnection);
|
|
50
60
|
if (this.databaseConnectionPromise)
|
|
@@ -52,2532 +62,1623 @@ var OracleQueryRunner = /** @class */ (function (_super) {
|
|
|
52
62
|
if (this.mode === "slave" && this.driver.isReplicated) {
|
|
53
63
|
this.databaseConnectionPromise = this.driver
|
|
54
64
|
.obtainSlaveConnection()
|
|
55
|
-
.then(
|
|
56
|
-
|
|
57
|
-
return
|
|
65
|
+
.then((connection) => {
|
|
66
|
+
this.databaseConnection = connection;
|
|
67
|
+
return this.databaseConnection;
|
|
58
68
|
});
|
|
59
69
|
}
|
|
60
70
|
else {
|
|
61
71
|
// master
|
|
62
72
|
this.databaseConnectionPromise = this.driver
|
|
63
73
|
.obtainMasterConnection()
|
|
64
|
-
.then(
|
|
65
|
-
|
|
66
|
-
return
|
|
74
|
+
.then((connection) => {
|
|
75
|
+
this.databaseConnection = connection;
|
|
76
|
+
return this.databaseConnection;
|
|
67
77
|
});
|
|
68
78
|
}
|
|
69
79
|
return this.databaseConnectionPromise;
|
|
70
|
-
}
|
|
80
|
+
}
|
|
71
81
|
/**
|
|
72
82
|
* Releases used database connection.
|
|
73
83
|
* You cannot use query runner methods once its released.
|
|
74
84
|
*/
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
return [2 /*return*/];
|
|
83
|
-
}
|
|
84
|
-
return [4 /*yield*/, this.databaseConnection.close()];
|
|
85
|
-
case 1:
|
|
86
|
-
_a.sent();
|
|
87
|
-
return [2 /*return*/];
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
};
|
|
85
|
+
async release() {
|
|
86
|
+
this.isReleased = true;
|
|
87
|
+
if (!this.databaseConnection) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
await this.databaseConnection.close();
|
|
91
|
+
}
|
|
92
92
|
/**
|
|
93
93
|
* Starts transaction.
|
|
94
94
|
*/
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
throw err_1;
|
|
121
|
-
case 4:
|
|
122
|
-
if (!(this.transactionDepth === 0)) return [3 /*break*/, 6];
|
|
123
|
-
return [4 /*yield*/, this.query("SET TRANSACTION ISOLATION LEVEL " + isolationLevel)];
|
|
124
|
-
case 5:
|
|
125
|
-
_a.sent();
|
|
126
|
-
return [3 /*break*/, 8];
|
|
127
|
-
case 6: return [4 /*yield*/, this.query("SAVEPOINT typeorm_".concat(this.transactionDepth))];
|
|
128
|
-
case 7:
|
|
129
|
-
_a.sent();
|
|
130
|
-
_a.label = 8;
|
|
131
|
-
case 8:
|
|
132
|
-
this.transactionDepth += 1;
|
|
133
|
-
return [4 /*yield*/, this.broadcaster.broadcast("AfterTransactionStart")];
|
|
134
|
-
case 9:
|
|
135
|
-
_a.sent();
|
|
136
|
-
return [2 /*return*/];
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
});
|
|
140
|
-
};
|
|
95
|
+
async startTransaction(isolationLevel = "READ COMMITTED") {
|
|
96
|
+
if (this.isReleased)
|
|
97
|
+
throw new QueryRunnerAlreadyReleasedError_1.QueryRunnerAlreadyReleasedError();
|
|
98
|
+
// await this.query("START TRANSACTION");
|
|
99
|
+
if (isolationLevel !== "SERIALIZABLE" &&
|
|
100
|
+
isolationLevel !== "READ COMMITTED") {
|
|
101
|
+
throw new error_1.TypeORMError(`Oracle only supports SERIALIZABLE and READ COMMITTED isolation`);
|
|
102
|
+
}
|
|
103
|
+
this.isTransactionActive = true;
|
|
104
|
+
try {
|
|
105
|
+
await this.broadcaster.broadcast("BeforeTransactionStart");
|
|
106
|
+
}
|
|
107
|
+
catch (err) {
|
|
108
|
+
this.isTransactionActive = false;
|
|
109
|
+
throw err;
|
|
110
|
+
}
|
|
111
|
+
if (this.transactionDepth === 0) {
|
|
112
|
+
await this.query("SET TRANSACTION ISOLATION LEVEL " + isolationLevel);
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
await this.query(`SAVEPOINT typeorm_${this.transactionDepth}`);
|
|
116
|
+
}
|
|
117
|
+
this.transactionDepth += 1;
|
|
118
|
+
await this.broadcaster.broadcast("AfterTransactionStart");
|
|
119
|
+
}
|
|
141
120
|
/**
|
|
142
121
|
* Commits transaction.
|
|
143
122
|
* Error will be thrown if transaction was not started.
|
|
144
123
|
*/
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
return [4 /*yield*/, this.query("COMMIT")];
|
|
157
|
-
case 2:
|
|
158
|
-
_a.sent();
|
|
159
|
-
this.isTransactionActive = false;
|
|
160
|
-
_a.label = 3;
|
|
161
|
-
case 3:
|
|
162
|
-
this.transactionDepth -= 1;
|
|
163
|
-
return [4 /*yield*/, this.broadcaster.broadcast("AfterTransactionCommit")];
|
|
164
|
-
case 4:
|
|
165
|
-
_a.sent();
|
|
166
|
-
return [2 /*return*/];
|
|
167
|
-
}
|
|
168
|
-
});
|
|
169
|
-
});
|
|
170
|
-
};
|
|
124
|
+
async commitTransaction() {
|
|
125
|
+
if (!this.isTransactionActive)
|
|
126
|
+
throw new TransactionNotStartedError_1.TransactionNotStartedError();
|
|
127
|
+
await this.broadcaster.broadcast("BeforeTransactionCommit");
|
|
128
|
+
if (this.transactionDepth === 1) {
|
|
129
|
+
await this.query("COMMIT");
|
|
130
|
+
this.isTransactionActive = false;
|
|
131
|
+
}
|
|
132
|
+
this.transactionDepth -= 1;
|
|
133
|
+
await this.broadcaster.broadcast("AfterTransactionCommit");
|
|
134
|
+
}
|
|
171
135
|
/**
|
|
172
136
|
* Rollbacks transaction.
|
|
173
137
|
* Error will be thrown if transaction was not started.
|
|
174
138
|
*/
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
return [3 /*break*/, 5];
|
|
190
|
-
case 3: return [4 /*yield*/, this.query("ROLLBACK")];
|
|
191
|
-
case 4:
|
|
192
|
-
_a.sent();
|
|
193
|
-
this.isTransactionActive = false;
|
|
194
|
-
_a.label = 5;
|
|
195
|
-
case 5:
|
|
196
|
-
this.transactionDepth -= 1;
|
|
197
|
-
return [4 /*yield*/, this.broadcaster.broadcast("AfterTransactionRollback")];
|
|
198
|
-
case 6:
|
|
199
|
-
_a.sent();
|
|
200
|
-
return [2 /*return*/];
|
|
201
|
-
}
|
|
202
|
-
});
|
|
203
|
-
});
|
|
204
|
-
};
|
|
139
|
+
async rollbackTransaction() {
|
|
140
|
+
if (!this.isTransactionActive)
|
|
141
|
+
throw new TransactionNotStartedError_1.TransactionNotStartedError();
|
|
142
|
+
await this.broadcaster.broadcast("BeforeTransactionRollback");
|
|
143
|
+
if (this.transactionDepth > 1) {
|
|
144
|
+
await this.query(`ROLLBACK TO SAVEPOINT typeorm_${this.transactionDepth - 1}`);
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
await this.query("ROLLBACK");
|
|
148
|
+
this.isTransactionActive = false;
|
|
149
|
+
}
|
|
150
|
+
this.transactionDepth -= 1;
|
|
151
|
+
await this.broadcaster.broadcast("AfterTransactionRollback");
|
|
152
|
+
}
|
|
205
153
|
/**
|
|
206
154
|
* Executes a given SQL query.
|
|
207
155
|
*/
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
}
|
|
260
|
-
if (useStructuredResult) {
|
|
261
|
-
return [2 /*return*/, result];
|
|
262
|
-
}
|
|
263
|
-
else {
|
|
264
|
-
return [2 /*return*/, result.raw];
|
|
265
|
-
}
|
|
266
|
-
return [3 /*break*/, 5];
|
|
267
|
-
case 4:
|
|
268
|
-
err_2 = _a.sent();
|
|
269
|
-
this.driver.connection.logger.logQueryError(err_2, query, parameters, this);
|
|
270
|
-
throw new QueryFailedError_1.QueryFailedError(query, parameters, err_2);
|
|
271
|
-
case 5: return [2 /*return*/];
|
|
272
|
-
}
|
|
273
|
-
});
|
|
274
|
-
});
|
|
275
|
-
};
|
|
156
|
+
async query(query, parameters, useStructuredResult = false) {
|
|
157
|
+
if (this.isReleased)
|
|
158
|
+
throw new QueryRunnerAlreadyReleasedError_1.QueryRunnerAlreadyReleasedError();
|
|
159
|
+
const databaseConnection = await this.connect();
|
|
160
|
+
this.driver.connection.logger.logQuery(query, parameters, this);
|
|
161
|
+
const queryStartTime = +new Date();
|
|
162
|
+
try {
|
|
163
|
+
const executionOptions = {
|
|
164
|
+
autoCommit: !this.isTransactionActive,
|
|
165
|
+
outFormat: this.driver.oracle.OBJECT,
|
|
166
|
+
};
|
|
167
|
+
const raw = await databaseConnection.execute(query, parameters || {}, executionOptions);
|
|
168
|
+
// log slow queries if maxQueryExecution time is set
|
|
169
|
+
const maxQueryExecutionTime = this.driver.options.maxQueryExecutionTime;
|
|
170
|
+
const queryEndTime = +new Date();
|
|
171
|
+
const queryExecutionTime = queryEndTime - queryStartTime;
|
|
172
|
+
if (maxQueryExecutionTime &&
|
|
173
|
+
queryExecutionTime > maxQueryExecutionTime)
|
|
174
|
+
this.driver.connection.logger.logQuerySlow(queryExecutionTime, query, parameters, this);
|
|
175
|
+
const result = new QueryResult_1.QueryResult();
|
|
176
|
+
result.raw =
|
|
177
|
+
raw.rows ||
|
|
178
|
+
raw.outBinds ||
|
|
179
|
+
raw.rowsAffected ||
|
|
180
|
+
raw.implicitResults;
|
|
181
|
+
if (raw?.hasOwnProperty("rows") && Array.isArray(raw.rows)) {
|
|
182
|
+
result.records = raw.rows;
|
|
183
|
+
}
|
|
184
|
+
if (raw?.hasOwnProperty("outBinds") &&
|
|
185
|
+
Array.isArray(raw.outBinds)) {
|
|
186
|
+
result.records = raw.outBinds;
|
|
187
|
+
}
|
|
188
|
+
if (raw?.hasOwnProperty("implicitResults") &&
|
|
189
|
+
Array.isArray(raw.implicitResults)) {
|
|
190
|
+
result.records = raw.implicitResults;
|
|
191
|
+
}
|
|
192
|
+
if (raw?.hasOwnProperty("rowsAffected")) {
|
|
193
|
+
result.affected = raw.rowsAffected;
|
|
194
|
+
}
|
|
195
|
+
if (useStructuredResult) {
|
|
196
|
+
return result;
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
return result.raw;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
catch (err) {
|
|
203
|
+
this.driver.connection.logger.logQueryError(err, query, parameters, this);
|
|
204
|
+
throw new QueryFailedError_1.QueryFailedError(query, parameters, err);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
276
207
|
/**
|
|
277
208
|
* Returns raw data stream.
|
|
278
209
|
*/
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
return [2 /*return*/, stream];
|
|
305
|
-
}
|
|
306
|
-
catch (err) {
|
|
307
|
-
this.driver.connection.logger.logQueryError(err, query, parameters, this);
|
|
308
|
-
throw new QueryFailedError_1.QueryFailedError(query, parameters, err);
|
|
309
|
-
}
|
|
310
|
-
return [2 /*return*/];
|
|
311
|
-
}
|
|
312
|
-
});
|
|
313
|
-
});
|
|
314
|
-
};
|
|
210
|
+
async stream(query, parameters, onEnd, onError) {
|
|
211
|
+
if (this.isReleased) {
|
|
212
|
+
throw new QueryRunnerAlreadyReleasedError_1.QueryRunnerAlreadyReleasedError();
|
|
213
|
+
}
|
|
214
|
+
const executionOptions = {
|
|
215
|
+
autoCommit: !this.isTransactionActive,
|
|
216
|
+
outFormat: this.driver.oracle.OBJECT,
|
|
217
|
+
};
|
|
218
|
+
const databaseConnection = await this.connect();
|
|
219
|
+
this.driver.connection.logger.logQuery(query, parameters, this);
|
|
220
|
+
try {
|
|
221
|
+
const stream = databaseConnection.queryStream(query, parameters, executionOptions);
|
|
222
|
+
if (onEnd) {
|
|
223
|
+
stream.on("end", onEnd);
|
|
224
|
+
}
|
|
225
|
+
if (onError) {
|
|
226
|
+
stream.on("error", onError);
|
|
227
|
+
}
|
|
228
|
+
return stream;
|
|
229
|
+
}
|
|
230
|
+
catch (err) {
|
|
231
|
+
this.driver.connection.logger.logQueryError(err, query, parameters, this);
|
|
232
|
+
throw new QueryFailedError_1.QueryFailedError(query, parameters, err);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
315
235
|
/**
|
|
316
236
|
* Returns all available database names including system databases.
|
|
317
237
|
*/
|
|
318
|
-
|
|
319
|
-
return
|
|
320
|
-
|
|
321
|
-
return [2 /*return*/, Promise.resolve([])];
|
|
322
|
-
});
|
|
323
|
-
});
|
|
324
|
-
};
|
|
238
|
+
async getDatabases() {
|
|
239
|
+
return Promise.resolve([]);
|
|
240
|
+
}
|
|
325
241
|
/**
|
|
326
242
|
* Returns all available schema names including system schemas.
|
|
327
243
|
* If database parameter specified, returns schemas of that database.
|
|
328
244
|
*/
|
|
329
|
-
|
|
330
|
-
return
|
|
331
|
-
|
|
332
|
-
return [2 /*return*/, Promise.resolve([])];
|
|
333
|
-
});
|
|
334
|
-
});
|
|
335
|
-
};
|
|
245
|
+
async getSchemas(database) {
|
|
246
|
+
return Promise.resolve([]);
|
|
247
|
+
}
|
|
336
248
|
/**
|
|
337
249
|
* Checks if database with the given name exist.
|
|
338
250
|
*/
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
return
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
query = _a.sent();
|
|
349
|
-
return [2 /*return*/, query.length > 0];
|
|
350
|
-
case 2:
|
|
351
|
-
e_1 = _a.sent();
|
|
352
|
-
return [2 /*return*/, false];
|
|
353
|
-
case 3: return [2 /*return*/];
|
|
354
|
-
}
|
|
355
|
-
});
|
|
356
|
-
});
|
|
357
|
-
};
|
|
251
|
+
async hasDatabase(database) {
|
|
252
|
+
try {
|
|
253
|
+
const query = await this.query(`SELECT 1 AS "exists" FROM global_name@"${database}"`);
|
|
254
|
+
return query.length > 0;
|
|
255
|
+
}
|
|
256
|
+
catch (e) {
|
|
257
|
+
return false;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
358
260
|
/**
|
|
359
261
|
* Loads currently using database
|
|
360
262
|
*/
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
switch (_a.label) {
|
|
366
|
-
case 0: return [4 /*yield*/, this.query("SELECT SYS_CONTEXT('USERENV','DB_NAME') AS \"db_name\" FROM dual")];
|
|
367
|
-
case 1:
|
|
368
|
-
query = _a.sent();
|
|
369
|
-
return [2 /*return*/, query[0]["db_name"]];
|
|
370
|
-
}
|
|
371
|
-
});
|
|
372
|
-
});
|
|
373
|
-
};
|
|
263
|
+
async getCurrentDatabase() {
|
|
264
|
+
const query = await this.query(`SELECT SYS_CONTEXT('USERENV','DB_NAME') AS "db_name" FROM dual`);
|
|
265
|
+
return query[0]["db_name"];
|
|
266
|
+
}
|
|
374
267
|
/**
|
|
375
268
|
* Checks if schema with the given name exist.
|
|
376
269
|
*/
|
|
377
|
-
|
|
378
|
-
return
|
|
379
|
-
|
|
380
|
-
return [2 /*return*/, Promise.resolve(false)];
|
|
381
|
-
});
|
|
382
|
-
});
|
|
383
|
-
};
|
|
270
|
+
async hasSchema(schema) {
|
|
271
|
+
return Promise.resolve(false);
|
|
272
|
+
}
|
|
384
273
|
/**
|
|
385
274
|
* Loads currently using database schema
|
|
386
275
|
*/
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
switch (_a.label) {
|
|
392
|
-
case 0: return [4 /*yield*/, this.query("SELECT SYS_CONTEXT('USERENV','CURRENT_SCHEMA') AS \"schema_name\" FROM dual")];
|
|
393
|
-
case 1:
|
|
394
|
-
query = _a.sent();
|
|
395
|
-
return [2 /*return*/, query[0]["schema_name"]];
|
|
396
|
-
}
|
|
397
|
-
});
|
|
398
|
-
});
|
|
399
|
-
};
|
|
276
|
+
async getCurrentSchema() {
|
|
277
|
+
const query = await this.query(`SELECT SYS_CONTEXT('USERENV','CURRENT_SCHEMA') AS "schema_name" FROM dual`);
|
|
278
|
+
return query[0]["schema_name"];
|
|
279
|
+
}
|
|
400
280
|
/**
|
|
401
281
|
* Checks if table with the given name exist in the database.
|
|
402
282
|
*/
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
tableName = this.driver.parseTableName(tableOrName).tableName;
|
|
410
|
-
sql = "SELECT \"TABLE_NAME\" FROM \"USER_TABLES\" WHERE \"TABLE_NAME\" = '".concat(tableName, "'");
|
|
411
|
-
return [4 /*yield*/, this.query(sql)];
|
|
412
|
-
case 1:
|
|
413
|
-
result = _a.sent();
|
|
414
|
-
return [2 /*return*/, result.length ? true : false];
|
|
415
|
-
}
|
|
416
|
-
});
|
|
417
|
-
});
|
|
418
|
-
};
|
|
283
|
+
async hasTable(tableOrName) {
|
|
284
|
+
const { tableName } = this.driver.parseTableName(tableOrName);
|
|
285
|
+
const sql = `SELECT "TABLE_NAME" FROM "USER_TABLES" WHERE "TABLE_NAME" = '${tableName}'`;
|
|
286
|
+
const result = await this.query(sql);
|
|
287
|
+
return result.length ? true : false;
|
|
288
|
+
}
|
|
419
289
|
/**
|
|
420
290
|
* Checks if column with the given name exist in the given table.
|
|
421
291
|
*/
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
tableName = this.driver.parseTableName(tableOrName).tableName;
|
|
429
|
-
sql = "SELECT \"COLUMN_NAME\" FROM \"USER_TAB_COLS\" WHERE \"TABLE_NAME\" = '".concat(tableName, "' AND \"COLUMN_NAME\" = '").concat(columnName, "'");
|
|
430
|
-
return [4 /*yield*/, this.query(sql)];
|
|
431
|
-
case 1:
|
|
432
|
-
result = _a.sent();
|
|
433
|
-
return [2 /*return*/, result.length ? true : false];
|
|
434
|
-
}
|
|
435
|
-
});
|
|
436
|
-
});
|
|
437
|
-
};
|
|
292
|
+
async hasColumn(tableOrName, columnName) {
|
|
293
|
+
const { tableName } = this.driver.parseTableName(tableOrName);
|
|
294
|
+
const sql = `SELECT "COLUMN_NAME" FROM "USER_TAB_COLS" WHERE "TABLE_NAME" = '${tableName}' AND "COLUMN_NAME" = '${columnName}'`;
|
|
295
|
+
const result = await this.query(sql);
|
|
296
|
+
return result.length ? true : false;
|
|
297
|
+
}
|
|
438
298
|
/**
|
|
439
299
|
* Creates a new database.
|
|
440
300
|
*/
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
_a.sent();
|
|
454
|
-
return [3 /*break*/, 4];
|
|
455
|
-
case 3:
|
|
456
|
-
e_2 = _a.sent();
|
|
457
|
-
// if (e instanceof QueryFailedError) {
|
|
458
|
-
if (e_2.message.includes("ORA-01100: database already mounted")) {
|
|
459
|
-
return [2 /*return*/];
|
|
460
|
-
}
|
|
461
|
-
// }
|
|
462
|
-
throw e_2;
|
|
463
|
-
case 4: return [3 /*break*/, 7];
|
|
464
|
-
case 5: return [4 /*yield*/, this.query("CREATE DATABASE \"".concat(database, "\""))];
|
|
465
|
-
case 6:
|
|
466
|
-
_a.sent();
|
|
467
|
-
_a.label = 7;
|
|
468
|
-
case 7: return [2 /*return*/];
|
|
301
|
+
async createDatabase(database, ifNotExist) {
|
|
302
|
+
// Even with `IF NOT EXISTS` we get:
|
|
303
|
+
// ORA-01501: CREATE DATABASE failed
|
|
304
|
+
// ORA-01100: database already mounted
|
|
305
|
+
if (ifNotExist) {
|
|
306
|
+
try {
|
|
307
|
+
await this.query(`CREATE DATABASE IF NOT EXISTS "${database}";`);
|
|
308
|
+
}
|
|
309
|
+
catch (e) {
|
|
310
|
+
// if (e instanceof QueryFailedError) {
|
|
311
|
+
if (e.message.includes("ORA-01100: database already mounted")) {
|
|
312
|
+
return;
|
|
469
313
|
}
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
314
|
+
// }
|
|
315
|
+
throw e;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
else {
|
|
319
|
+
await this.query(`CREATE DATABASE "${database}"`);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
473
322
|
/**
|
|
474
323
|
* Drops database.
|
|
475
324
|
*/
|
|
476
|
-
|
|
477
|
-
return
|
|
478
|
-
|
|
479
|
-
return [2 /*return*/, Promise.resolve()];
|
|
480
|
-
});
|
|
481
|
-
});
|
|
482
|
-
};
|
|
325
|
+
async dropDatabase(database, ifExist) {
|
|
326
|
+
return Promise.resolve();
|
|
327
|
+
}
|
|
483
328
|
/**
|
|
484
329
|
* Creates a new table schema.
|
|
485
330
|
*/
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
throw new error_1.TypeORMError("Schema create queries are not supported by Oracle driver.");
|
|
490
|
-
});
|
|
491
|
-
});
|
|
492
|
-
};
|
|
331
|
+
async createSchema(schemaPath, ifNotExist) {
|
|
332
|
+
throw new error_1.TypeORMError(`Schema create queries are not supported by Oracle driver.`);
|
|
333
|
+
}
|
|
493
334
|
/**
|
|
494
335
|
* Drops table schema.
|
|
495
336
|
*/
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
throw new error_1.TypeORMError("Schema drop queries are not supported by Oracle driver.");
|
|
500
|
-
});
|
|
501
|
-
});
|
|
502
|
-
};
|
|
337
|
+
async dropSchema(schemaPath, ifExist) {
|
|
338
|
+
throw new error_1.TypeORMError(`Schema drop queries are not supported by Oracle driver.`);
|
|
339
|
+
}
|
|
503
340
|
/**
|
|
504
341
|
* Creates a new table.
|
|
505
342
|
*/
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
upQueries.push(this.createTableSql(table, createForeignKeys));
|
|
528
|
-
downQueries.push(this.dropTableSql(table));
|
|
529
|
-
// if createForeignKeys is true, we must drop created foreign keys in down query.
|
|
530
|
-
// createTable does not need separate method to create foreign keys, because it create fk's in the same query with table creation.
|
|
531
|
-
if (createForeignKeys)
|
|
532
|
-
table.foreignKeys.forEach(function (foreignKey) {
|
|
533
|
-
return downQueries.push(_this.dropForeignKeySql(table, foreignKey));
|
|
534
|
-
});
|
|
535
|
-
if (createIndices) {
|
|
536
|
-
table.indices.forEach(function (index) {
|
|
537
|
-
// new index may be passed without name. In this case we generate index name manually.
|
|
538
|
-
if (!index.name)
|
|
539
|
-
index.name = _this.connection.namingStrategy.indexName(table, index.columnNames, index.where);
|
|
540
|
-
upQueries.push(_this.createIndexSql(table, index));
|
|
541
|
-
downQueries.push(_this.dropIndexSql(index));
|
|
542
|
-
});
|
|
543
|
-
}
|
|
544
|
-
generatedColumns = table.columns.filter(function (column) { return column.generatedType && column.asExpression; });
|
|
545
|
-
try {
|
|
546
|
-
for (generatedColumns_1 = tslib_1.__values(generatedColumns), generatedColumns_1_1 = generatedColumns_1.next(); !generatedColumns_1_1.done; generatedColumns_1_1 = generatedColumns_1.next()) {
|
|
547
|
-
column = generatedColumns_1_1.value;
|
|
548
|
-
insertQuery = this.insertTypeormMetadataSql({
|
|
549
|
-
table: table.name,
|
|
550
|
-
type: MetadataTableType_1.MetadataTableType.GENERATED_COLUMN,
|
|
551
|
-
name: column.name,
|
|
552
|
-
value: column.asExpression,
|
|
553
|
-
});
|
|
554
|
-
deleteQuery = this.deleteTypeormMetadataSql({
|
|
555
|
-
table: table.name,
|
|
556
|
-
type: MetadataTableType_1.MetadataTableType.GENERATED_COLUMN,
|
|
557
|
-
name: column.name,
|
|
558
|
-
});
|
|
559
|
-
upQueries.push(insertQuery);
|
|
560
|
-
downQueries.push(deleteQuery);
|
|
561
|
-
}
|
|
562
|
-
}
|
|
563
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
564
|
-
finally {
|
|
565
|
-
try {
|
|
566
|
-
if (generatedColumns_1_1 && !generatedColumns_1_1.done && (_a = generatedColumns_1.return)) _a.call(generatedColumns_1);
|
|
567
|
-
}
|
|
568
|
-
finally { if (e_3) throw e_3.error; }
|
|
569
|
-
}
|
|
570
|
-
return [4 /*yield*/, this.executeQueries(upQueries, downQueries)];
|
|
571
|
-
case 3:
|
|
572
|
-
_b.sent();
|
|
573
|
-
return [2 /*return*/];
|
|
574
|
-
}
|
|
343
|
+
async createTable(table, ifNotExist = false, createForeignKeys = true, createIndices = true) {
|
|
344
|
+
if (ifNotExist) {
|
|
345
|
+
const isTableExist = await this.hasTable(table);
|
|
346
|
+
if (isTableExist)
|
|
347
|
+
return Promise.resolve();
|
|
348
|
+
}
|
|
349
|
+
const upQueries = [];
|
|
350
|
+
const downQueries = [];
|
|
351
|
+
upQueries.push(this.createTableSql(table, createForeignKeys));
|
|
352
|
+
downQueries.push(this.dropTableSql(table));
|
|
353
|
+
// if createForeignKeys is true, we must drop created foreign keys in down query.
|
|
354
|
+
// createTable does not need separate method to create foreign keys, because it create fk's in the same query with table creation.
|
|
355
|
+
if (createForeignKeys)
|
|
356
|
+
table.foreignKeys.forEach((foreignKey) => downQueries.push(this.dropForeignKeySql(table, foreignKey)));
|
|
357
|
+
if (createIndices) {
|
|
358
|
+
table.indices.forEach((index) => {
|
|
359
|
+
// new index may be passed without name. In this case we generate index name manually.
|
|
360
|
+
if (!index.name)
|
|
361
|
+
index.name = this.connection.namingStrategy.indexName(table, index.columnNames, index.where);
|
|
362
|
+
upQueries.push(this.createIndexSql(table, index));
|
|
363
|
+
downQueries.push(this.dropIndexSql(index));
|
|
575
364
|
});
|
|
576
|
-
}
|
|
577
|
-
|
|
365
|
+
}
|
|
366
|
+
// if table have column with generated type, we must add the expression to the metadata table
|
|
367
|
+
const generatedColumns = table.columns.filter((column) => column.generatedType && column.asExpression);
|
|
368
|
+
for (const column of generatedColumns) {
|
|
369
|
+
const insertQuery = this.insertTypeormMetadataSql({
|
|
370
|
+
table: table.name,
|
|
371
|
+
type: MetadataTableType_1.MetadataTableType.GENERATED_COLUMN,
|
|
372
|
+
name: column.name,
|
|
373
|
+
value: column.asExpression,
|
|
374
|
+
});
|
|
375
|
+
const deleteQuery = this.deleteTypeormMetadataSql({
|
|
376
|
+
table: table.name,
|
|
377
|
+
type: MetadataTableType_1.MetadataTableType.GENERATED_COLUMN,
|
|
378
|
+
name: column.name,
|
|
379
|
+
});
|
|
380
|
+
upQueries.push(insertQuery);
|
|
381
|
+
downQueries.push(deleteQuery);
|
|
382
|
+
}
|
|
383
|
+
await this.executeQueries(upQueries, downQueries);
|
|
384
|
+
}
|
|
578
385
|
/**
|
|
579
386
|
* Drops the table.
|
|
580
387
|
*/
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
if (
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
if (!InstanceChecker_1.InstanceChecker.isTable(tableOrName)) return [3 /*break*/, 3];
|
|
601
|
-
_a = tableOrName;
|
|
602
|
-
return [3 /*break*/, 5];
|
|
603
|
-
case 3: return [4 /*yield*/, this.getCachedTable(tableOrName)];
|
|
604
|
-
case 4:
|
|
605
|
-
_a = _c.sent();
|
|
606
|
-
_c.label = 5;
|
|
607
|
-
case 5:
|
|
608
|
-
table = _a;
|
|
609
|
-
upQueries = [];
|
|
610
|
-
downQueries = [];
|
|
611
|
-
if (dropIndices) {
|
|
612
|
-
table.indices.forEach(function (index) {
|
|
613
|
-
upQueries.push(_this.dropIndexSql(index));
|
|
614
|
-
downQueries.push(_this.createIndexSql(table, index));
|
|
615
|
-
});
|
|
616
|
-
}
|
|
617
|
-
// if dropForeignKeys is true, we just drop the table, otherwise we also drop table foreign keys.
|
|
618
|
-
// createTable does not need separate method to create foreign keys, because it create fk's in the same query with table creation.
|
|
619
|
-
if (dropForeignKeys)
|
|
620
|
-
table.foreignKeys.forEach(function (foreignKey) {
|
|
621
|
-
return upQueries.push(_this.dropForeignKeySql(table, foreignKey));
|
|
622
|
-
});
|
|
623
|
-
upQueries.push(this.dropTableSql(table));
|
|
624
|
-
downQueries.push(this.createTableSql(table, createForeignKeys));
|
|
625
|
-
generatedColumns = table.columns.filter(function (column) { return column.generatedType && column.asExpression; });
|
|
626
|
-
try {
|
|
627
|
-
for (generatedColumns_2 = tslib_1.__values(generatedColumns), generatedColumns_2_1 = generatedColumns_2.next(); !generatedColumns_2_1.done; generatedColumns_2_1 = generatedColumns_2.next()) {
|
|
628
|
-
column = generatedColumns_2_1.value;
|
|
629
|
-
deleteQuery = this.deleteTypeormMetadataSql({
|
|
630
|
-
table: table.name,
|
|
631
|
-
type: MetadataTableType_1.MetadataTableType.GENERATED_COLUMN,
|
|
632
|
-
name: column.name,
|
|
633
|
-
});
|
|
634
|
-
insertQuery = this.insertTypeormMetadataSql({
|
|
635
|
-
table: table.name,
|
|
636
|
-
type: MetadataTableType_1.MetadataTableType.GENERATED_COLUMN,
|
|
637
|
-
name: column.name,
|
|
638
|
-
value: column.asExpression,
|
|
639
|
-
});
|
|
640
|
-
upQueries.push(deleteQuery);
|
|
641
|
-
downQueries.push(insertQuery);
|
|
642
|
-
}
|
|
643
|
-
}
|
|
644
|
-
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
645
|
-
finally {
|
|
646
|
-
try {
|
|
647
|
-
if (generatedColumns_2_1 && !generatedColumns_2_1.done && (_b = generatedColumns_2.return)) _b.call(generatedColumns_2);
|
|
648
|
-
}
|
|
649
|
-
finally { if (e_4) throw e_4.error; }
|
|
650
|
-
}
|
|
651
|
-
return [4 /*yield*/, this.executeQueries(upQueries, downQueries)];
|
|
652
|
-
case 6:
|
|
653
|
-
_c.sent();
|
|
654
|
-
return [2 /*return*/];
|
|
655
|
-
}
|
|
388
|
+
async dropTable(tableOrName, ifExist, dropForeignKeys = true, dropIndices = true) {
|
|
389
|
+
// It needs because if table does not exist and dropForeignKeys or dropIndices is true, we don't need
|
|
390
|
+
// to perform drop queries for foreign keys and indices.
|
|
391
|
+
if (ifExist) {
|
|
392
|
+
const isTableExist = await this.hasTable(tableOrName);
|
|
393
|
+
if (!isTableExist)
|
|
394
|
+
return Promise.resolve();
|
|
395
|
+
}
|
|
396
|
+
// if dropTable called with dropForeignKeys = true, we must create foreign keys in down query.
|
|
397
|
+
const createForeignKeys = dropForeignKeys;
|
|
398
|
+
const table = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
|
|
399
|
+
? tableOrName
|
|
400
|
+
: await this.getCachedTable(tableOrName);
|
|
401
|
+
const upQueries = [];
|
|
402
|
+
const downQueries = [];
|
|
403
|
+
if (dropIndices) {
|
|
404
|
+
table.indices.forEach((index) => {
|
|
405
|
+
upQueries.push(this.dropIndexSql(index));
|
|
406
|
+
downQueries.push(this.createIndexSql(table, index));
|
|
656
407
|
});
|
|
657
|
-
}
|
|
658
|
-
|
|
408
|
+
}
|
|
409
|
+
// if dropForeignKeys is true, we just drop the table, otherwise we also drop table foreign keys.
|
|
410
|
+
// createTable does not need separate method to create foreign keys, because it create fk's in the same query with table creation.
|
|
411
|
+
if (dropForeignKeys)
|
|
412
|
+
table.foreignKeys.forEach((foreignKey) => upQueries.push(this.dropForeignKeySql(table, foreignKey)));
|
|
413
|
+
upQueries.push(this.dropTableSql(table));
|
|
414
|
+
downQueries.push(this.createTableSql(table, createForeignKeys));
|
|
415
|
+
// if table had columns with generated type, we must remove the expression from the metadata table
|
|
416
|
+
const generatedColumns = table.columns.filter((column) => column.generatedType && column.asExpression);
|
|
417
|
+
for (const column of generatedColumns) {
|
|
418
|
+
const deleteQuery = this.deleteTypeormMetadataSql({
|
|
419
|
+
table: table.name,
|
|
420
|
+
type: MetadataTableType_1.MetadataTableType.GENERATED_COLUMN,
|
|
421
|
+
name: column.name,
|
|
422
|
+
});
|
|
423
|
+
const insertQuery = this.insertTypeormMetadataSql({
|
|
424
|
+
table: table.name,
|
|
425
|
+
type: MetadataTableType_1.MetadataTableType.GENERATED_COLUMN,
|
|
426
|
+
name: column.name,
|
|
427
|
+
value: column.asExpression,
|
|
428
|
+
});
|
|
429
|
+
upQueries.push(deleteQuery);
|
|
430
|
+
downQueries.push(insertQuery);
|
|
431
|
+
}
|
|
432
|
+
await this.executeQueries(upQueries, downQueries);
|
|
433
|
+
}
|
|
659
434
|
/**
|
|
660
435
|
* Creates a new view.
|
|
661
436
|
*/
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
upQueries.push(this.insertViewDefinitionSql(view));
|
|
674
|
-
downQueries.push(this.dropViewSql(view));
|
|
675
|
-
if (syncWithMetadata)
|
|
676
|
-
downQueries.push(this.deleteViewDefinitionSql(view));
|
|
677
|
-
return [4 /*yield*/, this.executeQueries(upQueries, downQueries)];
|
|
678
|
-
case 1:
|
|
679
|
-
_a.sent();
|
|
680
|
-
return [2 /*return*/];
|
|
681
|
-
}
|
|
682
|
-
});
|
|
683
|
-
});
|
|
684
|
-
};
|
|
437
|
+
async createView(view, syncWithMetadata = false) {
|
|
438
|
+
const upQueries = [];
|
|
439
|
+
const downQueries = [];
|
|
440
|
+
upQueries.push(this.createViewSql(view));
|
|
441
|
+
if (syncWithMetadata)
|
|
442
|
+
upQueries.push(this.insertViewDefinitionSql(view));
|
|
443
|
+
downQueries.push(this.dropViewSql(view));
|
|
444
|
+
if (syncWithMetadata)
|
|
445
|
+
downQueries.push(this.deleteViewDefinitionSql(view));
|
|
446
|
+
await this.executeQueries(upQueries, downQueries);
|
|
447
|
+
}
|
|
685
448
|
/**
|
|
686
449
|
* Drops the view.
|
|
687
450
|
*/
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
downQueries = [];
|
|
700
|
-
upQueries.push(this.deleteViewDefinitionSql(view));
|
|
701
|
-
upQueries.push(this.dropViewSql(view));
|
|
702
|
-
downQueries.push(this.insertViewDefinitionSql(view));
|
|
703
|
-
downQueries.push(this.createViewSql(view));
|
|
704
|
-
return [4 /*yield*/, this.executeQueries(upQueries, downQueries)];
|
|
705
|
-
case 2:
|
|
706
|
-
_a.sent();
|
|
707
|
-
return [2 /*return*/];
|
|
708
|
-
}
|
|
709
|
-
});
|
|
710
|
-
});
|
|
711
|
-
};
|
|
451
|
+
async dropView(target) {
|
|
452
|
+
const viewName = InstanceChecker_1.InstanceChecker.isView(target) ? target.name : target;
|
|
453
|
+
const view = await this.getCachedView(viewName);
|
|
454
|
+
const upQueries = [];
|
|
455
|
+
const downQueries = [];
|
|
456
|
+
upQueries.push(this.deleteViewDefinitionSql(view));
|
|
457
|
+
upQueries.push(this.dropViewSql(view));
|
|
458
|
+
downQueries.push(this.insertViewDefinitionSql(view));
|
|
459
|
+
downQueries.push(this.createViewSql(view));
|
|
460
|
+
await this.executeQueries(upQueries, downQueries);
|
|
461
|
+
}
|
|
712
462
|
/**
|
|
713
463
|
* Renames the given table.
|
|
714
464
|
*/
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
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
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
newTable.foreignKeys.forEach(function (foreignKey) {
|
|
779
|
-
var oldForeignKeyName = _this.connection.namingStrategy.foreignKeyName(oldTable, foreignKey.columnNames, _this.getTablePath(foreignKey), foreignKey.referencedColumnNames);
|
|
780
|
-
// Skip renaming if foreign key has user defined constraint name
|
|
781
|
-
if (foreignKey.name !== oldForeignKeyName)
|
|
782
|
-
return;
|
|
783
|
-
// build new constraint name
|
|
784
|
-
var newForeignKeyName = _this.connection.namingStrategy.foreignKeyName(newTable, foreignKey.columnNames, _this.getTablePath(foreignKey), foreignKey.referencedColumnNames);
|
|
785
|
-
// build queries
|
|
786
|
-
upQueries.push(new Query_1.Query("ALTER TABLE ".concat(_this.escapePath(newTable), " RENAME CONSTRAINT \"").concat(foreignKey.name, "\" TO \"").concat(newForeignKeyName, "\"")));
|
|
787
|
-
downQueries.push(new Query_1.Query("ALTER TABLE ".concat(_this.escapePath(newTable), " RENAME CONSTRAINT \"").concat(newForeignKeyName, "\" TO \"").concat(foreignKey.name, "\"")));
|
|
788
|
-
// replace constraint name
|
|
789
|
-
foreignKey.name = newForeignKeyName;
|
|
790
|
-
});
|
|
791
|
-
return [4 /*yield*/, this.executeQueries(upQueries, downQueries)
|
|
792
|
-
// rename old table and replace it in cached tabled;
|
|
793
|
-
];
|
|
794
|
-
case 4:
|
|
795
|
-
_c.sent();
|
|
796
|
-
// rename old table and replace it in cached tabled;
|
|
797
|
-
oldTable.name = newTable.name;
|
|
798
|
-
this.replaceCachedTable(oldTable, newTable);
|
|
799
|
-
return [2 /*return*/];
|
|
800
|
-
}
|
|
801
|
-
});
|
|
465
|
+
async renameTable(oldTableOrName, newTableName) {
|
|
466
|
+
const upQueries = [];
|
|
467
|
+
const downQueries = [];
|
|
468
|
+
const oldTable = InstanceChecker_1.InstanceChecker.isTable(oldTableOrName)
|
|
469
|
+
? oldTableOrName
|
|
470
|
+
: await this.getCachedTable(oldTableOrName);
|
|
471
|
+
let newTable = oldTable.clone();
|
|
472
|
+
const { database: dbName, tableName: oldTableName } = this.driver.parseTableName(oldTable);
|
|
473
|
+
newTable.name = dbName ? `${dbName}.${newTableName}` : newTableName;
|
|
474
|
+
// rename table
|
|
475
|
+
upQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(oldTable)} RENAME TO "${newTableName}"`));
|
|
476
|
+
downQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(newTable)} RENAME TO "${oldTableName}"`));
|
|
477
|
+
// rename primary key constraint
|
|
478
|
+
if (newTable.primaryColumns.length > 0 &&
|
|
479
|
+
!newTable.primaryColumns[0].primaryKeyConstraintName) {
|
|
480
|
+
const columnNames = newTable.primaryColumns.map((column) => column.name);
|
|
481
|
+
const oldPkName = this.connection.namingStrategy.primaryKeyName(oldTable, columnNames);
|
|
482
|
+
const newPkName = this.connection.namingStrategy.primaryKeyName(newTable, columnNames);
|
|
483
|
+
// build queries
|
|
484
|
+
upQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(newTable)} RENAME CONSTRAINT "${oldPkName}" TO "${newPkName}"`));
|
|
485
|
+
downQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(newTable)} RENAME CONSTRAINT "${newPkName}" TO "${oldPkName}"`));
|
|
486
|
+
}
|
|
487
|
+
// rename unique constraints
|
|
488
|
+
newTable.uniques.forEach((unique) => {
|
|
489
|
+
const oldUniqueName = this.connection.namingStrategy.uniqueConstraintName(oldTable, unique.columnNames);
|
|
490
|
+
// Skip renaming if Unique has user defined constraint name
|
|
491
|
+
if (unique.name !== oldUniqueName)
|
|
492
|
+
return;
|
|
493
|
+
// build new constraint name
|
|
494
|
+
const newUniqueName = this.connection.namingStrategy.uniqueConstraintName(newTable, unique.columnNames);
|
|
495
|
+
// build queries
|
|
496
|
+
upQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(newTable)} RENAME CONSTRAINT "${unique.name}" TO "${newUniqueName}"`));
|
|
497
|
+
downQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(newTable)} RENAME CONSTRAINT "${newUniqueName}" TO "${unique.name}"`));
|
|
498
|
+
// replace constraint name
|
|
499
|
+
unique.name = newUniqueName;
|
|
500
|
+
});
|
|
501
|
+
// rename index constraints
|
|
502
|
+
newTable.indices.forEach((index) => {
|
|
503
|
+
const oldIndexName = this.connection.namingStrategy.indexName(oldTable, index.columnNames, index.where);
|
|
504
|
+
// Skip renaming if Index has user defined constraint name
|
|
505
|
+
if (index.name !== oldIndexName)
|
|
506
|
+
return;
|
|
507
|
+
// build new constraint name
|
|
508
|
+
const newIndexName = this.connection.namingStrategy.indexName(newTable, index.columnNames, index.where);
|
|
509
|
+
// build queries
|
|
510
|
+
upQueries.push(new Query_1.Query(`ALTER INDEX "${index.name}" RENAME TO "${newIndexName}"`));
|
|
511
|
+
downQueries.push(new Query_1.Query(`ALTER INDEX "${newIndexName}" RENAME TO "${index.name}"`));
|
|
512
|
+
// replace constraint name
|
|
513
|
+
index.name = newIndexName;
|
|
514
|
+
});
|
|
515
|
+
// rename foreign key constraints
|
|
516
|
+
newTable.foreignKeys.forEach((foreignKey) => {
|
|
517
|
+
const oldForeignKeyName = this.connection.namingStrategy.foreignKeyName(oldTable, foreignKey.columnNames, this.getTablePath(foreignKey), foreignKey.referencedColumnNames);
|
|
518
|
+
// Skip renaming if foreign key has user defined constraint name
|
|
519
|
+
if (foreignKey.name !== oldForeignKeyName)
|
|
520
|
+
return;
|
|
521
|
+
// build new constraint name
|
|
522
|
+
const newForeignKeyName = this.connection.namingStrategy.foreignKeyName(newTable, foreignKey.columnNames, this.getTablePath(foreignKey), foreignKey.referencedColumnNames);
|
|
523
|
+
// build queries
|
|
524
|
+
upQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(newTable)} RENAME CONSTRAINT "${foreignKey.name}" TO "${newForeignKeyName}"`));
|
|
525
|
+
downQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(newTable)} RENAME CONSTRAINT "${newForeignKeyName}" TO "${foreignKey.name}"`));
|
|
526
|
+
// replace constraint name
|
|
527
|
+
foreignKey.name = newForeignKeyName;
|
|
802
528
|
});
|
|
803
|
-
|
|
529
|
+
await this.executeQueries(upQueries, downQueries);
|
|
530
|
+
// rename old table and replace it in cached tabled;
|
|
531
|
+
oldTable.name = newTable.name;
|
|
532
|
+
this.replaceCachedTable(oldTable, newTable);
|
|
533
|
+
}
|
|
804
534
|
/**
|
|
805
535
|
* Creates a new column from the column in the table.
|
|
806
536
|
*/
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
index.columnNames[0] === column.name;
|
|
854
|
-
});
|
|
855
|
-
if (columnIndex) {
|
|
856
|
-
clonedTable.indices.splice(clonedTable.indices.indexOf(columnIndex), 1);
|
|
857
|
-
upQueries.push(this.createIndexSql(table, columnIndex));
|
|
858
|
-
downQueries.push(this.dropIndexSql(columnIndex));
|
|
859
|
-
}
|
|
860
|
-
// create unique constraint
|
|
861
|
-
if (column.isUnique) {
|
|
862
|
-
uniqueConstraint = new TableUnique_1.TableUnique({
|
|
863
|
-
name: this.connection.namingStrategy.uniqueConstraintName(table, [column.name]),
|
|
864
|
-
columnNames: [column.name],
|
|
865
|
-
});
|
|
866
|
-
clonedTable.uniques.push(uniqueConstraint);
|
|
867
|
-
upQueries.push(new Query_1.Query("ALTER TABLE ".concat(this.escapePath(table), " ADD CONSTRAINT \"").concat(uniqueConstraint.name, "\" UNIQUE (\"").concat(column.name, "\")")));
|
|
868
|
-
downQueries.push(new Query_1.Query("ALTER TABLE ".concat(this.escapePath(table), " DROP CONSTRAINT \"").concat(uniqueConstraint.name, "\"")));
|
|
869
|
-
}
|
|
870
|
-
if (column.generatedType && column.asExpression) {
|
|
871
|
-
insertQuery = this.insertTypeormMetadataSql({
|
|
872
|
-
table: table.name,
|
|
873
|
-
type: MetadataTableType_1.MetadataTableType.GENERATED_COLUMN,
|
|
874
|
-
name: column.name,
|
|
875
|
-
value: column.asExpression,
|
|
876
|
-
});
|
|
877
|
-
deleteQuery = this.deleteTypeormMetadataSql({
|
|
878
|
-
table: table.name,
|
|
879
|
-
type: MetadataTableType_1.MetadataTableType.GENERATED_COLUMN,
|
|
880
|
-
name: column.name,
|
|
881
|
-
});
|
|
882
|
-
upQueries.push(insertQuery);
|
|
883
|
-
downQueries.push(deleteQuery);
|
|
884
|
-
}
|
|
885
|
-
return [4 /*yield*/, this.executeQueries(upQueries, downQueries)];
|
|
886
|
-
case 4:
|
|
887
|
-
_b.sent();
|
|
888
|
-
clonedTable.addColumn(column);
|
|
889
|
-
this.replaceCachedTable(table, clonedTable);
|
|
890
|
-
return [2 /*return*/];
|
|
891
|
-
}
|
|
537
|
+
async addColumn(tableOrName, column) {
|
|
538
|
+
const table = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
|
|
539
|
+
? tableOrName
|
|
540
|
+
: await this.getCachedTable(tableOrName);
|
|
541
|
+
const clonedTable = table.clone();
|
|
542
|
+
const upQueries = [];
|
|
543
|
+
const downQueries = [];
|
|
544
|
+
upQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} ADD ${this.buildCreateColumnSql(column)}`));
|
|
545
|
+
downQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} DROP COLUMN "${column.name}"`));
|
|
546
|
+
// create or update primary key constraint
|
|
547
|
+
if (column.isPrimary) {
|
|
548
|
+
const primaryColumns = clonedTable.primaryColumns;
|
|
549
|
+
// if table already have primary key, me must drop it and recreate again
|
|
550
|
+
if (primaryColumns.length > 0) {
|
|
551
|
+
const pkName = primaryColumns[0].primaryKeyConstraintName
|
|
552
|
+
? primaryColumns[0].primaryKeyConstraintName
|
|
553
|
+
: this.connection.namingStrategy.primaryKeyName(clonedTable, primaryColumns.map((column) => column.name));
|
|
554
|
+
const columnNames = primaryColumns
|
|
555
|
+
.map((column) => `"${column.name}"`)
|
|
556
|
+
.join(", ");
|
|
557
|
+
upQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} DROP CONSTRAINT "${pkName}"`));
|
|
558
|
+
downQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} ADD CONSTRAINT "${pkName}" PRIMARY KEY (${columnNames})`));
|
|
559
|
+
}
|
|
560
|
+
primaryColumns.push(column);
|
|
561
|
+
const pkName = primaryColumns[0].primaryKeyConstraintName
|
|
562
|
+
? primaryColumns[0].primaryKeyConstraintName
|
|
563
|
+
: this.connection.namingStrategy.primaryKeyName(clonedTable, primaryColumns.map((column) => column.name));
|
|
564
|
+
const columnNames = primaryColumns
|
|
565
|
+
.map((column) => `"${column.name}"`)
|
|
566
|
+
.join(", ");
|
|
567
|
+
upQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} ADD CONSTRAINT "${pkName}" PRIMARY KEY (${columnNames})`));
|
|
568
|
+
downQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} DROP CONSTRAINT "${pkName}"`));
|
|
569
|
+
}
|
|
570
|
+
// create column index
|
|
571
|
+
const columnIndex = clonedTable.indices.find((index) => index.columnNames.length === 1 &&
|
|
572
|
+
index.columnNames[0] === column.name);
|
|
573
|
+
if (columnIndex) {
|
|
574
|
+
clonedTable.indices.splice(clonedTable.indices.indexOf(columnIndex), 1);
|
|
575
|
+
upQueries.push(this.createIndexSql(table, columnIndex));
|
|
576
|
+
downQueries.push(this.dropIndexSql(columnIndex));
|
|
577
|
+
}
|
|
578
|
+
// create unique constraint
|
|
579
|
+
if (column.isUnique) {
|
|
580
|
+
const uniqueConstraint = new TableUnique_1.TableUnique({
|
|
581
|
+
name: this.connection.namingStrategy.uniqueConstraintName(table, [column.name]),
|
|
582
|
+
columnNames: [column.name],
|
|
892
583
|
});
|
|
893
|
-
|
|
894
|
-
|
|
584
|
+
clonedTable.uniques.push(uniqueConstraint);
|
|
585
|
+
upQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} ADD CONSTRAINT "${uniqueConstraint.name}" UNIQUE ("${column.name}")`));
|
|
586
|
+
downQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} DROP CONSTRAINT "${uniqueConstraint.name}"`));
|
|
587
|
+
}
|
|
588
|
+
if (column.generatedType && column.asExpression) {
|
|
589
|
+
const insertQuery = this.insertTypeormMetadataSql({
|
|
590
|
+
table: table.name,
|
|
591
|
+
type: MetadataTableType_1.MetadataTableType.GENERATED_COLUMN,
|
|
592
|
+
name: column.name,
|
|
593
|
+
value: column.asExpression,
|
|
594
|
+
});
|
|
595
|
+
const deleteQuery = this.deleteTypeormMetadataSql({
|
|
596
|
+
table: table.name,
|
|
597
|
+
type: MetadataTableType_1.MetadataTableType.GENERATED_COLUMN,
|
|
598
|
+
name: column.name,
|
|
599
|
+
});
|
|
600
|
+
upQueries.push(insertQuery);
|
|
601
|
+
downQueries.push(deleteQuery);
|
|
602
|
+
}
|
|
603
|
+
await this.executeQueries(upQueries, downQueries);
|
|
604
|
+
clonedTable.addColumn(column);
|
|
605
|
+
this.replaceCachedTable(table, clonedTable);
|
|
606
|
+
}
|
|
895
607
|
/**
|
|
896
608
|
* Creates a new columns from the column in the table.
|
|
897
609
|
*/
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
switch (_b.label) {
|
|
904
|
-
case 0:
|
|
905
|
-
_b.trys.push([0, 5, 6, 7]);
|
|
906
|
-
columns_1 = tslib_1.__values(columns), columns_1_1 = columns_1.next();
|
|
907
|
-
_b.label = 1;
|
|
908
|
-
case 1:
|
|
909
|
-
if (!!columns_1_1.done) return [3 /*break*/, 4];
|
|
910
|
-
column = columns_1_1.value;
|
|
911
|
-
return [4 /*yield*/, this.addColumn(tableOrName, column)];
|
|
912
|
-
case 2:
|
|
913
|
-
_b.sent();
|
|
914
|
-
_b.label = 3;
|
|
915
|
-
case 3:
|
|
916
|
-
columns_1_1 = columns_1.next();
|
|
917
|
-
return [3 /*break*/, 1];
|
|
918
|
-
case 4: return [3 /*break*/, 7];
|
|
919
|
-
case 5:
|
|
920
|
-
e_5_1 = _b.sent();
|
|
921
|
-
e_5 = { error: e_5_1 };
|
|
922
|
-
return [3 /*break*/, 7];
|
|
923
|
-
case 6:
|
|
924
|
-
try {
|
|
925
|
-
if (columns_1_1 && !columns_1_1.done && (_a = columns_1.return)) _a.call(columns_1);
|
|
926
|
-
}
|
|
927
|
-
finally { if (e_5) throw e_5.error; }
|
|
928
|
-
return [7 /*endfinally*/];
|
|
929
|
-
case 7: return [2 /*return*/];
|
|
930
|
-
}
|
|
931
|
-
});
|
|
932
|
-
});
|
|
933
|
-
};
|
|
610
|
+
async addColumns(tableOrName, columns) {
|
|
611
|
+
for (const column of columns) {
|
|
612
|
+
await this.addColumn(tableOrName, column);
|
|
613
|
+
}
|
|
614
|
+
}
|
|
934
615
|
/**
|
|
935
616
|
* Renames column in the given table.
|
|
936
617
|
*/
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
throw new error_1.TypeORMError("Column \"".concat(oldTableColumnOrName, "\" was not found in the ").concat(this.escapePath(table), " table."));
|
|
957
|
-
newColumn = undefined;
|
|
958
|
-
if (InstanceChecker_1.InstanceChecker.isTableColumn(newTableColumnOrName)) {
|
|
959
|
-
newColumn = newTableColumnOrName;
|
|
960
|
-
}
|
|
961
|
-
else {
|
|
962
|
-
newColumn = oldColumn.clone();
|
|
963
|
-
newColumn.name = newTableColumnOrName;
|
|
964
|
-
}
|
|
965
|
-
return [4 /*yield*/, this.changeColumn(table, oldColumn, newColumn)];
|
|
966
|
-
case 4:
|
|
967
|
-
_b.sent();
|
|
968
|
-
return [2 /*return*/];
|
|
969
|
-
}
|
|
970
|
-
});
|
|
971
|
-
});
|
|
972
|
-
};
|
|
618
|
+
async renameColumn(tableOrName, oldTableColumnOrName, newTableColumnOrName) {
|
|
619
|
+
const table = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
|
|
620
|
+
? tableOrName
|
|
621
|
+
: await this.getCachedTable(tableOrName);
|
|
622
|
+
const oldColumn = InstanceChecker_1.InstanceChecker.isTableColumn(oldTableColumnOrName)
|
|
623
|
+
? oldTableColumnOrName
|
|
624
|
+
: table.columns.find((c) => c.name === oldTableColumnOrName);
|
|
625
|
+
if (!oldColumn)
|
|
626
|
+
throw new error_1.TypeORMError(`Column "${oldTableColumnOrName}" was not found in the ${this.escapePath(table)} table.`);
|
|
627
|
+
let newColumn = undefined;
|
|
628
|
+
if (InstanceChecker_1.InstanceChecker.isTableColumn(newTableColumnOrName)) {
|
|
629
|
+
newColumn = newTableColumnOrName;
|
|
630
|
+
}
|
|
631
|
+
else {
|
|
632
|
+
newColumn = oldColumn.clone();
|
|
633
|
+
newColumn.name = newTableColumnOrName;
|
|
634
|
+
}
|
|
635
|
+
await this.changeColumn(table, oldColumn, newColumn);
|
|
636
|
+
}
|
|
973
637
|
/**
|
|
974
638
|
* Changes a column in the table.
|
|
975
639
|
*/
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
return [3 /*break*/, 8];
|
|
1021
|
-
case 6:
|
|
1022
|
-
if (newColumn.name !== oldColumn.name) {
|
|
1023
|
-
// rename column
|
|
1024
|
-
upQueries.push(new Query_1.Query("ALTER TABLE ".concat(this.escapePath(table), " RENAME COLUMN \"").concat(oldColumn.name, "\" TO \"").concat(newColumn.name, "\"")));
|
|
1025
|
-
downQueries.push(new Query_1.Query("ALTER TABLE ".concat(this.escapePath(table), " RENAME COLUMN \"").concat(newColumn.name, "\" TO \"").concat(oldColumn.name, "\"")));
|
|
1026
|
-
// rename column primary key constraint
|
|
1027
|
-
if (oldColumn.isPrimary === true &&
|
|
1028
|
-
!oldColumn.primaryKeyConstraintName) {
|
|
1029
|
-
primaryColumns = clonedTable.primaryColumns;
|
|
1030
|
-
columnNames = primaryColumns.map(function (column) { return column.name; });
|
|
1031
|
-
oldPkName = this.connection.namingStrategy.primaryKeyName(clonedTable, columnNames);
|
|
1032
|
-
// replace old column name with new column name
|
|
1033
|
-
columnNames.splice(columnNames.indexOf(oldColumn.name), 1);
|
|
1034
|
-
columnNames.push(newColumn.name);
|
|
1035
|
-
newPkName = this.connection.namingStrategy.primaryKeyName(clonedTable, columnNames);
|
|
1036
|
-
upQueries.push(new Query_1.Query("ALTER TABLE ".concat(this.escapePath(table), " RENAME CONSTRAINT \"").concat(oldPkName, "\" TO \"").concat(newPkName, "\"")));
|
|
1037
|
-
downQueries.push(new Query_1.Query("ALTER TABLE ".concat(this.escapePath(table), " RENAME CONSTRAINT \"").concat(newPkName, "\" TO \"").concat(oldPkName, "\"")));
|
|
1038
|
-
}
|
|
1039
|
-
// rename unique constraints
|
|
1040
|
-
clonedTable.findColumnUniques(oldColumn).forEach(function (unique) {
|
|
1041
|
-
var oldUniqueName = _this.connection.namingStrategy.uniqueConstraintName(clonedTable, unique.columnNames);
|
|
1042
|
-
// Skip renaming if Unique has user defined constraint name
|
|
1043
|
-
if (unique.name !== oldUniqueName)
|
|
1044
|
-
return;
|
|
1045
|
-
// build new constraint name
|
|
1046
|
-
unique.columnNames.splice(unique.columnNames.indexOf(oldColumn.name), 1);
|
|
1047
|
-
unique.columnNames.push(newColumn.name);
|
|
1048
|
-
var newUniqueName = _this.connection.namingStrategy.uniqueConstraintName(clonedTable, unique.columnNames);
|
|
1049
|
-
// build queries
|
|
1050
|
-
upQueries.push(new Query_1.Query("ALTER TABLE ".concat(_this.escapePath(table), " RENAME CONSTRAINT \"").concat(unique.name, "\" TO \"").concat(newUniqueName, "\"")));
|
|
1051
|
-
downQueries.push(new Query_1.Query("ALTER TABLE ".concat(_this.escapePath(table), " RENAME CONSTRAINT \"").concat(newUniqueName, "\" TO \"").concat(unique.name, "\"")));
|
|
1052
|
-
// replace constraint name
|
|
1053
|
-
unique.name = newUniqueName;
|
|
1054
|
-
});
|
|
1055
|
-
// rename index constraints
|
|
1056
|
-
clonedTable.findColumnIndices(oldColumn).forEach(function (index) {
|
|
1057
|
-
var oldIndexName = _this.connection.namingStrategy.indexName(clonedTable, index.columnNames, index.where);
|
|
1058
|
-
// Skip renaming if Index has user defined constraint name
|
|
1059
|
-
if (index.name !== oldIndexName)
|
|
1060
|
-
return;
|
|
1061
|
-
// build new constraint name
|
|
1062
|
-
index.columnNames.splice(index.columnNames.indexOf(oldColumn.name), 1);
|
|
1063
|
-
index.columnNames.push(newColumn.name);
|
|
1064
|
-
var newIndexName = _this.connection.namingStrategy.indexName(clonedTable, index.columnNames, index.where);
|
|
1065
|
-
// build queries
|
|
1066
|
-
upQueries.push(new Query_1.Query("ALTER INDEX \"".concat(index.name, "\" RENAME TO \"").concat(newIndexName, "\"")));
|
|
1067
|
-
downQueries.push(new Query_1.Query("ALTER INDEX \"".concat(newIndexName, "\" RENAME TO \"").concat(index.name, "\"")));
|
|
1068
|
-
// replace constraint name
|
|
1069
|
-
index.name = newIndexName;
|
|
1070
|
-
});
|
|
1071
|
-
// rename foreign key constraints
|
|
1072
|
-
clonedTable
|
|
1073
|
-
.findColumnForeignKeys(oldColumn)
|
|
1074
|
-
.forEach(function (foreignKey) {
|
|
1075
|
-
var foreignKeyName = _this.connection.namingStrategy.foreignKeyName(clonedTable, foreignKey.columnNames, _this.getTablePath(foreignKey), foreignKey.referencedColumnNames);
|
|
1076
|
-
// Skip renaming if foreign key has user defined constraint name
|
|
1077
|
-
if (foreignKey.name !== foreignKeyName)
|
|
1078
|
-
return;
|
|
1079
|
-
// build new constraint name
|
|
1080
|
-
foreignKey.columnNames.splice(foreignKey.columnNames.indexOf(oldColumn.name), 1);
|
|
1081
|
-
foreignKey.columnNames.push(newColumn.name);
|
|
1082
|
-
var newForeignKeyName = _this.connection.namingStrategy.foreignKeyName(clonedTable, foreignKey.columnNames, _this.getTablePath(foreignKey), foreignKey.referencedColumnNames);
|
|
1083
|
-
// build queries
|
|
1084
|
-
upQueries.push(new Query_1.Query("ALTER TABLE ".concat(_this.escapePath(table), " RENAME CONSTRAINT \"").concat(foreignKey.name, "\" TO \"").concat(newForeignKeyName, "\"")));
|
|
1085
|
-
downQueries.push(new Query_1.Query("ALTER TABLE ".concat(_this.escapePath(table), " RENAME CONSTRAINT \"").concat(newForeignKeyName, "\" TO \"").concat(foreignKey.name, "\"")));
|
|
1086
|
-
// replace constraint name
|
|
1087
|
-
foreignKey.name = newForeignKeyName;
|
|
1088
|
-
});
|
|
1089
|
-
oldTableColumn = clonedTable.columns.find(function (column) { return column.name === oldColumn.name; });
|
|
1090
|
-
clonedTable.columns[clonedTable.columns.indexOf(oldTableColumn)].name = newColumn.name;
|
|
1091
|
-
oldColumn.name = newColumn.name;
|
|
1092
|
-
}
|
|
1093
|
-
if (this.isColumnChanged(oldColumn, newColumn, true)) {
|
|
1094
|
-
defaultUp = "";
|
|
1095
|
-
defaultDown = "";
|
|
1096
|
-
nullableUp = "";
|
|
1097
|
-
nullableDown = "";
|
|
1098
|
-
// changing column default
|
|
1099
|
-
if (newColumn.default !== null &&
|
|
1100
|
-
newColumn.default !== undefined) {
|
|
1101
|
-
defaultUp = "DEFAULT ".concat(newColumn.default);
|
|
1102
|
-
if (oldColumn.default !== null &&
|
|
1103
|
-
oldColumn.default !== undefined) {
|
|
1104
|
-
defaultDown = "DEFAULT ".concat(oldColumn.default);
|
|
1105
|
-
}
|
|
1106
|
-
else {
|
|
1107
|
-
defaultDown = "DEFAULT NULL";
|
|
1108
|
-
}
|
|
1109
|
-
}
|
|
1110
|
-
else if (oldColumn.default !== null &&
|
|
1111
|
-
oldColumn.default !== undefined) {
|
|
1112
|
-
defaultUp = "DEFAULT NULL";
|
|
1113
|
-
defaultDown = "DEFAULT ".concat(oldColumn.default);
|
|
1114
|
-
}
|
|
1115
|
-
// changing column isNullable property
|
|
1116
|
-
if (newColumn.isNullable !== oldColumn.isNullable) {
|
|
1117
|
-
if (newColumn.isNullable === true) {
|
|
1118
|
-
nullableUp = "NULL";
|
|
1119
|
-
nullableDown = "NOT NULL";
|
|
1120
|
-
}
|
|
1121
|
-
else {
|
|
1122
|
-
nullableUp = "NOT NULL";
|
|
1123
|
-
nullableDown = "NULL";
|
|
1124
|
-
}
|
|
1125
|
-
}
|
|
1126
|
-
upQueries.push(new Query_1.Query("ALTER TABLE ".concat(this.escapePath(table), " MODIFY \"").concat(oldColumn.name, "\" ").concat(this.connection.driver.createFullType(newColumn), " ").concat(defaultUp, " ").concat(nullableUp)));
|
|
1127
|
-
downQueries.push(new Query_1.Query("ALTER TABLE ".concat(this.escapePath(table), " MODIFY \"").concat(oldColumn.name, "\" ").concat(this.connection.driver.createFullType(oldColumn), " ").concat(defaultDown, " ").concat(nullableDown)));
|
|
1128
|
-
}
|
|
1129
|
-
if (newColumn.isPrimary !== oldColumn.isPrimary) {
|
|
1130
|
-
primaryColumns = clonedTable.primaryColumns;
|
|
1131
|
-
// if primary column state changed, we must always drop existed constraint.
|
|
1132
|
-
if (primaryColumns.length > 0) {
|
|
1133
|
-
pkName = primaryColumns[0].primaryKeyConstraintName
|
|
1134
|
-
? primaryColumns[0].primaryKeyConstraintName
|
|
1135
|
-
: this.connection.namingStrategy.primaryKeyName(clonedTable, primaryColumns.map(function (column) { return column.name; }));
|
|
1136
|
-
columnNames = primaryColumns
|
|
1137
|
-
.map(function (column) { return "\"".concat(column.name, "\""); })
|
|
1138
|
-
.join(", ");
|
|
1139
|
-
upQueries.push(new Query_1.Query("ALTER TABLE ".concat(this.escapePath(table), " DROP CONSTRAINT \"").concat(pkName, "\"")));
|
|
1140
|
-
downQueries.push(new Query_1.Query("ALTER TABLE ".concat(this.escapePath(table), " ADD CONSTRAINT \"").concat(pkName, "\" PRIMARY KEY (").concat(columnNames, ")")));
|
|
1141
|
-
}
|
|
1142
|
-
if (newColumn.isPrimary === true) {
|
|
1143
|
-
primaryColumns.push(newColumn);
|
|
1144
|
-
column = clonedTable.columns.find(function (column) { return column.name === newColumn.name; });
|
|
1145
|
-
column.isPrimary = true;
|
|
1146
|
-
pkName = primaryColumns[0].primaryKeyConstraintName
|
|
1147
|
-
? primaryColumns[0].primaryKeyConstraintName
|
|
1148
|
-
: this.connection.namingStrategy.primaryKeyName(clonedTable, primaryColumns.map(function (column) { return column.name; }));
|
|
1149
|
-
columnNames = primaryColumns
|
|
1150
|
-
.map(function (column) { return "\"".concat(column.name, "\""); })
|
|
1151
|
-
.join(", ");
|
|
1152
|
-
upQueries.push(new Query_1.Query("ALTER TABLE ".concat(this.escapePath(table), " ADD CONSTRAINT \"").concat(pkName, "\" PRIMARY KEY (").concat(columnNames, ")")));
|
|
1153
|
-
downQueries.push(new Query_1.Query("ALTER TABLE ".concat(this.escapePath(table), " DROP CONSTRAINT \"").concat(pkName, "\"")));
|
|
1154
|
-
}
|
|
1155
|
-
else {
|
|
1156
|
-
primaryColumn = primaryColumns.find(function (c) { return c.name === newColumn.name; });
|
|
1157
|
-
primaryColumns.splice(primaryColumns.indexOf(primaryColumn), 1);
|
|
1158
|
-
column = clonedTable.columns.find(function (column) { return column.name === newColumn.name; });
|
|
1159
|
-
column.isPrimary = false;
|
|
1160
|
-
// if we have another primary keys, we must recreate constraint.
|
|
1161
|
-
if (primaryColumns.length > 0) {
|
|
1162
|
-
pkName = primaryColumns[0]
|
|
1163
|
-
.primaryKeyConstraintName
|
|
1164
|
-
? primaryColumns[0].primaryKeyConstraintName
|
|
1165
|
-
: this.connection.namingStrategy.primaryKeyName(clonedTable, primaryColumns.map(function (column) { return column.name; }));
|
|
1166
|
-
columnNames = primaryColumns
|
|
1167
|
-
.map(function (column) { return "\"".concat(column.name, "\""); })
|
|
1168
|
-
.join(", ");
|
|
1169
|
-
upQueries.push(new Query_1.Query("ALTER TABLE ".concat(this.escapePath(table), " ADD CONSTRAINT \"").concat(pkName, "\" PRIMARY KEY (").concat(columnNames, ")")));
|
|
1170
|
-
downQueries.push(new Query_1.Query("ALTER TABLE ".concat(this.escapePath(table), " DROP CONSTRAINT \"").concat(pkName, "\"")));
|
|
1171
|
-
}
|
|
1172
|
-
}
|
|
1173
|
-
}
|
|
1174
|
-
if (newColumn.isUnique !== oldColumn.isUnique) {
|
|
1175
|
-
if (newColumn.isUnique === true) {
|
|
1176
|
-
uniqueConstraint = new TableUnique_1.TableUnique({
|
|
1177
|
-
name: this.connection.namingStrategy.uniqueConstraintName(table, [newColumn.name]),
|
|
1178
|
-
columnNames: [newColumn.name],
|
|
1179
|
-
});
|
|
1180
|
-
clonedTable.uniques.push(uniqueConstraint);
|
|
1181
|
-
upQueries.push(new Query_1.Query("ALTER TABLE ".concat(this.escapePath(table), " ADD CONSTRAINT \"").concat(uniqueConstraint.name, "\" UNIQUE (\"").concat(newColumn.name, "\")")));
|
|
1182
|
-
downQueries.push(new Query_1.Query("ALTER TABLE ".concat(this.escapePath(table), " DROP CONSTRAINT \"").concat(uniqueConstraint.name, "\"")));
|
|
1183
|
-
}
|
|
1184
|
-
else {
|
|
1185
|
-
uniqueConstraint = clonedTable.uniques.find(function (unique) {
|
|
1186
|
-
return (unique.columnNames.length === 1 &&
|
|
1187
|
-
!!unique.columnNames.find(function (columnName) {
|
|
1188
|
-
return columnName === newColumn.name;
|
|
1189
|
-
}));
|
|
1190
|
-
});
|
|
1191
|
-
clonedTable.uniques.splice(clonedTable.uniques.indexOf(uniqueConstraint), 1);
|
|
1192
|
-
upQueries.push(new Query_1.Query("ALTER TABLE ".concat(this.escapePath(table), " DROP CONSTRAINT \"").concat(uniqueConstraint.name, "\"")));
|
|
1193
|
-
downQueries.push(new Query_1.Query("ALTER TABLE ".concat(this.escapePath(table), " ADD CONSTRAINT \"").concat(uniqueConstraint.name, "\" UNIQUE (\"").concat(newColumn.name, "\")")));
|
|
1194
|
-
}
|
|
1195
|
-
}
|
|
1196
|
-
return [4 /*yield*/, this.executeQueries(upQueries, downQueries)];
|
|
1197
|
-
case 7:
|
|
1198
|
-
_b.sent();
|
|
1199
|
-
this.replaceCachedTable(table, clonedTable);
|
|
1200
|
-
_b.label = 8;
|
|
1201
|
-
case 8: return [2 /*return*/];
|
|
640
|
+
async changeColumn(tableOrName, oldTableColumnOrName, newColumn) {
|
|
641
|
+
const table = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
|
|
642
|
+
? tableOrName
|
|
643
|
+
: await this.getCachedTable(tableOrName);
|
|
644
|
+
let clonedTable = table.clone();
|
|
645
|
+
const upQueries = [];
|
|
646
|
+
const downQueries = [];
|
|
647
|
+
const oldColumn = InstanceChecker_1.InstanceChecker.isTableColumn(oldTableColumnOrName)
|
|
648
|
+
? oldTableColumnOrName
|
|
649
|
+
: table.columns.find((column) => column.name === oldTableColumnOrName);
|
|
650
|
+
if (!oldColumn)
|
|
651
|
+
throw new error_1.TypeORMError(`Column "${oldTableColumnOrName}" was not found in the ${this.escapePath(table)} table.`);
|
|
652
|
+
if ((newColumn.isGenerated !== oldColumn.isGenerated &&
|
|
653
|
+
newColumn.generationStrategy !== "uuid") ||
|
|
654
|
+
oldColumn.type !== newColumn.type ||
|
|
655
|
+
oldColumn.length !== newColumn.length ||
|
|
656
|
+
oldColumn.generatedType !== newColumn.generatedType ||
|
|
657
|
+
oldColumn.asExpression !== newColumn.asExpression) {
|
|
658
|
+
// Oracle does not support changing of IDENTITY column, so we must drop column and recreate it again.
|
|
659
|
+
// Also, we recreate column if column type changed
|
|
660
|
+
await this.dropColumn(table, oldColumn);
|
|
661
|
+
await this.addColumn(table, newColumn);
|
|
662
|
+
// update cloned table
|
|
663
|
+
clonedTable = table.clone();
|
|
664
|
+
}
|
|
665
|
+
else {
|
|
666
|
+
if (newColumn.name !== oldColumn.name) {
|
|
667
|
+
// rename column
|
|
668
|
+
upQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} RENAME COLUMN "${oldColumn.name}" TO "${newColumn.name}"`));
|
|
669
|
+
downQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} RENAME COLUMN "${newColumn.name}" TO "${oldColumn.name}"`));
|
|
670
|
+
// rename column primary key constraint
|
|
671
|
+
if (oldColumn.isPrimary === true &&
|
|
672
|
+
!oldColumn.primaryKeyConstraintName) {
|
|
673
|
+
const primaryColumns = clonedTable.primaryColumns;
|
|
674
|
+
// build old primary constraint name
|
|
675
|
+
const columnNames = primaryColumns.map((column) => column.name);
|
|
676
|
+
const oldPkName = this.connection.namingStrategy.primaryKeyName(clonedTable, columnNames);
|
|
677
|
+
// replace old column name with new column name
|
|
678
|
+
columnNames.splice(columnNames.indexOf(oldColumn.name), 1);
|
|
679
|
+
columnNames.push(newColumn.name);
|
|
680
|
+
// build new primary constraint name
|
|
681
|
+
const newPkName = this.connection.namingStrategy.primaryKeyName(clonedTable, columnNames);
|
|
682
|
+
upQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} RENAME CONSTRAINT "${oldPkName}" TO "${newPkName}"`));
|
|
683
|
+
downQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} RENAME CONSTRAINT "${newPkName}" TO "${oldPkName}"`));
|
|
1202
684
|
}
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
685
|
+
// rename unique constraints
|
|
686
|
+
clonedTable.findColumnUniques(oldColumn).forEach((unique) => {
|
|
687
|
+
const oldUniqueName = this.connection.namingStrategy.uniqueConstraintName(clonedTable, unique.columnNames);
|
|
688
|
+
// Skip renaming if Unique has user defined constraint name
|
|
689
|
+
if (unique.name !== oldUniqueName)
|
|
690
|
+
return;
|
|
691
|
+
// build new constraint name
|
|
692
|
+
unique.columnNames.splice(unique.columnNames.indexOf(oldColumn.name), 1);
|
|
693
|
+
unique.columnNames.push(newColumn.name);
|
|
694
|
+
const newUniqueName = this.connection.namingStrategy.uniqueConstraintName(clonedTable, unique.columnNames);
|
|
695
|
+
// build queries
|
|
696
|
+
upQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} RENAME CONSTRAINT "${unique.name}" TO "${newUniqueName}"`));
|
|
697
|
+
downQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} RENAME CONSTRAINT "${newUniqueName}" TO "${unique.name}"`));
|
|
698
|
+
// replace constraint name
|
|
699
|
+
unique.name = newUniqueName;
|
|
700
|
+
});
|
|
701
|
+
// rename index constraints
|
|
702
|
+
clonedTable.findColumnIndices(oldColumn).forEach((index) => {
|
|
703
|
+
const oldIndexName = this.connection.namingStrategy.indexName(clonedTable, index.columnNames, index.where);
|
|
704
|
+
// Skip renaming if Index has user defined constraint name
|
|
705
|
+
if (index.name !== oldIndexName)
|
|
706
|
+
return;
|
|
707
|
+
// build new constraint name
|
|
708
|
+
index.columnNames.splice(index.columnNames.indexOf(oldColumn.name), 1);
|
|
709
|
+
index.columnNames.push(newColumn.name);
|
|
710
|
+
const newIndexName = this.connection.namingStrategy.indexName(clonedTable, index.columnNames, index.where);
|
|
711
|
+
// build queries
|
|
712
|
+
upQueries.push(new Query_1.Query(`ALTER INDEX "${index.name}" RENAME TO "${newIndexName}"`));
|
|
713
|
+
downQueries.push(new Query_1.Query(`ALTER INDEX "${newIndexName}" RENAME TO "${index.name}"`));
|
|
714
|
+
// replace constraint name
|
|
715
|
+
index.name = newIndexName;
|
|
716
|
+
});
|
|
717
|
+
// rename foreign key constraints
|
|
718
|
+
clonedTable
|
|
719
|
+
.findColumnForeignKeys(oldColumn)
|
|
720
|
+
.forEach((foreignKey) => {
|
|
721
|
+
const foreignKeyName = this.connection.namingStrategy.foreignKeyName(clonedTable, foreignKey.columnNames, this.getTablePath(foreignKey), foreignKey.referencedColumnNames);
|
|
722
|
+
// Skip renaming if foreign key has user defined constraint name
|
|
723
|
+
if (foreignKey.name !== foreignKeyName)
|
|
724
|
+
return;
|
|
725
|
+
// build new constraint name
|
|
726
|
+
foreignKey.columnNames.splice(foreignKey.columnNames.indexOf(oldColumn.name), 1);
|
|
727
|
+
foreignKey.columnNames.push(newColumn.name);
|
|
728
|
+
const newForeignKeyName = this.connection.namingStrategy.foreignKeyName(clonedTable, foreignKey.columnNames, this.getTablePath(foreignKey), foreignKey.referencedColumnNames);
|
|
729
|
+
// build queries
|
|
730
|
+
upQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} RENAME CONSTRAINT "${foreignKey.name}" TO "${newForeignKeyName}"`));
|
|
731
|
+
downQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} RENAME CONSTRAINT "${newForeignKeyName}" TO "${foreignKey.name}"`));
|
|
732
|
+
// replace constraint name
|
|
733
|
+
foreignKey.name = newForeignKeyName;
|
|
734
|
+
});
|
|
735
|
+
// rename old column in the Table object
|
|
736
|
+
const oldTableColumn = clonedTable.columns.find((column) => column.name === oldColumn.name);
|
|
737
|
+
clonedTable.columns[clonedTable.columns.indexOf(oldTableColumn)].name = newColumn.name;
|
|
738
|
+
oldColumn.name = newColumn.name;
|
|
739
|
+
}
|
|
740
|
+
if (this.isColumnChanged(oldColumn, newColumn, true)) {
|
|
741
|
+
let defaultUp = "";
|
|
742
|
+
let defaultDown = "";
|
|
743
|
+
let nullableUp = "";
|
|
744
|
+
let nullableDown = "";
|
|
745
|
+
// changing column default
|
|
746
|
+
if (newColumn.default !== null &&
|
|
747
|
+
newColumn.default !== undefined) {
|
|
748
|
+
defaultUp = `DEFAULT ${newColumn.default}`;
|
|
749
|
+
if (oldColumn.default !== null &&
|
|
750
|
+
oldColumn.default !== undefined) {
|
|
751
|
+
defaultDown = `DEFAULT ${oldColumn.default}`;
|
|
752
|
+
}
|
|
753
|
+
else {
|
|
754
|
+
defaultDown = "DEFAULT NULL";
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
else if (oldColumn.default !== null &&
|
|
758
|
+
oldColumn.default !== undefined) {
|
|
759
|
+
defaultUp = "DEFAULT NULL";
|
|
760
|
+
defaultDown = `DEFAULT ${oldColumn.default}`;
|
|
761
|
+
}
|
|
762
|
+
// changing column isNullable property
|
|
763
|
+
if (newColumn.isNullable !== oldColumn.isNullable) {
|
|
764
|
+
if (newColumn.isNullable === true) {
|
|
765
|
+
nullableUp = "NULL";
|
|
766
|
+
nullableDown = "NOT NULL";
|
|
767
|
+
}
|
|
768
|
+
else {
|
|
769
|
+
nullableUp = "NOT NULL";
|
|
770
|
+
nullableDown = "NULL";
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
upQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} MODIFY "${oldColumn.name}" ${this.connection.driver.createFullType(newColumn)} ${defaultUp} ${nullableUp}`));
|
|
774
|
+
downQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} MODIFY "${oldColumn.name}" ${this.connection.driver.createFullType(oldColumn)} ${defaultDown} ${nullableDown}`));
|
|
775
|
+
}
|
|
776
|
+
if (newColumn.isPrimary !== oldColumn.isPrimary) {
|
|
777
|
+
const primaryColumns = clonedTable.primaryColumns;
|
|
778
|
+
// if primary column state changed, we must always drop existed constraint.
|
|
779
|
+
if (primaryColumns.length > 0) {
|
|
780
|
+
const pkName = primaryColumns[0].primaryKeyConstraintName
|
|
781
|
+
? primaryColumns[0].primaryKeyConstraintName
|
|
782
|
+
: this.connection.namingStrategy.primaryKeyName(clonedTable, primaryColumns.map((column) => column.name));
|
|
783
|
+
const columnNames = primaryColumns
|
|
784
|
+
.map((column) => `"${column.name}"`)
|
|
785
|
+
.join(", ");
|
|
786
|
+
upQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} DROP CONSTRAINT "${pkName}"`));
|
|
787
|
+
downQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} ADD CONSTRAINT "${pkName}" PRIMARY KEY (${columnNames})`));
|
|
788
|
+
}
|
|
789
|
+
if (newColumn.isPrimary === true) {
|
|
790
|
+
primaryColumns.push(newColumn);
|
|
791
|
+
// update column in table
|
|
792
|
+
const column = clonedTable.columns.find((column) => column.name === newColumn.name);
|
|
793
|
+
column.isPrimary = true;
|
|
794
|
+
const pkName = primaryColumns[0].primaryKeyConstraintName
|
|
795
|
+
? primaryColumns[0].primaryKeyConstraintName
|
|
796
|
+
: this.connection.namingStrategy.primaryKeyName(clonedTable, primaryColumns.map((column) => column.name));
|
|
797
|
+
const columnNames = primaryColumns
|
|
798
|
+
.map((column) => `"${column.name}"`)
|
|
799
|
+
.join(", ");
|
|
800
|
+
upQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} ADD CONSTRAINT "${pkName}" PRIMARY KEY (${columnNames})`));
|
|
801
|
+
downQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} DROP CONSTRAINT "${pkName}"`));
|
|
802
|
+
}
|
|
803
|
+
else {
|
|
804
|
+
const primaryColumn = primaryColumns.find((c) => c.name === newColumn.name);
|
|
805
|
+
primaryColumns.splice(primaryColumns.indexOf(primaryColumn), 1);
|
|
806
|
+
// update column in table
|
|
807
|
+
const column = clonedTable.columns.find((column) => column.name === newColumn.name);
|
|
808
|
+
column.isPrimary = false;
|
|
809
|
+
// if we have another primary keys, we must recreate constraint.
|
|
810
|
+
if (primaryColumns.length > 0) {
|
|
811
|
+
const pkName = primaryColumns[0]
|
|
812
|
+
.primaryKeyConstraintName
|
|
813
|
+
? primaryColumns[0].primaryKeyConstraintName
|
|
814
|
+
: this.connection.namingStrategy.primaryKeyName(clonedTable, primaryColumns.map((column) => column.name));
|
|
815
|
+
const columnNames = primaryColumns
|
|
816
|
+
.map((column) => `"${column.name}"`)
|
|
817
|
+
.join(", ");
|
|
818
|
+
upQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} ADD CONSTRAINT "${pkName}" PRIMARY KEY (${columnNames})`));
|
|
819
|
+
downQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} DROP CONSTRAINT "${pkName}"`));
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
if (newColumn.isUnique !== oldColumn.isUnique) {
|
|
824
|
+
if (newColumn.isUnique === true) {
|
|
825
|
+
const uniqueConstraint = new TableUnique_1.TableUnique({
|
|
826
|
+
name: this.connection.namingStrategy.uniqueConstraintName(table, [newColumn.name]),
|
|
827
|
+
columnNames: [newColumn.name],
|
|
828
|
+
});
|
|
829
|
+
clonedTable.uniques.push(uniqueConstraint);
|
|
830
|
+
upQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} ADD CONSTRAINT "${uniqueConstraint.name}" UNIQUE ("${newColumn.name}")`));
|
|
831
|
+
downQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} DROP CONSTRAINT "${uniqueConstraint.name}"`));
|
|
832
|
+
}
|
|
833
|
+
else {
|
|
834
|
+
const uniqueConstraint = clonedTable.uniques.find((unique) => {
|
|
835
|
+
return (unique.columnNames.length === 1 &&
|
|
836
|
+
!!unique.columnNames.find((columnName) => columnName === newColumn.name));
|
|
837
|
+
});
|
|
838
|
+
clonedTable.uniques.splice(clonedTable.uniques.indexOf(uniqueConstraint), 1);
|
|
839
|
+
upQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} DROP CONSTRAINT "${uniqueConstraint.name}"`));
|
|
840
|
+
downQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} ADD CONSTRAINT "${uniqueConstraint.name}" UNIQUE ("${newColumn.name}")`));
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
await this.executeQueries(upQueries, downQueries);
|
|
844
|
+
this.replaceCachedTable(table, clonedTable);
|
|
845
|
+
}
|
|
846
|
+
}
|
|
1206
847
|
/**
|
|
1207
848
|
* Changes a column in the table.
|
|
1208
849
|
*/
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
switch (_c.label) {
|
|
1215
|
-
case 0:
|
|
1216
|
-
_c.trys.push([0, 5, 6, 7]);
|
|
1217
|
-
changedColumns_1 = tslib_1.__values(changedColumns), changedColumns_1_1 = changedColumns_1.next();
|
|
1218
|
-
_c.label = 1;
|
|
1219
|
-
case 1:
|
|
1220
|
-
if (!!changedColumns_1_1.done) return [3 /*break*/, 4];
|
|
1221
|
-
_a = changedColumns_1_1.value, oldColumn = _a.oldColumn, newColumn = _a.newColumn;
|
|
1222
|
-
return [4 /*yield*/, this.changeColumn(tableOrName, oldColumn, newColumn)];
|
|
1223
|
-
case 2:
|
|
1224
|
-
_c.sent();
|
|
1225
|
-
_c.label = 3;
|
|
1226
|
-
case 3:
|
|
1227
|
-
changedColumns_1_1 = changedColumns_1.next();
|
|
1228
|
-
return [3 /*break*/, 1];
|
|
1229
|
-
case 4: return [3 /*break*/, 7];
|
|
1230
|
-
case 5:
|
|
1231
|
-
e_6_1 = _c.sent();
|
|
1232
|
-
e_6 = { error: e_6_1 };
|
|
1233
|
-
return [3 /*break*/, 7];
|
|
1234
|
-
case 6:
|
|
1235
|
-
try {
|
|
1236
|
-
if (changedColumns_1_1 && !changedColumns_1_1.done && (_b = changedColumns_1.return)) _b.call(changedColumns_1);
|
|
1237
|
-
}
|
|
1238
|
-
finally { if (e_6) throw e_6.error; }
|
|
1239
|
-
return [7 /*endfinally*/];
|
|
1240
|
-
case 7: return [2 /*return*/];
|
|
1241
|
-
}
|
|
1242
|
-
});
|
|
1243
|
-
});
|
|
1244
|
-
};
|
|
850
|
+
async changeColumns(tableOrName, changedColumns) {
|
|
851
|
+
for (const { oldColumn, newColumn } of changedColumns) {
|
|
852
|
+
await this.changeColumn(tableOrName, oldColumn, newColumn);
|
|
853
|
+
}
|
|
854
|
+
}
|
|
1245
855
|
/**
|
|
1246
856
|
* Drops column in the table.
|
|
1247
857
|
*/
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
});
|
|
1318
|
-
if (columnUnique) {
|
|
1319
|
-
clonedTable.uniques.splice(clonedTable.uniques.indexOf(columnUnique), 1);
|
|
1320
|
-
upQueries.push(this.dropUniqueConstraintSql(table, columnUnique));
|
|
1321
|
-
downQueries.push(this.createUniqueConstraintSql(table, columnUnique));
|
|
1322
|
-
}
|
|
1323
|
-
upQueries.push(new Query_1.Query("ALTER TABLE ".concat(this.escapePath(table), " DROP COLUMN \"").concat(column.name, "\"")));
|
|
1324
|
-
downQueries.push(new Query_1.Query("ALTER TABLE ".concat(this.escapePath(table), " ADD ").concat(this.buildCreateColumnSql(column))));
|
|
1325
|
-
if (column.generatedType && column.asExpression) {
|
|
1326
|
-
deleteQuery = this.deleteTypeormMetadataSql({
|
|
1327
|
-
table: table.name,
|
|
1328
|
-
type: MetadataTableType_1.MetadataTableType.GENERATED_COLUMN,
|
|
1329
|
-
name: column.name,
|
|
1330
|
-
});
|
|
1331
|
-
insertQuery = this.insertTypeormMetadataSql({
|
|
1332
|
-
table: table.name,
|
|
1333
|
-
type: MetadataTableType_1.MetadataTableType.GENERATED_COLUMN,
|
|
1334
|
-
name: column.name,
|
|
1335
|
-
value: column.asExpression,
|
|
1336
|
-
});
|
|
1337
|
-
upQueries.push(deleteQuery);
|
|
1338
|
-
downQueries.push(insertQuery);
|
|
1339
|
-
}
|
|
1340
|
-
return [4 /*yield*/, this.executeQueries(upQueries, downQueries)];
|
|
1341
|
-
case 4:
|
|
1342
|
-
_b.sent();
|
|
1343
|
-
clonedTable.removeColumn(column);
|
|
1344
|
-
this.replaceCachedTable(table, clonedTable);
|
|
1345
|
-
return [2 /*return*/];
|
|
1346
|
-
}
|
|
858
|
+
async dropColumn(tableOrName, columnOrName) {
|
|
859
|
+
const table = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
|
|
860
|
+
? tableOrName
|
|
861
|
+
: await this.getCachedTable(tableOrName);
|
|
862
|
+
const column = InstanceChecker_1.InstanceChecker.isTableColumn(columnOrName)
|
|
863
|
+
? columnOrName
|
|
864
|
+
: table.findColumnByName(columnOrName);
|
|
865
|
+
if (!column)
|
|
866
|
+
throw new error_1.TypeORMError(`Column "${columnOrName}" was not found in table ${this.escapePath(table)}`);
|
|
867
|
+
const clonedTable = table.clone();
|
|
868
|
+
const upQueries = [];
|
|
869
|
+
const downQueries = [];
|
|
870
|
+
// drop primary key constraint
|
|
871
|
+
if (column.isPrimary) {
|
|
872
|
+
const pkName = column.primaryKeyConstraintName
|
|
873
|
+
? column.primaryKeyConstraintName
|
|
874
|
+
: this.connection.namingStrategy.primaryKeyName(clonedTable, clonedTable.primaryColumns.map((column) => column.name));
|
|
875
|
+
const columnNames = clonedTable.primaryColumns
|
|
876
|
+
.map((primaryColumn) => `"${primaryColumn.name}"`)
|
|
877
|
+
.join(", ");
|
|
878
|
+
upQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(clonedTable)} DROP CONSTRAINT "${pkName}"`));
|
|
879
|
+
downQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(clonedTable)} ADD CONSTRAINT "${pkName}" PRIMARY KEY (${columnNames})`));
|
|
880
|
+
// update column in table
|
|
881
|
+
const tableColumn = clonedTable.findColumnByName(column.name);
|
|
882
|
+
tableColumn.isPrimary = false;
|
|
883
|
+
// if primary key have multiple columns, we must recreate it without dropped column
|
|
884
|
+
if (clonedTable.primaryColumns.length > 0) {
|
|
885
|
+
const pkName = clonedTable.primaryColumns[0]
|
|
886
|
+
.primaryKeyConstraintName
|
|
887
|
+
? clonedTable.primaryColumns[0].primaryKeyConstraintName
|
|
888
|
+
: this.connection.namingStrategy.primaryKeyName(clonedTable, clonedTable.primaryColumns.map((column) => column.name));
|
|
889
|
+
const columnNames = clonedTable.primaryColumns
|
|
890
|
+
.map((primaryColumn) => `"${primaryColumn.name}"`)
|
|
891
|
+
.join(", ");
|
|
892
|
+
upQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(clonedTable)} ADD CONSTRAINT "${pkName}" PRIMARY KEY (${columnNames})`));
|
|
893
|
+
downQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(clonedTable)} DROP CONSTRAINT "${pkName}"`));
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
// drop column index
|
|
897
|
+
const columnIndex = clonedTable.indices.find((index) => index.columnNames.length === 1 &&
|
|
898
|
+
index.columnNames[0] === column.name);
|
|
899
|
+
if (columnIndex) {
|
|
900
|
+
upQueries.push(this.dropIndexSql(columnIndex));
|
|
901
|
+
downQueries.push(this.createIndexSql(table, columnIndex));
|
|
902
|
+
}
|
|
903
|
+
// drop column check
|
|
904
|
+
const columnCheck = clonedTable.checks.find((check) => !!check.columnNames &&
|
|
905
|
+
check.columnNames.length === 1 &&
|
|
906
|
+
check.columnNames[0] === column.name);
|
|
907
|
+
if (columnCheck) {
|
|
908
|
+
clonedTable.checks.splice(clonedTable.checks.indexOf(columnCheck), 1);
|
|
909
|
+
upQueries.push(this.dropCheckConstraintSql(table, columnCheck));
|
|
910
|
+
downQueries.push(this.createCheckConstraintSql(table, columnCheck));
|
|
911
|
+
}
|
|
912
|
+
// drop column unique
|
|
913
|
+
const columnUnique = clonedTable.uniques.find((unique) => unique.columnNames.length === 1 &&
|
|
914
|
+
unique.columnNames[0] === column.name);
|
|
915
|
+
if (columnUnique) {
|
|
916
|
+
clonedTable.uniques.splice(clonedTable.uniques.indexOf(columnUnique), 1);
|
|
917
|
+
upQueries.push(this.dropUniqueConstraintSql(table, columnUnique));
|
|
918
|
+
downQueries.push(this.createUniqueConstraintSql(table, columnUnique));
|
|
919
|
+
}
|
|
920
|
+
upQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} DROP COLUMN "${column.name}"`));
|
|
921
|
+
downQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} ADD ${this.buildCreateColumnSql(column)}`));
|
|
922
|
+
if (column.generatedType && column.asExpression) {
|
|
923
|
+
const deleteQuery = this.deleteTypeormMetadataSql({
|
|
924
|
+
table: table.name,
|
|
925
|
+
type: MetadataTableType_1.MetadataTableType.GENERATED_COLUMN,
|
|
926
|
+
name: column.name,
|
|
1347
927
|
});
|
|
1348
|
-
|
|
1349
|
-
|
|
928
|
+
const insertQuery = this.insertTypeormMetadataSql({
|
|
929
|
+
table: table.name,
|
|
930
|
+
type: MetadataTableType_1.MetadataTableType.GENERATED_COLUMN,
|
|
931
|
+
name: column.name,
|
|
932
|
+
value: column.asExpression,
|
|
933
|
+
});
|
|
934
|
+
upQueries.push(deleteQuery);
|
|
935
|
+
downQueries.push(insertQuery);
|
|
936
|
+
}
|
|
937
|
+
await this.executeQueries(upQueries, downQueries);
|
|
938
|
+
clonedTable.removeColumn(column);
|
|
939
|
+
this.replaceCachedTable(table, clonedTable);
|
|
940
|
+
}
|
|
1350
941
|
/**
|
|
1351
942
|
* Drops the columns in the table.
|
|
1352
943
|
*/
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
switch (_b.label) {
|
|
1359
|
-
case 0:
|
|
1360
|
-
_b.trys.push([0, 5, 6, 7]);
|
|
1361
|
-
columns_2 = tslib_1.__values(columns), columns_2_1 = columns_2.next();
|
|
1362
|
-
_b.label = 1;
|
|
1363
|
-
case 1:
|
|
1364
|
-
if (!!columns_2_1.done) return [3 /*break*/, 4];
|
|
1365
|
-
column = columns_2_1.value;
|
|
1366
|
-
return [4 /*yield*/, this.dropColumn(tableOrName, column)];
|
|
1367
|
-
case 2:
|
|
1368
|
-
_b.sent();
|
|
1369
|
-
_b.label = 3;
|
|
1370
|
-
case 3:
|
|
1371
|
-
columns_2_1 = columns_2.next();
|
|
1372
|
-
return [3 /*break*/, 1];
|
|
1373
|
-
case 4: return [3 /*break*/, 7];
|
|
1374
|
-
case 5:
|
|
1375
|
-
e_7_1 = _b.sent();
|
|
1376
|
-
e_7 = { error: e_7_1 };
|
|
1377
|
-
return [3 /*break*/, 7];
|
|
1378
|
-
case 6:
|
|
1379
|
-
try {
|
|
1380
|
-
if (columns_2_1 && !columns_2_1.done && (_a = columns_2.return)) _a.call(columns_2);
|
|
1381
|
-
}
|
|
1382
|
-
finally { if (e_7) throw e_7.error; }
|
|
1383
|
-
return [7 /*endfinally*/];
|
|
1384
|
-
case 7: return [2 /*return*/];
|
|
1385
|
-
}
|
|
1386
|
-
});
|
|
1387
|
-
});
|
|
1388
|
-
};
|
|
944
|
+
async dropColumns(tableOrName, columns) {
|
|
945
|
+
for (const column of columns) {
|
|
946
|
+
await this.dropColumn(tableOrName, column);
|
|
947
|
+
}
|
|
948
|
+
}
|
|
1389
949
|
/**
|
|
1390
950
|
* Creates a new primary key.
|
|
1391
951
|
*/
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
case 2:
|
|
1403
|
-
_a = _b.sent();
|
|
1404
|
-
_b.label = 3;
|
|
1405
|
-
case 3:
|
|
1406
|
-
table = _a;
|
|
1407
|
-
clonedTable = table.clone();
|
|
1408
|
-
up = this.createPrimaryKeySql(table, columnNames, constraintName);
|
|
1409
|
-
// mark columns as primary, because dropPrimaryKeySql build constraint name from table primary column names.
|
|
1410
|
-
clonedTable.columns.forEach(function (column) {
|
|
1411
|
-
if (columnNames.find(function (columnName) { return columnName === column.name; }))
|
|
1412
|
-
column.isPrimary = true;
|
|
1413
|
-
});
|
|
1414
|
-
down = this.dropPrimaryKeySql(clonedTable);
|
|
1415
|
-
return [4 /*yield*/, this.executeQueries(up, down)];
|
|
1416
|
-
case 4:
|
|
1417
|
-
_b.sent();
|
|
1418
|
-
this.replaceCachedTable(table, clonedTable);
|
|
1419
|
-
return [2 /*return*/];
|
|
1420
|
-
}
|
|
1421
|
-
});
|
|
952
|
+
async createPrimaryKey(tableOrName, columnNames, constraintName) {
|
|
953
|
+
const table = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
|
|
954
|
+
? tableOrName
|
|
955
|
+
: await this.getCachedTable(tableOrName);
|
|
956
|
+
const clonedTable = table.clone();
|
|
957
|
+
const up = this.createPrimaryKeySql(table, columnNames, constraintName);
|
|
958
|
+
// mark columns as primary, because dropPrimaryKeySql build constraint name from table primary column names.
|
|
959
|
+
clonedTable.columns.forEach((column) => {
|
|
960
|
+
if (columnNames.find((columnName) => columnName === column.name))
|
|
961
|
+
column.isPrimary = true;
|
|
1422
962
|
});
|
|
1423
|
-
|
|
963
|
+
const down = this.dropPrimaryKeySql(clonedTable);
|
|
964
|
+
await this.executeQueries(up, down);
|
|
965
|
+
this.replaceCachedTable(table, clonedTable);
|
|
966
|
+
}
|
|
1424
967
|
/**
|
|
1425
968
|
* Updates composite primary keys.
|
|
1426
969
|
*/
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
? primaryColumns[0].primaryKeyConstraintName
|
|
1463
|
-
: this.connection.namingStrategy.primaryKeyName(clonedTable, columnNames);
|
|
1464
|
-
columnNamesString = columnNames
|
|
1465
|
-
.map(function (columnName) { return "\"".concat(columnName, "\""); })
|
|
1466
|
-
.join(", ");
|
|
1467
|
-
upQueries.push(new Query_1.Query("ALTER TABLE ".concat(this.escapePath(table), " ADD CONSTRAINT \"").concat(pkName, "\" PRIMARY KEY (").concat(columnNamesString, ")")));
|
|
1468
|
-
downQueries.push(new Query_1.Query("ALTER TABLE ".concat(this.escapePath(table), " DROP CONSTRAINT \"").concat(pkName, "\"")));
|
|
1469
|
-
return [4 /*yield*/, this.executeQueries(upQueries, downQueries)];
|
|
1470
|
-
case 4:
|
|
1471
|
-
_b.sent();
|
|
1472
|
-
this.replaceCachedTable(table, clonedTable);
|
|
1473
|
-
return [2 /*return*/];
|
|
1474
|
-
}
|
|
1475
|
-
});
|
|
1476
|
-
});
|
|
1477
|
-
};
|
|
970
|
+
async updatePrimaryKeys(tableOrName, columns) {
|
|
971
|
+
const table = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
|
|
972
|
+
? tableOrName
|
|
973
|
+
: await this.getCachedTable(tableOrName);
|
|
974
|
+
const columnNames = columns.map((column) => column.name);
|
|
975
|
+
const clonedTable = table.clone();
|
|
976
|
+
const upQueries = [];
|
|
977
|
+
const downQueries = [];
|
|
978
|
+
// if table already have primary columns, we must drop them.
|
|
979
|
+
const primaryColumns = clonedTable.primaryColumns;
|
|
980
|
+
if (primaryColumns.length > 0) {
|
|
981
|
+
const pkName = primaryColumns[0].primaryKeyConstraintName
|
|
982
|
+
? primaryColumns[0].primaryKeyConstraintName
|
|
983
|
+
: this.connection.namingStrategy.primaryKeyName(clonedTable, primaryColumns.map((column) => column.name));
|
|
984
|
+
const columnNamesString = primaryColumns
|
|
985
|
+
.map((column) => `"${column.name}"`)
|
|
986
|
+
.join(", ");
|
|
987
|
+
upQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} DROP CONSTRAINT "${pkName}"`));
|
|
988
|
+
downQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} ADD CONSTRAINT "${pkName}" PRIMARY KEY (${columnNamesString})`));
|
|
989
|
+
}
|
|
990
|
+
// update columns in table.
|
|
991
|
+
clonedTable.columns
|
|
992
|
+
.filter((column) => columnNames.indexOf(column.name) !== -1)
|
|
993
|
+
.forEach((column) => (column.isPrimary = true));
|
|
994
|
+
const pkName = primaryColumns[0].primaryKeyConstraintName
|
|
995
|
+
? primaryColumns[0].primaryKeyConstraintName
|
|
996
|
+
: this.connection.namingStrategy.primaryKeyName(clonedTable, columnNames);
|
|
997
|
+
const columnNamesString = columnNames
|
|
998
|
+
.map((columnName) => `"${columnName}"`)
|
|
999
|
+
.join(", ");
|
|
1000
|
+
upQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} ADD CONSTRAINT "${pkName}" PRIMARY KEY (${columnNamesString})`));
|
|
1001
|
+
downQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} DROP CONSTRAINT "${pkName}"`));
|
|
1002
|
+
await this.executeQueries(upQueries, downQueries);
|
|
1003
|
+
this.replaceCachedTable(table, clonedTable);
|
|
1004
|
+
}
|
|
1478
1005
|
/**
|
|
1479
1006
|
* Drops a primary key.
|
|
1480
1007
|
*/
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
case 1: return [4 /*yield*/, this.getCachedTable(tableOrName)];
|
|
1491
|
-
case 2:
|
|
1492
|
-
_a = _b.sent();
|
|
1493
|
-
_b.label = 3;
|
|
1494
|
-
case 3:
|
|
1495
|
-
table = _a;
|
|
1496
|
-
up = this.dropPrimaryKeySql(table);
|
|
1497
|
-
down = this.createPrimaryKeySql(table, table.primaryColumns.map(function (column) { return column.name; }), constraintName);
|
|
1498
|
-
return [4 /*yield*/, this.executeQueries(up, down)];
|
|
1499
|
-
case 4:
|
|
1500
|
-
_b.sent();
|
|
1501
|
-
table.primaryColumns.forEach(function (column) {
|
|
1502
|
-
column.isPrimary = false;
|
|
1503
|
-
});
|
|
1504
|
-
return [2 /*return*/];
|
|
1505
|
-
}
|
|
1506
|
-
});
|
|
1008
|
+
async dropPrimaryKey(tableOrName, constraintName) {
|
|
1009
|
+
const table = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
|
|
1010
|
+
? tableOrName
|
|
1011
|
+
: await this.getCachedTable(tableOrName);
|
|
1012
|
+
const up = this.dropPrimaryKeySql(table);
|
|
1013
|
+
const down = this.createPrimaryKeySql(table, table.primaryColumns.map((column) => column.name), constraintName);
|
|
1014
|
+
await this.executeQueries(up, down);
|
|
1015
|
+
table.primaryColumns.forEach((column) => {
|
|
1016
|
+
column.isPrimary = false;
|
|
1507
1017
|
});
|
|
1508
|
-
}
|
|
1018
|
+
}
|
|
1509
1019
|
/**
|
|
1510
1020
|
* Creates a new unique constraint.
|
|
1511
1021
|
*/
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
_a = _b.sent();
|
|
1526
|
-
_b.label = 3;
|
|
1527
|
-
case 3:
|
|
1528
|
-
table = _a;
|
|
1529
|
-
// new unique constraint may be passed without name. In this case we generate unique name manually.
|
|
1530
|
-
if (!uniqueConstraint.name)
|
|
1531
|
-
uniqueConstraint.name =
|
|
1532
|
-
this.connection.namingStrategy.uniqueConstraintName(table, uniqueConstraint.columnNames);
|
|
1533
|
-
up = this.createUniqueConstraintSql(table, uniqueConstraint);
|
|
1534
|
-
down = this.dropUniqueConstraintSql(table, uniqueConstraint);
|
|
1535
|
-
return [4 /*yield*/, this.executeQueries(up, down)];
|
|
1536
|
-
case 4:
|
|
1537
|
-
_b.sent();
|
|
1538
|
-
table.addUniqueConstraint(uniqueConstraint);
|
|
1539
|
-
return [2 /*return*/];
|
|
1540
|
-
}
|
|
1541
|
-
});
|
|
1542
|
-
});
|
|
1543
|
-
};
|
|
1022
|
+
async createUniqueConstraint(tableOrName, uniqueConstraint) {
|
|
1023
|
+
const table = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
|
|
1024
|
+
? tableOrName
|
|
1025
|
+
: await this.getCachedTable(tableOrName);
|
|
1026
|
+
// new unique constraint may be passed without name. In this case we generate unique name manually.
|
|
1027
|
+
if (!uniqueConstraint.name)
|
|
1028
|
+
uniqueConstraint.name =
|
|
1029
|
+
this.connection.namingStrategy.uniqueConstraintName(table, uniqueConstraint.columnNames);
|
|
1030
|
+
const up = this.createUniqueConstraintSql(table, uniqueConstraint);
|
|
1031
|
+
const down = this.dropUniqueConstraintSql(table, uniqueConstraint);
|
|
1032
|
+
await this.executeQueries(up, down);
|
|
1033
|
+
table.addUniqueConstraint(uniqueConstraint);
|
|
1034
|
+
}
|
|
1544
1035
|
/**
|
|
1545
1036
|
* Creates a new unique constraints.
|
|
1546
1037
|
*/
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
return tslib_1.__generator(this, function (_a) {
|
|
1552
|
-
switch (_a.label) {
|
|
1553
|
-
case 0:
|
|
1554
|
-
promises = uniqueConstraints.map(function (uniqueConstraint) {
|
|
1555
|
-
return _this.createUniqueConstraint(tableOrName, uniqueConstraint);
|
|
1556
|
-
});
|
|
1557
|
-
return [4 /*yield*/, Promise.all(promises)];
|
|
1558
|
-
case 1:
|
|
1559
|
-
_a.sent();
|
|
1560
|
-
return [2 /*return*/];
|
|
1561
|
-
}
|
|
1562
|
-
});
|
|
1563
|
-
});
|
|
1564
|
-
};
|
|
1038
|
+
async createUniqueConstraints(tableOrName, uniqueConstraints) {
|
|
1039
|
+
const promises = uniqueConstraints.map((uniqueConstraint) => this.createUniqueConstraint(tableOrName, uniqueConstraint));
|
|
1040
|
+
await Promise.all(promises);
|
|
1041
|
+
}
|
|
1565
1042
|
/**
|
|
1566
1043
|
* Drops an unique constraint.
|
|
1567
1044
|
*/
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
table = _a;
|
|
1583
|
-
uniqueConstraint = InstanceChecker_1.InstanceChecker.isTableUnique(uniqueOrName)
|
|
1584
|
-
? uniqueOrName
|
|
1585
|
-
: table.uniques.find(function (u) { return u.name === uniqueOrName; });
|
|
1586
|
-
if (!uniqueConstraint)
|
|
1587
|
-
throw new error_1.TypeORMError("Supplied unique constraint was not found in table ".concat(table.name));
|
|
1588
|
-
up = this.dropUniqueConstraintSql(table, uniqueConstraint);
|
|
1589
|
-
down = this.createUniqueConstraintSql(table, uniqueConstraint);
|
|
1590
|
-
return [4 /*yield*/, this.executeQueries(up, down)];
|
|
1591
|
-
case 4:
|
|
1592
|
-
_b.sent();
|
|
1593
|
-
table.removeUniqueConstraint(uniqueConstraint);
|
|
1594
|
-
return [2 /*return*/];
|
|
1595
|
-
}
|
|
1596
|
-
});
|
|
1597
|
-
});
|
|
1598
|
-
};
|
|
1045
|
+
async dropUniqueConstraint(tableOrName, uniqueOrName) {
|
|
1046
|
+
const table = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
|
|
1047
|
+
? tableOrName
|
|
1048
|
+
: await this.getCachedTable(tableOrName);
|
|
1049
|
+
const uniqueConstraint = InstanceChecker_1.InstanceChecker.isTableUnique(uniqueOrName)
|
|
1050
|
+
? uniqueOrName
|
|
1051
|
+
: table.uniques.find((u) => u.name === uniqueOrName);
|
|
1052
|
+
if (!uniqueConstraint)
|
|
1053
|
+
throw new error_1.TypeORMError(`Supplied unique constraint was not found in table ${table.name}`);
|
|
1054
|
+
const up = this.dropUniqueConstraintSql(table, uniqueConstraint);
|
|
1055
|
+
const down = this.createUniqueConstraintSql(table, uniqueConstraint);
|
|
1056
|
+
await this.executeQueries(up, down);
|
|
1057
|
+
table.removeUniqueConstraint(uniqueConstraint);
|
|
1058
|
+
}
|
|
1599
1059
|
/**
|
|
1600
1060
|
* Creates an unique constraints.
|
|
1601
1061
|
*/
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
return tslib_1.__generator(this, function (_a) {
|
|
1607
|
-
switch (_a.label) {
|
|
1608
|
-
case 0:
|
|
1609
|
-
promises = uniqueConstraints.map(function (uniqueConstraint) {
|
|
1610
|
-
return _this.dropUniqueConstraint(tableOrName, uniqueConstraint);
|
|
1611
|
-
});
|
|
1612
|
-
return [4 /*yield*/, Promise.all(promises)];
|
|
1613
|
-
case 1:
|
|
1614
|
-
_a.sent();
|
|
1615
|
-
return [2 /*return*/];
|
|
1616
|
-
}
|
|
1617
|
-
});
|
|
1618
|
-
});
|
|
1619
|
-
};
|
|
1062
|
+
async dropUniqueConstraints(tableOrName, uniqueConstraints) {
|
|
1063
|
+
const promises = uniqueConstraints.map((uniqueConstraint) => this.dropUniqueConstraint(tableOrName, uniqueConstraint));
|
|
1064
|
+
await Promise.all(promises);
|
|
1065
|
+
}
|
|
1620
1066
|
/**
|
|
1621
1067
|
* Creates new check constraint.
|
|
1622
1068
|
*/
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
_a = _b.sent();
|
|
1637
|
-
_b.label = 3;
|
|
1638
|
-
case 3:
|
|
1639
|
-
table = _a;
|
|
1640
|
-
// new unique constraint may be passed without name. In this case we generate unique name manually.
|
|
1641
|
-
if (!checkConstraint.name)
|
|
1642
|
-
checkConstraint.name =
|
|
1643
|
-
this.connection.namingStrategy.checkConstraintName(table, checkConstraint.expression);
|
|
1644
|
-
up = this.createCheckConstraintSql(table, checkConstraint);
|
|
1645
|
-
down = this.dropCheckConstraintSql(table, checkConstraint);
|
|
1646
|
-
return [4 /*yield*/, this.executeQueries(up, down)];
|
|
1647
|
-
case 4:
|
|
1648
|
-
_b.sent();
|
|
1649
|
-
table.addCheckConstraint(checkConstraint);
|
|
1650
|
-
return [2 /*return*/];
|
|
1651
|
-
}
|
|
1652
|
-
});
|
|
1653
|
-
});
|
|
1654
|
-
};
|
|
1069
|
+
async createCheckConstraint(tableOrName, checkConstraint) {
|
|
1070
|
+
const table = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
|
|
1071
|
+
? tableOrName
|
|
1072
|
+
: await this.getCachedTable(tableOrName);
|
|
1073
|
+
// new unique constraint may be passed without name. In this case we generate unique name manually.
|
|
1074
|
+
if (!checkConstraint.name)
|
|
1075
|
+
checkConstraint.name =
|
|
1076
|
+
this.connection.namingStrategy.checkConstraintName(table, checkConstraint.expression);
|
|
1077
|
+
const up = this.createCheckConstraintSql(table, checkConstraint);
|
|
1078
|
+
const down = this.dropCheckConstraintSql(table, checkConstraint);
|
|
1079
|
+
await this.executeQueries(up, down);
|
|
1080
|
+
table.addCheckConstraint(checkConstraint);
|
|
1081
|
+
}
|
|
1655
1082
|
/**
|
|
1656
1083
|
* Creates new check constraints.
|
|
1657
1084
|
*/
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
return tslib_1.__generator(this, function (_a) {
|
|
1663
|
-
switch (_a.label) {
|
|
1664
|
-
case 0:
|
|
1665
|
-
promises = checkConstraints.map(function (checkConstraint) {
|
|
1666
|
-
return _this.createCheckConstraint(tableOrName, checkConstraint);
|
|
1667
|
-
});
|
|
1668
|
-
return [4 /*yield*/, Promise.all(promises)];
|
|
1669
|
-
case 1:
|
|
1670
|
-
_a.sent();
|
|
1671
|
-
return [2 /*return*/];
|
|
1672
|
-
}
|
|
1673
|
-
});
|
|
1674
|
-
});
|
|
1675
|
-
};
|
|
1085
|
+
async createCheckConstraints(tableOrName, checkConstraints) {
|
|
1086
|
+
const promises = checkConstraints.map((checkConstraint) => this.createCheckConstraint(tableOrName, checkConstraint));
|
|
1087
|
+
await Promise.all(promises);
|
|
1088
|
+
}
|
|
1676
1089
|
/**
|
|
1677
1090
|
* Drops check constraint.
|
|
1678
1091
|
*/
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
table = _a;
|
|
1694
|
-
checkConstraint = InstanceChecker_1.InstanceChecker.isTableCheck(checkOrName)
|
|
1695
|
-
? checkOrName
|
|
1696
|
-
: table.checks.find(function (c) { return c.name === checkOrName; });
|
|
1697
|
-
if (!checkConstraint)
|
|
1698
|
-
throw new error_1.TypeORMError("Supplied check constraint was not found in table ".concat(table.name));
|
|
1699
|
-
up = this.dropCheckConstraintSql(table, checkConstraint);
|
|
1700
|
-
down = this.createCheckConstraintSql(table, checkConstraint);
|
|
1701
|
-
return [4 /*yield*/, this.executeQueries(up, down)];
|
|
1702
|
-
case 4:
|
|
1703
|
-
_b.sent();
|
|
1704
|
-
table.removeCheckConstraint(checkConstraint);
|
|
1705
|
-
return [2 /*return*/];
|
|
1706
|
-
}
|
|
1707
|
-
});
|
|
1708
|
-
});
|
|
1709
|
-
};
|
|
1092
|
+
async dropCheckConstraint(tableOrName, checkOrName) {
|
|
1093
|
+
const table = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
|
|
1094
|
+
? tableOrName
|
|
1095
|
+
: await this.getCachedTable(tableOrName);
|
|
1096
|
+
const checkConstraint = InstanceChecker_1.InstanceChecker.isTableCheck(checkOrName)
|
|
1097
|
+
? checkOrName
|
|
1098
|
+
: table.checks.find((c) => c.name === checkOrName);
|
|
1099
|
+
if (!checkConstraint)
|
|
1100
|
+
throw new error_1.TypeORMError(`Supplied check constraint was not found in table ${table.name}`);
|
|
1101
|
+
const up = this.dropCheckConstraintSql(table, checkConstraint);
|
|
1102
|
+
const down = this.createCheckConstraintSql(table, checkConstraint);
|
|
1103
|
+
await this.executeQueries(up, down);
|
|
1104
|
+
table.removeCheckConstraint(checkConstraint);
|
|
1105
|
+
}
|
|
1710
1106
|
/**
|
|
1711
1107
|
* Drops check constraints.
|
|
1712
1108
|
*/
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
return tslib_1.__generator(this, function (_a) {
|
|
1718
|
-
switch (_a.label) {
|
|
1719
|
-
case 0:
|
|
1720
|
-
promises = checkConstraints.map(function (checkConstraint) {
|
|
1721
|
-
return _this.dropCheckConstraint(tableOrName, checkConstraint);
|
|
1722
|
-
});
|
|
1723
|
-
return [4 /*yield*/, Promise.all(promises)];
|
|
1724
|
-
case 1:
|
|
1725
|
-
_a.sent();
|
|
1726
|
-
return [2 /*return*/];
|
|
1727
|
-
}
|
|
1728
|
-
});
|
|
1729
|
-
});
|
|
1730
|
-
};
|
|
1109
|
+
async dropCheckConstraints(tableOrName, checkConstraints) {
|
|
1110
|
+
const promises = checkConstraints.map((checkConstraint) => this.dropCheckConstraint(tableOrName, checkConstraint));
|
|
1111
|
+
await Promise.all(promises);
|
|
1112
|
+
}
|
|
1731
1113
|
/**
|
|
1732
1114
|
* Creates a new exclusion constraint.
|
|
1733
1115
|
*/
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
throw new error_1.TypeORMError("Oracle does not support exclusion constraints.");
|
|
1738
|
-
});
|
|
1739
|
-
});
|
|
1740
|
-
};
|
|
1116
|
+
async createExclusionConstraint(tableOrName, exclusionConstraint) {
|
|
1117
|
+
throw new error_1.TypeORMError(`Oracle does not support exclusion constraints.`);
|
|
1118
|
+
}
|
|
1741
1119
|
/**
|
|
1742
1120
|
* Creates a new exclusion constraints.
|
|
1743
1121
|
*/
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
throw new error_1.TypeORMError("Oracle does not support exclusion constraints.");
|
|
1748
|
-
});
|
|
1749
|
-
});
|
|
1750
|
-
};
|
|
1122
|
+
async createExclusionConstraints(tableOrName, exclusionConstraints) {
|
|
1123
|
+
throw new error_1.TypeORMError(`Oracle does not support exclusion constraints.`);
|
|
1124
|
+
}
|
|
1751
1125
|
/**
|
|
1752
1126
|
* Drops exclusion constraint.
|
|
1753
1127
|
*/
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
throw new error_1.TypeORMError("Oracle does not support exclusion constraints.");
|
|
1758
|
-
});
|
|
1759
|
-
});
|
|
1760
|
-
};
|
|
1128
|
+
async dropExclusionConstraint(tableOrName, exclusionOrName) {
|
|
1129
|
+
throw new error_1.TypeORMError(`Oracle does not support exclusion constraints.`);
|
|
1130
|
+
}
|
|
1761
1131
|
/**
|
|
1762
1132
|
* Drops exclusion constraints.
|
|
1763
1133
|
*/
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
throw new error_1.TypeORMError("Oracle does not support exclusion constraints.");
|
|
1768
|
-
});
|
|
1769
|
-
});
|
|
1770
|
-
};
|
|
1134
|
+
async dropExclusionConstraints(tableOrName, exclusionConstraints) {
|
|
1135
|
+
throw new error_1.TypeORMError(`Oracle does not support exclusion constraints.`);
|
|
1136
|
+
}
|
|
1771
1137
|
/**
|
|
1772
1138
|
* Creates a new foreign key.
|
|
1773
1139
|
*/
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
case 2:
|
|
1787
|
-
_a = _b.sent();
|
|
1788
|
-
_b.label = 3;
|
|
1789
|
-
case 3:
|
|
1790
|
-
table = _a;
|
|
1791
|
-
// new FK may be passed without name. In this case we generate FK name manually.
|
|
1792
|
-
if (!foreignKey.name)
|
|
1793
|
-
foreignKey.name = this.connection.namingStrategy.foreignKeyName(table, foreignKey.columnNames, this.getTablePath(foreignKey), foreignKey.referencedColumnNames);
|
|
1794
|
-
up = this.createForeignKeySql(table, foreignKey);
|
|
1795
|
-
down = this.dropForeignKeySql(table, foreignKey);
|
|
1796
|
-
return [4 /*yield*/, this.executeQueries(up, down)];
|
|
1797
|
-
case 4:
|
|
1798
|
-
_b.sent();
|
|
1799
|
-
table.addForeignKey(foreignKey);
|
|
1800
|
-
return [2 /*return*/];
|
|
1801
|
-
}
|
|
1802
|
-
});
|
|
1803
|
-
});
|
|
1804
|
-
};
|
|
1140
|
+
async createForeignKey(tableOrName, foreignKey) {
|
|
1141
|
+
const table = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
|
|
1142
|
+
? tableOrName
|
|
1143
|
+
: await this.getCachedTable(tableOrName);
|
|
1144
|
+
// new FK may be passed without name. In this case we generate FK name manually.
|
|
1145
|
+
if (!foreignKey.name)
|
|
1146
|
+
foreignKey.name = this.connection.namingStrategy.foreignKeyName(table, foreignKey.columnNames, this.getTablePath(foreignKey), foreignKey.referencedColumnNames);
|
|
1147
|
+
const up = this.createForeignKeySql(table, foreignKey);
|
|
1148
|
+
const down = this.dropForeignKeySql(table, foreignKey);
|
|
1149
|
+
await this.executeQueries(up, down);
|
|
1150
|
+
table.addForeignKey(foreignKey);
|
|
1151
|
+
}
|
|
1805
1152
|
/**
|
|
1806
1153
|
* Creates a new foreign keys.
|
|
1807
1154
|
*/
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
return tslib_1.__generator(this, function (_a) {
|
|
1813
|
-
switch (_a.label) {
|
|
1814
|
-
case 0:
|
|
1815
|
-
promises = foreignKeys.map(function (foreignKey) {
|
|
1816
|
-
return _this.createForeignKey(tableOrName, foreignKey);
|
|
1817
|
-
});
|
|
1818
|
-
return [4 /*yield*/, Promise.all(promises)];
|
|
1819
|
-
case 1:
|
|
1820
|
-
_a.sent();
|
|
1821
|
-
return [2 /*return*/];
|
|
1822
|
-
}
|
|
1823
|
-
});
|
|
1824
|
-
});
|
|
1825
|
-
};
|
|
1155
|
+
async createForeignKeys(tableOrName, foreignKeys) {
|
|
1156
|
+
const promises = foreignKeys.map((foreignKey) => this.createForeignKey(tableOrName, foreignKey));
|
|
1157
|
+
await Promise.all(promises);
|
|
1158
|
+
}
|
|
1826
1159
|
/**
|
|
1827
1160
|
* Drops a foreign key from the table.
|
|
1828
1161
|
*/
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
table = _a;
|
|
1844
|
-
foreignKey = InstanceChecker_1.InstanceChecker.isTableForeignKey(foreignKeyOrName)
|
|
1845
|
-
? foreignKeyOrName
|
|
1846
|
-
: table.foreignKeys.find(function (fk) { return fk.name === foreignKeyOrName; });
|
|
1847
|
-
if (!foreignKey)
|
|
1848
|
-
throw new error_1.TypeORMError("Supplied foreign key was not found in table ".concat(table.name));
|
|
1849
|
-
up = this.dropForeignKeySql(table, foreignKey);
|
|
1850
|
-
down = this.createForeignKeySql(table, foreignKey);
|
|
1851
|
-
return [4 /*yield*/, this.executeQueries(up, down)];
|
|
1852
|
-
case 4:
|
|
1853
|
-
_b.sent();
|
|
1854
|
-
table.removeForeignKey(foreignKey);
|
|
1855
|
-
return [2 /*return*/];
|
|
1856
|
-
}
|
|
1857
|
-
});
|
|
1858
|
-
});
|
|
1859
|
-
};
|
|
1162
|
+
async dropForeignKey(tableOrName, foreignKeyOrName) {
|
|
1163
|
+
const table = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
|
|
1164
|
+
? tableOrName
|
|
1165
|
+
: await this.getCachedTable(tableOrName);
|
|
1166
|
+
const foreignKey = InstanceChecker_1.InstanceChecker.isTableForeignKey(foreignKeyOrName)
|
|
1167
|
+
? foreignKeyOrName
|
|
1168
|
+
: table.foreignKeys.find((fk) => fk.name === foreignKeyOrName);
|
|
1169
|
+
if (!foreignKey)
|
|
1170
|
+
throw new error_1.TypeORMError(`Supplied foreign key was not found in table ${table.name}`);
|
|
1171
|
+
const up = this.dropForeignKeySql(table, foreignKey);
|
|
1172
|
+
const down = this.createForeignKeySql(table, foreignKey);
|
|
1173
|
+
await this.executeQueries(up, down);
|
|
1174
|
+
table.removeForeignKey(foreignKey);
|
|
1175
|
+
}
|
|
1860
1176
|
/**
|
|
1861
1177
|
* Drops a foreign keys from the table.
|
|
1862
1178
|
*/
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
return tslib_1.__generator(this, function (_a) {
|
|
1868
|
-
switch (_a.label) {
|
|
1869
|
-
case 0:
|
|
1870
|
-
promises = foreignKeys.map(function (foreignKey) {
|
|
1871
|
-
return _this.dropForeignKey(tableOrName, foreignKey);
|
|
1872
|
-
});
|
|
1873
|
-
return [4 /*yield*/, Promise.all(promises)];
|
|
1874
|
-
case 1:
|
|
1875
|
-
_a.sent();
|
|
1876
|
-
return [2 /*return*/];
|
|
1877
|
-
}
|
|
1878
|
-
});
|
|
1879
|
-
});
|
|
1880
|
-
};
|
|
1179
|
+
async dropForeignKeys(tableOrName, foreignKeys) {
|
|
1180
|
+
const promises = foreignKeys.map((foreignKey) => this.dropForeignKey(tableOrName, foreignKey));
|
|
1181
|
+
await Promise.all(promises);
|
|
1182
|
+
}
|
|
1881
1183
|
/**
|
|
1882
1184
|
* Creates a new index.
|
|
1883
1185
|
*/
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
case 2:
|
|
1897
|
-
_a = _b.sent();
|
|
1898
|
-
_b.label = 3;
|
|
1899
|
-
case 3:
|
|
1900
|
-
table = _a;
|
|
1901
|
-
// new index may be passed without name. In this case we generate index name manually.
|
|
1902
|
-
if (!index.name)
|
|
1903
|
-
index.name = this.generateIndexName(table, index);
|
|
1904
|
-
up = this.createIndexSql(table, index);
|
|
1905
|
-
down = this.dropIndexSql(index);
|
|
1906
|
-
return [4 /*yield*/, this.executeQueries(up, down)];
|
|
1907
|
-
case 4:
|
|
1908
|
-
_b.sent();
|
|
1909
|
-
table.addIndex(index);
|
|
1910
|
-
return [2 /*return*/];
|
|
1911
|
-
}
|
|
1912
|
-
});
|
|
1913
|
-
});
|
|
1914
|
-
};
|
|
1186
|
+
async createIndex(tableOrName, index) {
|
|
1187
|
+
const table = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
|
|
1188
|
+
? tableOrName
|
|
1189
|
+
: await this.getCachedTable(tableOrName);
|
|
1190
|
+
// new index may be passed without name. In this case we generate index name manually.
|
|
1191
|
+
if (!index.name)
|
|
1192
|
+
index.name = this.generateIndexName(table, index);
|
|
1193
|
+
const up = this.createIndexSql(table, index);
|
|
1194
|
+
const down = this.dropIndexSql(index);
|
|
1195
|
+
await this.executeQueries(up, down);
|
|
1196
|
+
table.addIndex(index);
|
|
1197
|
+
}
|
|
1915
1198
|
/**
|
|
1916
1199
|
* Creates a new indices
|
|
1917
1200
|
*/
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
return tslib_1.__generator(this, function (_a) {
|
|
1923
|
-
switch (_a.label) {
|
|
1924
|
-
case 0:
|
|
1925
|
-
promises = indices.map(function (index) {
|
|
1926
|
-
return _this.createIndex(tableOrName, index);
|
|
1927
|
-
});
|
|
1928
|
-
return [4 /*yield*/, Promise.all(promises)];
|
|
1929
|
-
case 1:
|
|
1930
|
-
_a.sent();
|
|
1931
|
-
return [2 /*return*/];
|
|
1932
|
-
}
|
|
1933
|
-
});
|
|
1934
|
-
});
|
|
1935
|
-
};
|
|
1201
|
+
async createIndices(tableOrName, indices) {
|
|
1202
|
+
const promises = indices.map((index) => this.createIndex(tableOrName, index));
|
|
1203
|
+
await Promise.all(promises);
|
|
1204
|
+
}
|
|
1936
1205
|
/**
|
|
1937
1206
|
* Drops an index from the table.
|
|
1938
1207
|
*/
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
: table.indices.find(function (i) { return i.name === indexOrName; });
|
|
1957
|
-
if (!index)
|
|
1958
|
-
throw new error_1.TypeORMError("Supplied index ".concat(indexOrName, " was not found in table ").concat(table.name));
|
|
1959
|
-
// old index may be passed without name. In this case we generate index name manually.
|
|
1960
|
-
if (!index.name)
|
|
1961
|
-
index.name = this.generateIndexName(table, index);
|
|
1962
|
-
up = this.dropIndexSql(index);
|
|
1963
|
-
down = this.createIndexSql(table, index);
|
|
1964
|
-
return [4 /*yield*/, this.executeQueries(up, down)];
|
|
1965
|
-
case 4:
|
|
1966
|
-
_b.sent();
|
|
1967
|
-
table.removeIndex(index);
|
|
1968
|
-
return [2 /*return*/];
|
|
1969
|
-
}
|
|
1970
|
-
});
|
|
1971
|
-
});
|
|
1972
|
-
};
|
|
1208
|
+
async dropIndex(tableOrName, indexOrName) {
|
|
1209
|
+
const table = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
|
|
1210
|
+
? tableOrName
|
|
1211
|
+
: await this.getCachedTable(tableOrName);
|
|
1212
|
+
const index = InstanceChecker_1.InstanceChecker.isTableIndex(indexOrName)
|
|
1213
|
+
? indexOrName
|
|
1214
|
+
: table.indices.find((i) => i.name === indexOrName);
|
|
1215
|
+
if (!index)
|
|
1216
|
+
throw new error_1.TypeORMError(`Supplied index ${indexOrName} was not found in table ${table.name}`);
|
|
1217
|
+
// old index may be passed without name. In this case we generate index name manually.
|
|
1218
|
+
if (!index.name)
|
|
1219
|
+
index.name = this.generateIndexName(table, index);
|
|
1220
|
+
const up = this.dropIndexSql(index);
|
|
1221
|
+
const down = this.createIndexSql(table, index);
|
|
1222
|
+
await this.executeQueries(up, down);
|
|
1223
|
+
table.removeIndex(index);
|
|
1224
|
+
}
|
|
1973
1225
|
/**
|
|
1974
1226
|
* Drops an indices from the table.
|
|
1975
1227
|
*/
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
return tslib_1.__generator(this, function (_a) {
|
|
1981
|
-
switch (_a.label) {
|
|
1982
|
-
case 0:
|
|
1983
|
-
promises = indices.map(function (index) {
|
|
1984
|
-
return _this.dropIndex(tableOrName, index);
|
|
1985
|
-
});
|
|
1986
|
-
return [4 /*yield*/, Promise.all(promises)];
|
|
1987
|
-
case 1:
|
|
1988
|
-
_a.sent();
|
|
1989
|
-
return [2 /*return*/];
|
|
1990
|
-
}
|
|
1991
|
-
});
|
|
1992
|
-
});
|
|
1993
|
-
};
|
|
1228
|
+
async dropIndices(tableOrName, indices) {
|
|
1229
|
+
const promises = indices.map((index) => this.dropIndex(tableOrName, index));
|
|
1230
|
+
await Promise.all(promises);
|
|
1231
|
+
}
|
|
1994
1232
|
/**
|
|
1995
1233
|
* Clears all table contents.
|
|
1996
1234
|
* Note: this operation uses SQL's TRUNCATE query which cannot be reverted in transactions.
|
|
1997
1235
|
*/
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
switch (_a.label) {
|
|
2002
|
-
case 0: return [4 /*yield*/, this.query("TRUNCATE TABLE ".concat(this.escapePath(tableName)))];
|
|
2003
|
-
case 1:
|
|
2004
|
-
_a.sent();
|
|
2005
|
-
return [2 /*return*/];
|
|
2006
|
-
}
|
|
2007
|
-
});
|
|
2008
|
-
});
|
|
2009
|
-
};
|
|
1236
|
+
async clearTable(tableName) {
|
|
1237
|
+
await this.query(`TRUNCATE TABLE ${this.escapePath(tableName)}`);
|
|
1238
|
+
}
|
|
2010
1239
|
/**
|
|
2011
1240
|
* Removes all tables from the currently connected database.
|
|
2012
1241
|
*/
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
];
|
|
2044
|
-
case 6:
|
|
2045
|
-
_a.sent();
|
|
2046
|
-
dropTablesQuery = "SELECT 'DROP TABLE \"' || TABLE_NAME || '\" CASCADE CONSTRAINTS' AS \"query\" FROM \"USER_TABLES\"";
|
|
2047
|
-
return [4 /*yield*/, this.query(dropTablesQuery)];
|
|
2048
|
-
case 7:
|
|
2049
|
-
dropTableQueries = _a.sent();
|
|
2050
|
-
return [4 /*yield*/, Promise.all(dropTableQueries.map(function (query) { return _this.query(query["query"]); }))];
|
|
2051
|
-
case 8:
|
|
2052
|
-
_a.sent();
|
|
2053
|
-
if (!!isAnotherTransactionActive) return [3 /*break*/, 10];
|
|
2054
|
-
return [4 /*yield*/, this.commitTransaction()];
|
|
2055
|
-
case 9:
|
|
2056
|
-
_a.sent();
|
|
2057
|
-
_a.label = 10;
|
|
2058
|
-
case 10: return [3 /*break*/, 17];
|
|
2059
|
-
case 11:
|
|
2060
|
-
error_2 = _a.sent();
|
|
2061
|
-
_a.label = 12;
|
|
2062
|
-
case 12:
|
|
2063
|
-
_a.trys.push([12, 15, , 16]);
|
|
2064
|
-
if (!!isAnotherTransactionActive) return [3 /*break*/, 14];
|
|
2065
|
-
return [4 /*yield*/, this.rollbackTransaction()];
|
|
2066
|
-
case 13:
|
|
2067
|
-
_a.sent();
|
|
2068
|
-
_a.label = 14;
|
|
2069
|
-
case 14: return [3 /*break*/, 16];
|
|
2070
|
-
case 15:
|
|
2071
|
-
rollbackError_1 = _a.sent();
|
|
2072
|
-
return [3 /*break*/, 16];
|
|
2073
|
-
case 16: throw error_2;
|
|
2074
|
-
case 17: return [2 /*return*/];
|
|
2075
|
-
}
|
|
2076
|
-
});
|
|
2077
|
-
});
|
|
2078
|
-
};
|
|
1242
|
+
async clearDatabase() {
|
|
1243
|
+
const isAnotherTransactionActive = this.isTransactionActive;
|
|
1244
|
+
if (!isAnotherTransactionActive)
|
|
1245
|
+
await this.startTransaction();
|
|
1246
|
+
try {
|
|
1247
|
+
// drop views
|
|
1248
|
+
const dropViewsQuery = `SELECT 'DROP VIEW "' || VIEW_NAME || '"' AS "query" FROM "USER_VIEWS"`;
|
|
1249
|
+
const dropViewQueries = await this.query(dropViewsQuery);
|
|
1250
|
+
await Promise.all(dropViewQueries.map((query) => this.query(query["query"])));
|
|
1251
|
+
// drop materialized views
|
|
1252
|
+
const dropMatViewsQuery = `SELECT 'DROP MATERIALIZED VIEW "' || MVIEW_NAME || '"' AS "query" FROM "USER_MVIEWS"`;
|
|
1253
|
+
const dropMatViewQueries = await this.query(dropMatViewsQuery);
|
|
1254
|
+
await Promise.all(dropMatViewQueries.map((query) => this.query(query["query"])));
|
|
1255
|
+
// drop tables
|
|
1256
|
+
const dropTablesQuery = `SELECT 'DROP TABLE "' || TABLE_NAME || '" CASCADE CONSTRAINTS' AS "query" FROM "USER_TABLES"`;
|
|
1257
|
+
const dropTableQueries = await this.query(dropTablesQuery);
|
|
1258
|
+
await Promise.all(dropTableQueries.map((query) => this.query(query["query"])));
|
|
1259
|
+
if (!isAnotherTransactionActive)
|
|
1260
|
+
await this.commitTransaction();
|
|
1261
|
+
}
|
|
1262
|
+
catch (error) {
|
|
1263
|
+
try {
|
|
1264
|
+
// we throw original error even if rollback thrown an error
|
|
1265
|
+
if (!isAnotherTransactionActive)
|
|
1266
|
+
await this.rollbackTransaction();
|
|
1267
|
+
}
|
|
1268
|
+
catch (rollbackError) { }
|
|
1269
|
+
throw error;
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
2079
1272
|
// -------------------------------------------------------------------------
|
|
2080
1273
|
// Protected Methods
|
|
2081
1274
|
// -------------------------------------------------------------------------
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
case 4:
|
|
2113
|
-
dbViews = _a.sent();
|
|
2114
|
-
return [2 /*return*/, dbViews.map(function (dbView) {
|
|
2115
|
-
var parsedName = _this.driver.parseTableName(dbView["name"]);
|
|
2116
|
-
var view = new View_1.View();
|
|
2117
|
-
view.database =
|
|
2118
|
-
parsedName.database || dbView["database"] || currentDatabase;
|
|
2119
|
-
view.schema = parsedName.schema || dbView["schema"] || currentSchema;
|
|
2120
|
-
view.name = parsedName.tableName;
|
|
2121
|
-
view.expression = dbView["value"];
|
|
2122
|
-
view.materialized =
|
|
2123
|
-
dbView["type"] === MetadataTableType_1.MetadataTableType.MATERIALIZED_VIEW;
|
|
2124
|
-
return view;
|
|
2125
|
-
})];
|
|
2126
|
-
}
|
|
2127
|
-
});
|
|
1275
|
+
async loadViews(viewNames) {
|
|
1276
|
+
const hasTable = await this.hasTable(this.getTypeormMetadataTableName());
|
|
1277
|
+
if (!hasTable) {
|
|
1278
|
+
return [];
|
|
1279
|
+
}
|
|
1280
|
+
if (!viewNames) {
|
|
1281
|
+
viewNames = [];
|
|
1282
|
+
}
|
|
1283
|
+
const currentDatabase = await this.getCurrentDatabase();
|
|
1284
|
+
const currentSchema = await this.getCurrentSchema();
|
|
1285
|
+
const viewNamesString = viewNames
|
|
1286
|
+
.map((name) => "'" + name + "'")
|
|
1287
|
+
.join(", ");
|
|
1288
|
+
let query = `SELECT "T".* FROM ${this.escapePath(this.getTypeormMetadataTableName())} "T" ` +
|
|
1289
|
+
`INNER JOIN "USER_OBJECTS" "O" ON "O"."OBJECT_NAME" = "T"."name" AND "O"."OBJECT_TYPE" IN ( 'MATERIALIZED VIEW', 'VIEW' ) ` +
|
|
1290
|
+
`WHERE "T"."type" IN ( '${MetadataTableType_1.MetadataTableType.MATERIALIZED_VIEW}', '${MetadataTableType_1.MetadataTableType.VIEW}' )`;
|
|
1291
|
+
if (viewNamesString.length > 0)
|
|
1292
|
+
query += ` AND "T"."name" IN (${viewNamesString})`;
|
|
1293
|
+
const dbViews = await this.query(query);
|
|
1294
|
+
return dbViews.map((dbView) => {
|
|
1295
|
+
const parsedName = this.driver.parseTableName(dbView["name"]);
|
|
1296
|
+
const view = new View_1.View();
|
|
1297
|
+
view.database =
|
|
1298
|
+
parsedName.database || dbView["database"] || currentDatabase;
|
|
1299
|
+
view.schema = parsedName.schema || dbView["schema"] || currentSchema;
|
|
1300
|
+
view.name = parsedName.tableName;
|
|
1301
|
+
view.expression = dbView["value"];
|
|
1302
|
+
view.materialized =
|
|
1303
|
+
dbView["type"] === MetadataTableType_1.MetadataTableType.MATERIALIZED_VIEW;
|
|
1304
|
+
return view;
|
|
2128
1305
|
});
|
|
2129
|
-
}
|
|
1306
|
+
}
|
|
2130
1307
|
/**
|
|
2131
1308
|
* Loads all tables (with given names) from the database and creates a Table from them.
|
|
2132
1309
|
*/
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
return [4 /*yield*/, this.query(tablesSql)];
|
|
2156
|
-
case 3:
|
|
2157
|
-
_b.apply(_a, _c.concat([tslib_1.__spreadArray.apply(void 0, _d.concat([tslib_1.__read.apply(void 0, [(_k.sent())]), false]))]));
|
|
2158
|
-
return [3 /*break*/, 6];
|
|
2159
|
-
case 4:
|
|
2160
|
-
tablesCondition = tableNames
|
|
2161
|
-
.map(function (tableName) {
|
|
2162
|
-
var parts = tableName.split(".");
|
|
2163
|
-
if (parts.length >= 3) {
|
|
2164
|
-
var _a = tslib_1.__read(parts, 3), schema = _a[1], name_1 = _a[2];
|
|
2165
|
-
return "(\"OWNER\" = '".concat(schema, "' AND \"TABLE_NAME\" = '").concat(name_1, "')");
|
|
2166
|
-
}
|
|
2167
|
-
else if (parts.length === 2) {
|
|
2168
|
-
var _b = tslib_1.__read(parts, 2), schema = _b[0], name_2 = _b[1];
|
|
2169
|
-
return "(\"OWNER\" = '".concat(schema, "' AND \"TABLE_NAME\" = '").concat(name_2, "')");
|
|
2170
|
-
}
|
|
2171
|
-
else if (parts.length === 1) {
|
|
2172
|
-
var _c = tslib_1.__read(parts, 1), name_3 = _c[0];
|
|
2173
|
-
return "(\"TABLE_NAME\" = '".concat(name_3, "')");
|
|
2174
|
-
}
|
|
2175
|
-
else {
|
|
2176
|
-
return "(1=0)";
|
|
2177
|
-
}
|
|
2178
|
-
})
|
|
2179
|
-
.join(" OR ");
|
|
2180
|
-
tablesSql = "SELECT \"TABLE_NAME\", \"OWNER\" FROM \"ALL_TABLES\" WHERE ".concat(tablesCondition);
|
|
2181
|
-
_f = (_e = dbTables.push).apply;
|
|
2182
|
-
_g = [dbTables];
|
|
2183
|
-
_h = [[]];
|
|
2184
|
-
return [4 /*yield*/, this.query(tablesSql)];
|
|
2185
|
-
case 5:
|
|
2186
|
-
_f.apply(_e, _g.concat([tslib_1.__spreadArray.apply(void 0, _h.concat([tslib_1.__read.apply(void 0, [(_k.sent())]), false]))]));
|
|
2187
|
-
_k.label = 6;
|
|
2188
|
-
case 6:
|
|
2189
|
-
// if tables were not found in the db, no need to proceed
|
|
2190
|
-
if (dbTables.length === 0) {
|
|
2191
|
-
return [2 /*return*/, []];
|
|
2192
|
-
}
|
|
2193
|
-
columnsCondition = dbTables
|
|
2194
|
-
.map(function (_a) {
|
|
2195
|
-
var TABLE_NAME = _a.TABLE_NAME, OWNER = _a.OWNER;
|
|
2196
|
-
return "(\"C\".\"OWNER\" = '".concat(OWNER, "' AND \"C\".\"TABLE_NAME\" = '").concat(TABLE_NAME, "')");
|
|
2197
|
-
})
|
|
2198
|
-
.join(" OR ");
|
|
2199
|
-
columnsSql = "SELECT * FROM \"ALL_TAB_COLS\" \"C\" WHERE (".concat(columnsCondition, ")");
|
|
2200
|
-
indicesSql = "SELECT \"C\".\"INDEX_NAME\", \"C\".\"OWNER\", \"C\".\"TABLE_NAME\", \"C\".\"UNIQUENESS\", " +
|
|
2201
|
-
"LISTAGG (\"COL\".\"COLUMN_NAME\", ',') WITHIN GROUP (ORDER BY \"COL\".\"COLUMN_NAME\") AS \"COLUMN_NAMES\" " +
|
|
2202
|
-
"FROM \"ALL_INDEXES\" \"C\" " +
|
|
2203
|
-
"INNER JOIN \"ALL_IND_COLUMNS\" \"COL\" ON \"COL\".\"INDEX_OWNER\" = \"C\".\"OWNER\" AND \"COL\".\"INDEX_NAME\" = \"C\".\"INDEX_NAME\" " +
|
|
2204
|
-
"LEFT JOIN \"ALL_CONSTRAINTS\" \"CON\" ON \"CON\".\"OWNER\" = \"C\".\"OWNER\" AND \"CON\".\"CONSTRAINT_NAME\" = \"C\".\"INDEX_NAME\" " +
|
|
2205
|
-
"WHERE (".concat(columnsCondition, ") AND \"CON\".\"CONSTRAINT_NAME\" IS NULL ") +
|
|
2206
|
-
"GROUP BY \"C\".\"INDEX_NAME\", \"C\".\"OWNER\", \"C\".\"TABLE_NAME\", \"C\".\"UNIQUENESS\"";
|
|
2207
|
-
foreignKeysSql = "SELECT \"C\".\"CONSTRAINT_NAME\", \"C\".\"OWNER\", \"C\".\"TABLE_NAME\", \"COL\".\"COLUMN_NAME\", \"REF_COL\".\"TABLE_NAME\" AS \"REFERENCED_TABLE_NAME\", " +
|
|
2208
|
-
"\"REF_COL\".\"COLUMN_NAME\" AS \"REFERENCED_COLUMN_NAME\", \"C\".\"DELETE_RULE\" AS \"ON_DELETE\" " +
|
|
2209
|
-
"FROM \"ALL_CONSTRAINTS\" \"C\" " +
|
|
2210
|
-
"INNER JOIN \"ALL_CONS_COLUMNS\" \"COL\" ON \"COL\".\"OWNER\" = \"C\".\"OWNER\" AND \"COL\".\"CONSTRAINT_NAME\" = \"C\".\"CONSTRAINT_NAME\" " +
|
|
2211
|
-
"INNER JOIN \"ALL_CONS_COLUMNS\" \"REF_COL\" ON \"REF_COL\".\"OWNER\" = \"C\".\"R_OWNER\" AND \"REF_COL\".\"CONSTRAINT_NAME\" = \"C\".\"R_CONSTRAINT_NAME\" AND \"REF_COL\".\"POSITION\" = \"COL\".\"POSITION\" " +
|
|
2212
|
-
"WHERE (".concat(columnsCondition, ") AND \"C\".\"CONSTRAINT_TYPE\" = 'R'");
|
|
2213
|
-
constraintsSql = "SELECT \"C\".\"CONSTRAINT_NAME\", \"C\".\"CONSTRAINT_TYPE\", \"C\".\"OWNER\", \"C\".\"TABLE_NAME\", \"COL\".\"COLUMN_NAME\", \"C\".\"SEARCH_CONDITION\" " +
|
|
2214
|
-
"FROM \"ALL_CONSTRAINTS\" \"C\" " +
|
|
2215
|
-
"INNER JOIN \"ALL_CONS_COLUMNS\" \"COL\" ON \"COL\".\"OWNER\" = \"C\".\"OWNER\" AND \"COL\".\"CONSTRAINT_NAME\" = \"C\".\"CONSTRAINT_NAME\" " +
|
|
2216
|
-
"WHERE (".concat(columnsCondition, ") AND \"C\".\"CONSTRAINT_TYPE\" IN ('C', 'U', 'P') AND \"C\".\"GENERATED\" = 'USER NAME'");
|
|
2217
|
-
return [4 /*yield*/, Promise.all([
|
|
2218
|
-
this.query(columnsSql),
|
|
2219
|
-
this.query(indicesSql),
|
|
2220
|
-
this.query(foreignKeysSql),
|
|
2221
|
-
this.query(constraintsSql),
|
|
2222
|
-
])
|
|
2223
|
-
// create tables for loaded tables
|
|
2224
|
-
];
|
|
2225
|
-
case 7:
|
|
2226
|
-
_j = tslib_1.__read.apply(void 0, [_k.sent()
|
|
2227
|
-
// create tables for loaded tables
|
|
2228
|
-
, 4]), dbColumns = _j[0], dbIndices = _j[1], dbForeignKeys = _j[2], dbConstraints = _j[3];
|
|
2229
|
-
return [4 /*yield*/, Promise.all(dbTables.map(function (dbTable) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
2230
|
-
var table, owner, _a, tableUniqueConstraints, tableCheckConstraints, tableForeignKeyConstraints;
|
|
2231
|
-
var _this = this;
|
|
2232
|
-
return tslib_1.__generator(this, function (_b) {
|
|
2233
|
-
switch (_b.label) {
|
|
2234
|
-
case 0:
|
|
2235
|
-
table = new Table_1.Table();
|
|
2236
|
-
owner = dbTable["OWNER"] === currentSchema &&
|
|
2237
|
-
(!this.driver.options.schema ||
|
|
2238
|
-
this.driver.options.schema === currentSchema)
|
|
2239
|
-
? undefined
|
|
2240
|
-
: dbTable["OWNER"];
|
|
2241
|
-
table.database = currentDatabase;
|
|
2242
|
-
table.schema = dbTable["OWNER"];
|
|
2243
|
-
table.name = this.driver.buildTableName(dbTable["TABLE_NAME"], owner);
|
|
2244
|
-
// create columns from the loaded columns
|
|
2245
|
-
_a = table;
|
|
2246
|
-
return [4 /*yield*/, Promise.all(dbColumns
|
|
2247
|
-
.filter(function (dbColumn) {
|
|
2248
|
-
return dbColumn["OWNER"] === dbTable["OWNER"] &&
|
|
2249
|
-
dbColumn["TABLE_NAME"] ===
|
|
2250
|
-
dbTable["TABLE_NAME"];
|
|
2251
|
-
})
|
|
2252
|
-
.map(function (dbColumn) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
2253
|
-
var columnConstraints, uniqueConstraints, isConstraintComposite, tableColumn, length_1, primaryConstraint, anotherPrimaryConstraints, columnNames, pkName, asExpressionQuery, results;
|
|
2254
|
-
return tslib_1.__generator(this, function (_a) {
|
|
2255
|
-
switch (_a.label) {
|
|
2256
|
-
case 0:
|
|
2257
|
-
columnConstraints = dbConstraints.filter(function (dbConstraint) {
|
|
2258
|
-
return dbConstraint["OWNER"] ===
|
|
2259
|
-
dbColumn["OWNER"] &&
|
|
2260
|
-
dbConstraint["TABLE_NAME"] ===
|
|
2261
|
-
dbColumn["TABLE_NAME"] &&
|
|
2262
|
-
dbConstraint["COLUMN_NAME"] ===
|
|
2263
|
-
dbColumn["COLUMN_NAME"];
|
|
2264
|
-
});
|
|
2265
|
-
uniqueConstraints = columnConstraints.filter(function (constraint) {
|
|
2266
|
-
return constraint["CONSTRAINT_TYPE"] === "U";
|
|
2267
|
-
});
|
|
2268
|
-
isConstraintComposite = uniqueConstraints.every(function (uniqueConstraint) {
|
|
2269
|
-
return dbConstraints.some(function (dbConstraint) {
|
|
2270
|
-
return dbConstraint["OWNER"] ===
|
|
2271
|
-
dbColumn["OWNER"] &&
|
|
2272
|
-
dbConstraint["TABLE_NAME"] ===
|
|
2273
|
-
dbColumn["TABLE_NAME"] &&
|
|
2274
|
-
dbConstraint["COLUMN_NAME"] !==
|
|
2275
|
-
dbColumn["COLUMN_NAME"] &&
|
|
2276
|
-
dbConstraint["CONSTRAINT_NAME"] ===
|
|
2277
|
-
uniqueConstraint["CONSTRAINT_NAME"] &&
|
|
2278
|
-
dbConstraint["CONSTRAINT_TYPE"] ===
|
|
2279
|
-
"U";
|
|
2280
|
-
});
|
|
2281
|
-
});
|
|
2282
|
-
tableColumn = new TableColumn_1.TableColumn();
|
|
2283
|
-
tableColumn.name = dbColumn["COLUMN_NAME"];
|
|
2284
|
-
tableColumn.type =
|
|
2285
|
-
dbColumn["DATA_TYPE"].toLowerCase();
|
|
2286
|
-
if (tableColumn.type.indexOf("(") !== -1)
|
|
2287
|
-
tableColumn.type = tableColumn.type.replace(/\([0-9]*\)/, "");
|
|
2288
|
-
// check only columns that have length property
|
|
2289
|
-
if (this.driver.withLengthColumnTypes.indexOf(tableColumn.type) !== -1) {
|
|
2290
|
-
length_1 = tableColumn.type === "raw"
|
|
2291
|
-
? dbColumn["DATA_LENGTH"]
|
|
2292
|
-
: dbColumn["CHAR_COL_DECL_LENGTH"];
|
|
2293
|
-
tableColumn.length =
|
|
2294
|
-
length_1 &&
|
|
2295
|
-
!this.isDefaultColumnLength(table, tableColumn, length_1)
|
|
2296
|
-
? length_1.toString()
|
|
2297
|
-
: "";
|
|
2298
|
-
}
|
|
2299
|
-
if (tableColumn.type === "number" ||
|
|
2300
|
-
tableColumn.type === "float") {
|
|
2301
|
-
if (dbColumn["DATA_PRECISION"] !== null &&
|
|
2302
|
-
!this.isDefaultColumnPrecision(table, tableColumn, dbColumn["DATA_PRECISION"]))
|
|
2303
|
-
tableColumn.precision =
|
|
2304
|
-
dbColumn["DATA_PRECISION"];
|
|
2305
|
-
if (dbColumn["DATA_SCALE"] !== null &&
|
|
2306
|
-
!this.isDefaultColumnScale(table, tableColumn, dbColumn["DATA_SCALE"]))
|
|
2307
|
-
tableColumn.scale = dbColumn["DATA_SCALE"];
|
|
2308
|
-
}
|
|
2309
|
-
else if ((tableColumn.type === "timestamp" ||
|
|
2310
|
-
tableColumn.type ===
|
|
2311
|
-
"timestamp with time zone" ||
|
|
2312
|
-
tableColumn.type ===
|
|
2313
|
-
"timestamp with local time zone") &&
|
|
2314
|
-
dbColumn["DATA_SCALE"] !== null) {
|
|
2315
|
-
tableColumn.precision =
|
|
2316
|
-
!this.isDefaultColumnPrecision(table, tableColumn, dbColumn["DATA_SCALE"])
|
|
2317
|
-
? dbColumn["DATA_SCALE"]
|
|
2318
|
-
: undefined;
|
|
2319
|
-
}
|
|
2320
|
-
tableColumn.default =
|
|
2321
|
-
dbColumn["DATA_DEFAULT"] !== null &&
|
|
2322
|
-
dbColumn["DATA_DEFAULT"] !== undefined &&
|
|
2323
|
-
dbColumn["VIRTUAL_COLUMN"] === "NO" &&
|
|
2324
|
-
dbColumn["DATA_DEFAULT"].trim() !== "NULL"
|
|
2325
|
-
? (tableColumn.default =
|
|
2326
|
-
dbColumn["DATA_DEFAULT"].trim())
|
|
2327
|
-
: undefined;
|
|
2328
|
-
primaryConstraint = columnConstraints.find(function (constraint) {
|
|
2329
|
-
return constraint["CONSTRAINT_TYPE"] === "P";
|
|
2330
|
-
});
|
|
2331
|
-
if (primaryConstraint) {
|
|
2332
|
-
tableColumn.isPrimary = true;
|
|
2333
|
-
anotherPrimaryConstraints = dbConstraints.filter(function (constraint) {
|
|
2334
|
-
return constraint["OWNER"] ===
|
|
2335
|
-
dbColumn["OWNER"] &&
|
|
2336
|
-
constraint["TABLE_NAME"] ===
|
|
2337
|
-
dbColumn["TABLE_NAME"] &&
|
|
2338
|
-
constraint["COLUMN_NAME"] !==
|
|
2339
|
-
dbColumn["COLUMN_NAME"] &&
|
|
2340
|
-
constraint["CONSTRAINT_TYPE"] ===
|
|
2341
|
-
"P";
|
|
2342
|
-
});
|
|
2343
|
-
columnNames = anotherPrimaryConstraints.map(function (constraint) {
|
|
2344
|
-
return constraint["COLUMN_NAME"];
|
|
2345
|
-
});
|
|
2346
|
-
columnNames.push(dbColumn["COLUMN_NAME"]);
|
|
2347
|
-
pkName = this.connection.namingStrategy.primaryKeyName(table, columnNames);
|
|
2348
|
-
// if primary key has user-defined constraint name, write it in table column
|
|
2349
|
-
if (primaryConstraint["CONSTRAINT_NAME"] !==
|
|
2350
|
-
pkName) {
|
|
2351
|
-
tableColumn.primaryKeyConstraintName =
|
|
2352
|
-
primaryConstraint["CONSTRAINT_NAME"];
|
|
2353
|
-
}
|
|
2354
|
-
}
|
|
2355
|
-
tableColumn.isNullable =
|
|
2356
|
-
dbColumn["NULLABLE"] === "Y";
|
|
2357
|
-
tableColumn.isUnique =
|
|
2358
|
-
uniqueConstraints.length > 0 &&
|
|
2359
|
-
!isConstraintComposite;
|
|
2360
|
-
tableColumn.isGenerated =
|
|
2361
|
-
dbColumn["IDENTITY_COLUMN"] === "YES";
|
|
2362
|
-
if (tableColumn.isGenerated) {
|
|
2363
|
-
tableColumn.generationStrategy = "increment";
|
|
2364
|
-
tableColumn.default = undefined;
|
|
2365
|
-
}
|
|
2366
|
-
tableColumn.comment = ""; // todo
|
|
2367
|
-
if (!(dbColumn["VIRTUAL_COLUMN"] === "YES")) return [3 /*break*/, 3];
|
|
2368
|
-
tableColumn.generatedType = "VIRTUAL";
|
|
2369
|
-
return [4 /*yield*/, this.selectTypeormMetadataSql({
|
|
2370
|
-
table: dbTable["TABLE_NAME"],
|
|
2371
|
-
type: MetadataTableType_1.MetadataTableType.GENERATED_COLUMN,
|
|
2372
|
-
name: tableColumn.name,
|
|
2373
|
-
})];
|
|
2374
|
-
case 1:
|
|
2375
|
-
asExpressionQuery = _a.sent();
|
|
2376
|
-
return [4 /*yield*/, this.query(asExpressionQuery.query, asExpressionQuery.parameters)];
|
|
2377
|
-
case 2:
|
|
2378
|
-
results = _a.sent();
|
|
2379
|
-
if (results[0] && results[0].value) {
|
|
2380
|
-
tableColumn.asExpression = results[0].value;
|
|
2381
|
-
}
|
|
2382
|
-
else {
|
|
2383
|
-
tableColumn.asExpression = "";
|
|
2384
|
-
}
|
|
2385
|
-
_a.label = 3;
|
|
2386
|
-
case 3: return [2 /*return*/, tableColumn];
|
|
2387
|
-
}
|
|
2388
|
-
});
|
|
2389
|
-
}); }))
|
|
2390
|
-
// find unique constraints of table, group them by constraint name and build TableUnique.
|
|
2391
|
-
];
|
|
2392
|
-
case 1:
|
|
2393
|
-
// create columns from the loaded columns
|
|
2394
|
-
_a.columns = _b.sent();
|
|
2395
|
-
tableUniqueConstraints = OrmUtils_1.OrmUtils.uniq(dbConstraints.filter(function (dbConstraint) {
|
|
2396
|
-
return (dbConstraint["TABLE_NAME"] ===
|
|
2397
|
-
dbTable["TABLE_NAME"] &&
|
|
2398
|
-
dbConstraint["OWNER"] === dbTable["OWNER"] &&
|
|
2399
|
-
dbConstraint["CONSTRAINT_TYPE"] === "U");
|
|
2400
|
-
}), function (dbConstraint) { return dbConstraint["CONSTRAINT_NAME"]; });
|
|
2401
|
-
table.uniques = tableUniqueConstraints.map(function (constraint) {
|
|
2402
|
-
var uniques = dbConstraints.filter(function (dbC) {
|
|
2403
|
-
return dbC["CONSTRAINT_NAME"] ===
|
|
2404
|
-
constraint["CONSTRAINT_NAME"];
|
|
2405
|
-
});
|
|
2406
|
-
return new TableUnique_1.TableUnique({
|
|
2407
|
-
name: constraint["CONSTRAINT_NAME"],
|
|
2408
|
-
columnNames: uniques.map(function (u) { return u["COLUMN_NAME"]; }),
|
|
2409
|
-
});
|
|
2410
|
-
});
|
|
2411
|
-
tableCheckConstraints = OrmUtils_1.OrmUtils.uniq(dbConstraints.filter(function (dbConstraint) {
|
|
2412
|
-
return (dbConstraint["TABLE_NAME"] ===
|
|
2413
|
-
dbTable["TABLE_NAME"] &&
|
|
2414
|
-
dbConstraint["OWNER"] === dbTable["OWNER"] &&
|
|
2415
|
-
dbConstraint["CONSTRAINT_TYPE"] === "C");
|
|
2416
|
-
}), function (dbConstraint) { return dbConstraint["CONSTRAINT_NAME"]; });
|
|
2417
|
-
table.checks = tableCheckConstraints.map(function (constraint) {
|
|
2418
|
-
var checks = dbConstraints.filter(function (dbC) {
|
|
2419
|
-
return dbC["TABLE_NAME"] === constraint["TABLE_NAME"] &&
|
|
2420
|
-
dbC["OWNER"] === constraint["OWNER"] &&
|
|
2421
|
-
dbC["CONSTRAINT_NAME"] ===
|
|
2422
|
-
constraint["CONSTRAINT_NAME"];
|
|
2423
|
-
});
|
|
2424
|
-
return new TableCheck_1.TableCheck({
|
|
2425
|
-
name: constraint["CONSTRAINT_NAME"],
|
|
2426
|
-
columnNames: checks.map(function (c) { return c["COLUMN_NAME"]; }),
|
|
2427
|
-
expression: constraint["SEARCH_CONDITION"],
|
|
2428
|
-
});
|
|
2429
|
-
});
|
|
2430
|
-
tableForeignKeyConstraints = OrmUtils_1.OrmUtils.uniq(dbForeignKeys.filter(function (dbForeignKey) {
|
|
2431
|
-
return dbForeignKey["OWNER"] === dbTable["OWNER"] &&
|
|
2432
|
-
dbForeignKey["TABLE_NAME"] ===
|
|
2433
|
-
dbTable["TABLE_NAME"];
|
|
2434
|
-
}), function (dbForeignKey) { return dbForeignKey["CONSTRAINT_NAME"]; });
|
|
2435
|
-
table.foreignKeys = tableForeignKeyConstraints.map(function (dbForeignKey) {
|
|
2436
|
-
var foreignKeys = dbForeignKeys.filter(function (dbFk) {
|
|
2437
|
-
return dbFk["TABLE_NAME"] ===
|
|
2438
|
-
dbForeignKey["TABLE_NAME"] &&
|
|
2439
|
-
dbFk["OWNER"] === dbForeignKey["OWNER"] &&
|
|
2440
|
-
dbFk["CONSTRAINT_NAME"] ===
|
|
2441
|
-
dbForeignKey["CONSTRAINT_NAME"];
|
|
2442
|
-
});
|
|
2443
|
-
return new TableForeignKey_1.TableForeignKey({
|
|
2444
|
-
name: dbForeignKey["CONSTRAINT_NAME"],
|
|
2445
|
-
columnNames: foreignKeys.map(function (dbFk) { return dbFk["COLUMN_NAME"]; }),
|
|
2446
|
-
referencedDatabase: table.database,
|
|
2447
|
-
referencedSchema: dbForeignKey["OWNER"],
|
|
2448
|
-
referencedTableName: dbForeignKey["REFERENCED_TABLE_NAME"],
|
|
2449
|
-
referencedColumnNames: foreignKeys.map(function (dbFk) { return dbFk["REFERENCED_COLUMN_NAME"]; }),
|
|
2450
|
-
onDelete: dbForeignKey["ON_DELETE"],
|
|
2451
|
-
onUpdate: "NO ACTION", // Oracle does not have onUpdate option in FK's, but we need it for proper synchronization
|
|
2452
|
-
});
|
|
2453
|
-
});
|
|
2454
|
-
// create TableIndex objects from the loaded indices
|
|
2455
|
-
table.indices = dbIndices
|
|
2456
|
-
.filter(function (dbIndex) {
|
|
2457
|
-
return dbIndex["TABLE_NAME"] === dbTable["TABLE_NAME"] &&
|
|
2458
|
-
dbIndex["OWNER"] === dbTable["OWNER"];
|
|
2459
|
-
})
|
|
2460
|
-
.map(function (dbIndex) {
|
|
2461
|
-
return new TableIndex_1.TableIndex({
|
|
2462
|
-
name: dbIndex["INDEX_NAME"],
|
|
2463
|
-
columnNames: dbIndex["COLUMN_NAMES"].split(","),
|
|
2464
|
-
isUnique: dbIndex["UNIQUENESS"] === "UNIQUE",
|
|
2465
|
-
});
|
|
2466
|
-
});
|
|
2467
|
-
return [2 /*return*/, table];
|
|
2468
|
-
}
|
|
2469
|
-
});
|
|
2470
|
-
}); }))];
|
|
2471
|
-
case 8:
|
|
2472
|
-
// create tables for loaded tables
|
|
2473
|
-
return [2 /*return*/, _k.sent()];
|
|
1310
|
+
async loadTables(tableNames) {
|
|
1311
|
+
if (tableNames && tableNames.length === 0) {
|
|
1312
|
+
return [];
|
|
1313
|
+
}
|
|
1314
|
+
const dbTables = [];
|
|
1315
|
+
const currentSchema = await this.getCurrentSchema();
|
|
1316
|
+
const currentDatabase = await this.getCurrentDatabase();
|
|
1317
|
+
if (!tableNames) {
|
|
1318
|
+
const tablesSql = `SELECT "TABLE_NAME", "OWNER" FROM "ALL_TABLES"`;
|
|
1319
|
+
dbTables.push(...(await this.query(tablesSql)));
|
|
1320
|
+
}
|
|
1321
|
+
else {
|
|
1322
|
+
const tablesCondition = tableNames
|
|
1323
|
+
.map((tableName) => {
|
|
1324
|
+
const parts = tableName.split(".");
|
|
1325
|
+
if (parts.length >= 3) {
|
|
1326
|
+
const [, schema, name] = parts;
|
|
1327
|
+
return `("OWNER" = '${schema}' AND "TABLE_NAME" = '${name}')`;
|
|
1328
|
+
}
|
|
1329
|
+
else if (parts.length === 2) {
|
|
1330
|
+
const [schema, name] = parts;
|
|
1331
|
+
return `("OWNER" = '${schema}' AND "TABLE_NAME" = '${name}')`;
|
|
2474
1332
|
}
|
|
1333
|
+
else if (parts.length === 1) {
|
|
1334
|
+
const [name] = parts;
|
|
1335
|
+
return `("TABLE_NAME" = '${name}')`;
|
|
1336
|
+
}
|
|
1337
|
+
else {
|
|
1338
|
+
return `(1=0)`;
|
|
1339
|
+
}
|
|
1340
|
+
})
|
|
1341
|
+
.join(" OR ");
|
|
1342
|
+
const tablesSql = `SELECT "TABLE_NAME", "OWNER" FROM "ALL_TABLES" WHERE ${tablesCondition}`;
|
|
1343
|
+
dbTables.push(...(await this.query(tablesSql)));
|
|
1344
|
+
}
|
|
1345
|
+
// if tables were not found in the db, no need to proceed
|
|
1346
|
+
if (dbTables.length === 0) {
|
|
1347
|
+
return [];
|
|
1348
|
+
}
|
|
1349
|
+
// load tables, columns, indices and foreign keys
|
|
1350
|
+
const columnsCondition = dbTables
|
|
1351
|
+
.map(({ TABLE_NAME, OWNER }) => {
|
|
1352
|
+
return `("C"."OWNER" = '${OWNER}' AND "C"."TABLE_NAME" = '${TABLE_NAME}')`;
|
|
1353
|
+
})
|
|
1354
|
+
.join(" OR ");
|
|
1355
|
+
const columnsSql = `SELECT * FROM "ALL_TAB_COLS" "C" WHERE (${columnsCondition})`;
|
|
1356
|
+
const indicesSql = `SELECT "C"."INDEX_NAME", "C"."OWNER", "C"."TABLE_NAME", "C"."UNIQUENESS", ` +
|
|
1357
|
+
`LISTAGG ("COL"."COLUMN_NAME", ',') WITHIN GROUP (ORDER BY "COL"."COLUMN_NAME") AS "COLUMN_NAMES" ` +
|
|
1358
|
+
`FROM "ALL_INDEXES" "C" ` +
|
|
1359
|
+
`INNER JOIN "ALL_IND_COLUMNS" "COL" ON "COL"."INDEX_OWNER" = "C"."OWNER" AND "COL"."INDEX_NAME" = "C"."INDEX_NAME" ` +
|
|
1360
|
+
`LEFT JOIN "ALL_CONSTRAINTS" "CON" ON "CON"."OWNER" = "C"."OWNER" AND "CON"."CONSTRAINT_NAME" = "C"."INDEX_NAME" ` +
|
|
1361
|
+
`WHERE (${columnsCondition}) AND "CON"."CONSTRAINT_NAME" IS NULL ` +
|
|
1362
|
+
`GROUP BY "C"."INDEX_NAME", "C"."OWNER", "C"."TABLE_NAME", "C"."UNIQUENESS"`;
|
|
1363
|
+
const foreignKeysSql = `SELECT "C"."CONSTRAINT_NAME", "C"."OWNER", "C"."TABLE_NAME", "COL"."COLUMN_NAME", "REF_COL"."TABLE_NAME" AS "REFERENCED_TABLE_NAME", ` +
|
|
1364
|
+
`"REF_COL"."COLUMN_NAME" AS "REFERENCED_COLUMN_NAME", "C"."DELETE_RULE" AS "ON_DELETE" ` +
|
|
1365
|
+
`FROM "ALL_CONSTRAINTS" "C" ` +
|
|
1366
|
+
`INNER JOIN "ALL_CONS_COLUMNS" "COL" ON "COL"."OWNER" = "C"."OWNER" AND "COL"."CONSTRAINT_NAME" = "C"."CONSTRAINT_NAME" ` +
|
|
1367
|
+
`INNER JOIN "ALL_CONS_COLUMNS" "REF_COL" ON "REF_COL"."OWNER" = "C"."R_OWNER" AND "REF_COL"."CONSTRAINT_NAME" = "C"."R_CONSTRAINT_NAME" AND "REF_COL"."POSITION" = "COL"."POSITION" ` +
|
|
1368
|
+
`WHERE (${columnsCondition}) AND "C"."CONSTRAINT_TYPE" = 'R'`;
|
|
1369
|
+
const constraintsSql = `SELECT "C"."CONSTRAINT_NAME", "C"."CONSTRAINT_TYPE", "C"."OWNER", "C"."TABLE_NAME", "COL"."COLUMN_NAME", "C"."SEARCH_CONDITION" ` +
|
|
1370
|
+
`FROM "ALL_CONSTRAINTS" "C" ` +
|
|
1371
|
+
`INNER JOIN "ALL_CONS_COLUMNS" "COL" ON "COL"."OWNER" = "C"."OWNER" AND "COL"."CONSTRAINT_NAME" = "C"."CONSTRAINT_NAME" ` +
|
|
1372
|
+
`WHERE (${columnsCondition}) AND "C"."CONSTRAINT_TYPE" IN ('C', 'U', 'P') AND "C"."GENERATED" = 'USER NAME'`;
|
|
1373
|
+
const [dbColumns, dbIndices, dbForeignKeys, dbConstraints,] = await Promise.all([
|
|
1374
|
+
this.query(columnsSql),
|
|
1375
|
+
this.query(indicesSql),
|
|
1376
|
+
this.query(foreignKeysSql),
|
|
1377
|
+
this.query(constraintsSql),
|
|
1378
|
+
]);
|
|
1379
|
+
// create tables for loaded tables
|
|
1380
|
+
return await Promise.all(dbTables.map(async (dbTable) => {
|
|
1381
|
+
const table = new Table_1.Table();
|
|
1382
|
+
const owner = dbTable["OWNER"] === currentSchema &&
|
|
1383
|
+
(!this.driver.options.schema ||
|
|
1384
|
+
this.driver.options.schema === currentSchema)
|
|
1385
|
+
? undefined
|
|
1386
|
+
: dbTable["OWNER"];
|
|
1387
|
+
table.database = currentDatabase;
|
|
1388
|
+
table.schema = dbTable["OWNER"];
|
|
1389
|
+
table.name = this.driver.buildTableName(dbTable["TABLE_NAME"], owner);
|
|
1390
|
+
// create columns from the loaded columns
|
|
1391
|
+
table.columns = await Promise.all(dbColumns
|
|
1392
|
+
.filter((dbColumn) => dbColumn["OWNER"] === dbTable["OWNER"] &&
|
|
1393
|
+
dbColumn["TABLE_NAME"] ===
|
|
1394
|
+
dbTable["TABLE_NAME"])
|
|
1395
|
+
.map(async (dbColumn) => {
|
|
1396
|
+
const columnConstraints = dbConstraints.filter((dbConstraint) => dbConstraint["OWNER"] ===
|
|
1397
|
+
dbColumn["OWNER"] &&
|
|
1398
|
+
dbConstraint["TABLE_NAME"] ===
|
|
1399
|
+
dbColumn["TABLE_NAME"] &&
|
|
1400
|
+
dbConstraint["COLUMN_NAME"] ===
|
|
1401
|
+
dbColumn["COLUMN_NAME"]);
|
|
1402
|
+
const uniqueConstraints = columnConstraints.filter((constraint) => constraint["CONSTRAINT_TYPE"] === "U");
|
|
1403
|
+
const isConstraintComposite = uniqueConstraints.every((uniqueConstraint) => {
|
|
1404
|
+
return dbConstraints.some((dbConstraint) => dbConstraint["OWNER"] ===
|
|
1405
|
+
dbColumn["OWNER"] &&
|
|
1406
|
+
dbConstraint["TABLE_NAME"] ===
|
|
1407
|
+
dbColumn["TABLE_NAME"] &&
|
|
1408
|
+
dbConstraint["COLUMN_NAME"] !==
|
|
1409
|
+
dbColumn["COLUMN_NAME"] &&
|
|
1410
|
+
dbConstraint["CONSTRAINT_NAME"] ===
|
|
1411
|
+
uniqueConstraint["CONSTRAINT_NAME"] &&
|
|
1412
|
+
dbConstraint["CONSTRAINT_TYPE"] ===
|
|
1413
|
+
"U");
|
|
1414
|
+
});
|
|
1415
|
+
const tableColumn = new TableColumn_1.TableColumn();
|
|
1416
|
+
tableColumn.name = dbColumn["COLUMN_NAME"];
|
|
1417
|
+
tableColumn.type =
|
|
1418
|
+
dbColumn["DATA_TYPE"].toLowerCase();
|
|
1419
|
+
if (tableColumn.type.indexOf("(") !== -1)
|
|
1420
|
+
tableColumn.type = tableColumn.type.replace(/\([0-9]*\)/, "");
|
|
1421
|
+
// check only columns that have length property
|
|
1422
|
+
if (this.driver.withLengthColumnTypes.indexOf(tableColumn.type) !== -1) {
|
|
1423
|
+
const length = tableColumn.type === "raw"
|
|
1424
|
+
? dbColumn["DATA_LENGTH"]
|
|
1425
|
+
: dbColumn["CHAR_COL_DECL_LENGTH"];
|
|
1426
|
+
tableColumn.length =
|
|
1427
|
+
length &&
|
|
1428
|
+
!this.isDefaultColumnLength(table, tableColumn, length)
|
|
1429
|
+
? length.toString()
|
|
1430
|
+
: "";
|
|
1431
|
+
}
|
|
1432
|
+
if (tableColumn.type === "number" ||
|
|
1433
|
+
tableColumn.type === "float") {
|
|
1434
|
+
if (dbColumn["DATA_PRECISION"] !== null &&
|
|
1435
|
+
!this.isDefaultColumnPrecision(table, tableColumn, dbColumn["DATA_PRECISION"]))
|
|
1436
|
+
tableColumn.precision =
|
|
1437
|
+
dbColumn["DATA_PRECISION"];
|
|
1438
|
+
if (dbColumn["DATA_SCALE"] !== null &&
|
|
1439
|
+
!this.isDefaultColumnScale(table, tableColumn, dbColumn["DATA_SCALE"]))
|
|
1440
|
+
tableColumn.scale = dbColumn["DATA_SCALE"];
|
|
1441
|
+
}
|
|
1442
|
+
else if ((tableColumn.type === "timestamp" ||
|
|
1443
|
+
tableColumn.type ===
|
|
1444
|
+
"timestamp with time zone" ||
|
|
1445
|
+
tableColumn.type ===
|
|
1446
|
+
"timestamp with local time zone") &&
|
|
1447
|
+
dbColumn["DATA_SCALE"] !== null) {
|
|
1448
|
+
tableColumn.precision =
|
|
1449
|
+
!this.isDefaultColumnPrecision(table, tableColumn, dbColumn["DATA_SCALE"])
|
|
1450
|
+
? dbColumn["DATA_SCALE"]
|
|
1451
|
+
: undefined;
|
|
1452
|
+
}
|
|
1453
|
+
tableColumn.default =
|
|
1454
|
+
dbColumn["DATA_DEFAULT"] !== null &&
|
|
1455
|
+
dbColumn["DATA_DEFAULT"] !== undefined &&
|
|
1456
|
+
dbColumn["VIRTUAL_COLUMN"] === "NO" &&
|
|
1457
|
+
dbColumn["DATA_DEFAULT"].trim() !== "NULL"
|
|
1458
|
+
? (tableColumn.default =
|
|
1459
|
+
dbColumn["DATA_DEFAULT"].trim())
|
|
1460
|
+
: undefined;
|
|
1461
|
+
const primaryConstraint = columnConstraints.find((constraint) => constraint["CONSTRAINT_TYPE"] === "P");
|
|
1462
|
+
if (primaryConstraint) {
|
|
1463
|
+
tableColumn.isPrimary = true;
|
|
1464
|
+
// find another columns involved in primary key constraint
|
|
1465
|
+
const anotherPrimaryConstraints = dbConstraints.filter((constraint) => constraint["OWNER"] ===
|
|
1466
|
+
dbColumn["OWNER"] &&
|
|
1467
|
+
constraint["TABLE_NAME"] ===
|
|
1468
|
+
dbColumn["TABLE_NAME"] &&
|
|
1469
|
+
constraint["COLUMN_NAME"] !==
|
|
1470
|
+
dbColumn["COLUMN_NAME"] &&
|
|
1471
|
+
constraint["CONSTRAINT_TYPE"] ===
|
|
1472
|
+
"P");
|
|
1473
|
+
// collect all column names
|
|
1474
|
+
const columnNames = anotherPrimaryConstraints.map((constraint) => constraint["COLUMN_NAME"]);
|
|
1475
|
+
columnNames.push(dbColumn["COLUMN_NAME"]);
|
|
1476
|
+
// build default primary key constraint name
|
|
1477
|
+
const pkName = this.connection.namingStrategy.primaryKeyName(table, columnNames);
|
|
1478
|
+
// if primary key has user-defined constraint name, write it in table column
|
|
1479
|
+
if (primaryConstraint["CONSTRAINT_NAME"] !==
|
|
1480
|
+
pkName) {
|
|
1481
|
+
tableColumn.primaryKeyConstraintName =
|
|
1482
|
+
primaryConstraint["CONSTRAINT_NAME"];
|
|
1483
|
+
}
|
|
1484
|
+
}
|
|
1485
|
+
tableColumn.isNullable =
|
|
1486
|
+
dbColumn["NULLABLE"] === "Y";
|
|
1487
|
+
tableColumn.isUnique =
|
|
1488
|
+
uniqueConstraints.length > 0 &&
|
|
1489
|
+
!isConstraintComposite;
|
|
1490
|
+
tableColumn.isGenerated =
|
|
1491
|
+
dbColumn["IDENTITY_COLUMN"] === "YES";
|
|
1492
|
+
if (tableColumn.isGenerated) {
|
|
1493
|
+
tableColumn.generationStrategy = "increment";
|
|
1494
|
+
tableColumn.default = undefined;
|
|
1495
|
+
}
|
|
1496
|
+
tableColumn.comment = ""; // todo
|
|
1497
|
+
if (dbColumn["VIRTUAL_COLUMN"] === "YES") {
|
|
1498
|
+
tableColumn.generatedType = "VIRTUAL";
|
|
1499
|
+
const asExpressionQuery = await this.selectTypeormMetadataSql({
|
|
1500
|
+
table: dbTable["TABLE_NAME"],
|
|
1501
|
+
type: MetadataTableType_1.MetadataTableType.GENERATED_COLUMN,
|
|
1502
|
+
name: tableColumn.name,
|
|
1503
|
+
});
|
|
1504
|
+
const results = await this.query(asExpressionQuery.query, asExpressionQuery.parameters);
|
|
1505
|
+
if (results[0] && results[0].value) {
|
|
1506
|
+
tableColumn.asExpression = results[0].value;
|
|
1507
|
+
}
|
|
1508
|
+
else {
|
|
1509
|
+
tableColumn.asExpression = "";
|
|
1510
|
+
}
|
|
1511
|
+
}
|
|
1512
|
+
return tableColumn;
|
|
1513
|
+
}));
|
|
1514
|
+
// find unique constraints of table, group them by constraint name and build TableUnique.
|
|
1515
|
+
const tableUniqueConstraints = OrmUtils_1.OrmUtils.uniq(dbConstraints.filter((dbConstraint) => {
|
|
1516
|
+
return (dbConstraint["TABLE_NAME"] ===
|
|
1517
|
+
dbTable["TABLE_NAME"] &&
|
|
1518
|
+
dbConstraint["OWNER"] === dbTable["OWNER"] &&
|
|
1519
|
+
dbConstraint["CONSTRAINT_TYPE"] === "U");
|
|
1520
|
+
}), (dbConstraint) => dbConstraint["CONSTRAINT_NAME"]);
|
|
1521
|
+
table.uniques = tableUniqueConstraints.map((constraint) => {
|
|
1522
|
+
const uniques = dbConstraints.filter((dbC) => dbC["CONSTRAINT_NAME"] ===
|
|
1523
|
+
constraint["CONSTRAINT_NAME"]);
|
|
1524
|
+
return new TableUnique_1.TableUnique({
|
|
1525
|
+
name: constraint["CONSTRAINT_NAME"],
|
|
1526
|
+
columnNames: uniques.map((u) => u["COLUMN_NAME"]),
|
|
1527
|
+
});
|
|
2475
1528
|
});
|
|
2476
|
-
|
|
2477
|
-
|
|
1529
|
+
// find check constraints of table, group them by constraint name and build TableCheck.
|
|
1530
|
+
const tableCheckConstraints = OrmUtils_1.OrmUtils.uniq(dbConstraints.filter((dbConstraint) => {
|
|
1531
|
+
return (dbConstraint["TABLE_NAME"] ===
|
|
1532
|
+
dbTable["TABLE_NAME"] &&
|
|
1533
|
+
dbConstraint["OWNER"] === dbTable["OWNER"] &&
|
|
1534
|
+
dbConstraint["CONSTRAINT_TYPE"] === "C");
|
|
1535
|
+
}), (dbConstraint) => dbConstraint["CONSTRAINT_NAME"]);
|
|
1536
|
+
table.checks = tableCheckConstraints.map((constraint) => {
|
|
1537
|
+
const checks = dbConstraints.filter((dbC) => dbC["TABLE_NAME"] === constraint["TABLE_NAME"] &&
|
|
1538
|
+
dbC["OWNER"] === constraint["OWNER"] &&
|
|
1539
|
+
dbC["CONSTRAINT_NAME"] ===
|
|
1540
|
+
constraint["CONSTRAINT_NAME"]);
|
|
1541
|
+
return new TableCheck_1.TableCheck({
|
|
1542
|
+
name: constraint["CONSTRAINT_NAME"],
|
|
1543
|
+
columnNames: checks.map((c) => c["COLUMN_NAME"]),
|
|
1544
|
+
expression: constraint["SEARCH_CONDITION"],
|
|
1545
|
+
});
|
|
1546
|
+
});
|
|
1547
|
+
// find foreign key constraints of table, group them by constraint name and build TableForeignKey.
|
|
1548
|
+
const tableForeignKeyConstraints = OrmUtils_1.OrmUtils.uniq(dbForeignKeys.filter((dbForeignKey) => dbForeignKey["OWNER"] === dbTable["OWNER"] &&
|
|
1549
|
+
dbForeignKey["TABLE_NAME"] ===
|
|
1550
|
+
dbTable["TABLE_NAME"]), (dbForeignKey) => dbForeignKey["CONSTRAINT_NAME"]);
|
|
1551
|
+
table.foreignKeys = tableForeignKeyConstraints.map((dbForeignKey) => {
|
|
1552
|
+
const foreignKeys = dbForeignKeys.filter((dbFk) => dbFk["TABLE_NAME"] ===
|
|
1553
|
+
dbForeignKey["TABLE_NAME"] &&
|
|
1554
|
+
dbFk["OWNER"] === dbForeignKey["OWNER"] &&
|
|
1555
|
+
dbFk["CONSTRAINT_NAME"] ===
|
|
1556
|
+
dbForeignKey["CONSTRAINT_NAME"]);
|
|
1557
|
+
return new TableForeignKey_1.TableForeignKey({
|
|
1558
|
+
name: dbForeignKey["CONSTRAINT_NAME"],
|
|
1559
|
+
columnNames: foreignKeys.map((dbFk) => dbFk["COLUMN_NAME"]),
|
|
1560
|
+
referencedDatabase: table.database,
|
|
1561
|
+
referencedSchema: dbForeignKey["OWNER"],
|
|
1562
|
+
referencedTableName: dbForeignKey["REFERENCED_TABLE_NAME"],
|
|
1563
|
+
referencedColumnNames: foreignKeys.map((dbFk) => dbFk["REFERENCED_COLUMN_NAME"]),
|
|
1564
|
+
onDelete: dbForeignKey["ON_DELETE"],
|
|
1565
|
+
onUpdate: "NO ACTION", // Oracle does not have onUpdate option in FK's, but we need it for proper synchronization
|
|
1566
|
+
});
|
|
1567
|
+
});
|
|
1568
|
+
// create TableIndex objects from the loaded indices
|
|
1569
|
+
table.indices = dbIndices
|
|
1570
|
+
.filter((dbIndex) => dbIndex["TABLE_NAME"] === dbTable["TABLE_NAME"] &&
|
|
1571
|
+
dbIndex["OWNER"] === dbTable["OWNER"])
|
|
1572
|
+
.map((dbIndex) => {
|
|
1573
|
+
return new TableIndex_1.TableIndex({
|
|
1574
|
+
name: dbIndex["INDEX_NAME"],
|
|
1575
|
+
columnNames: dbIndex["COLUMN_NAMES"].split(","),
|
|
1576
|
+
isUnique: dbIndex["UNIQUENESS"] === "UNIQUE",
|
|
1577
|
+
});
|
|
1578
|
+
});
|
|
1579
|
+
return table;
|
|
1580
|
+
}));
|
|
1581
|
+
}
|
|
2478
1582
|
/**
|
|
2479
1583
|
* Builds and returns SQL for create table.
|
|
2480
1584
|
*/
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
.map(function (column) { return _this.buildCreateColumnSql(column); })
|
|
1585
|
+
createTableSql(table, createForeignKeys) {
|
|
1586
|
+
const columnDefinitions = table.columns
|
|
1587
|
+
.map((column) => this.buildCreateColumnSql(column))
|
|
2485
1588
|
.join(", ");
|
|
2486
|
-
|
|
1589
|
+
let sql = `CREATE TABLE ${this.escapePath(table)} (${columnDefinitions}`;
|
|
2487
1590
|
table.columns
|
|
2488
|
-
.filter(
|
|
2489
|
-
.forEach(
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
unique.columnNames[0] === column.name;
|
|
2493
|
-
});
|
|
1591
|
+
.filter((column) => column.isUnique)
|
|
1592
|
+
.forEach((column) => {
|
|
1593
|
+
const isUniqueExist = table.uniques.some((unique) => unique.columnNames.length === 1 &&
|
|
1594
|
+
unique.columnNames[0] === column.name);
|
|
2494
1595
|
if (!isUniqueExist)
|
|
2495
1596
|
table.uniques.push(new TableUnique_1.TableUnique({
|
|
2496
|
-
name:
|
|
1597
|
+
name: this.connection.namingStrategy.uniqueConstraintName(table, [column.name]),
|
|
2497
1598
|
columnNames: [column.name],
|
|
2498
1599
|
}));
|
|
2499
1600
|
});
|
|
2500
1601
|
if (table.uniques.length > 0) {
|
|
2501
|
-
|
|
2502
|
-
.map(
|
|
2503
|
-
|
|
1602
|
+
const uniquesSql = table.uniques
|
|
1603
|
+
.map((unique) => {
|
|
1604
|
+
const uniqueName = unique.name
|
|
2504
1605
|
? unique.name
|
|
2505
|
-
:
|
|
2506
|
-
|
|
2507
|
-
.map(
|
|
1606
|
+
: this.connection.namingStrategy.uniqueConstraintName(table, unique.columnNames);
|
|
1607
|
+
const columnNames = unique.columnNames
|
|
1608
|
+
.map((columnName) => `"${columnName}"`)
|
|
2508
1609
|
.join(", ");
|
|
2509
|
-
return
|
|
1610
|
+
return `CONSTRAINT "${uniqueName}" UNIQUE (${columnNames})`;
|
|
2510
1611
|
})
|
|
2511
1612
|
.join(", ");
|
|
2512
|
-
sql +=
|
|
1613
|
+
sql += `, ${uniquesSql}`;
|
|
2513
1614
|
}
|
|
2514
1615
|
if (table.checks.length > 0) {
|
|
2515
|
-
|
|
2516
|
-
.map(
|
|
2517
|
-
|
|
1616
|
+
const checksSql = table.checks
|
|
1617
|
+
.map((check) => {
|
|
1618
|
+
const checkName = check.name
|
|
2518
1619
|
? check.name
|
|
2519
|
-
:
|
|
2520
|
-
return
|
|
1620
|
+
: this.connection.namingStrategy.checkConstraintName(table, check.expression);
|
|
1621
|
+
return `CONSTRAINT "${checkName}" CHECK (${check.expression})`;
|
|
2521
1622
|
})
|
|
2522
1623
|
.join(", ");
|
|
2523
|
-
sql +=
|
|
1624
|
+
sql += `, ${checksSql}`;
|
|
2524
1625
|
}
|
|
2525
1626
|
if (table.foreignKeys.length > 0 && createForeignKeys) {
|
|
2526
|
-
|
|
2527
|
-
.map(
|
|
2528
|
-
|
|
2529
|
-
.map(
|
|
1627
|
+
const foreignKeysSql = table.foreignKeys
|
|
1628
|
+
.map((fk) => {
|
|
1629
|
+
const columnNames = fk.columnNames
|
|
1630
|
+
.map((columnName) => `"${columnName}"`)
|
|
2530
1631
|
.join(", ");
|
|
2531
1632
|
if (!fk.name)
|
|
2532
|
-
fk.name =
|
|
2533
|
-
|
|
2534
|
-
.map(
|
|
1633
|
+
fk.name = this.connection.namingStrategy.foreignKeyName(table, fk.columnNames, this.getTablePath(fk), fk.referencedColumnNames);
|
|
1634
|
+
const referencedColumnNames = fk.referencedColumnNames
|
|
1635
|
+
.map((columnName) => `"${columnName}"`)
|
|
2535
1636
|
.join(", ");
|
|
2536
|
-
|
|
1637
|
+
let constraint = `CONSTRAINT "${fk.name}" FOREIGN KEY (${columnNames}) REFERENCES ${this.escapePath(this.getTablePath(fk))} (${referencedColumnNames})`;
|
|
2537
1638
|
if (fk.onDelete && fk.onDelete !== "NO ACTION")
|
|
2538
1639
|
// Oracle does not support NO ACTION, but we set NO ACTION by default in EntityMetadata
|
|
2539
|
-
constraint +=
|
|
1640
|
+
constraint += ` ON DELETE ${fk.onDelete}`;
|
|
2540
1641
|
return constraint;
|
|
2541
1642
|
})
|
|
2542
1643
|
.join(", ");
|
|
2543
|
-
sql +=
|
|
1644
|
+
sql += `, ${foreignKeysSql}`;
|
|
2544
1645
|
}
|
|
2545
|
-
|
|
1646
|
+
const primaryColumns = table.columns.filter((column) => column.isPrimary);
|
|
2546
1647
|
if (primaryColumns.length > 0) {
|
|
2547
|
-
|
|
1648
|
+
const primaryKeyName = primaryColumns[0].primaryKeyConstraintName
|
|
2548
1649
|
? primaryColumns[0].primaryKeyConstraintName
|
|
2549
|
-
: this.connection.namingStrategy.primaryKeyName(table, primaryColumns.map(
|
|
2550
|
-
|
|
2551
|
-
.map(
|
|
1650
|
+
: this.connection.namingStrategy.primaryKeyName(table, primaryColumns.map((column) => column.name));
|
|
1651
|
+
const columnNames = primaryColumns
|
|
1652
|
+
.map((column) => `"${column.name}"`)
|
|
2552
1653
|
.join(", ");
|
|
2553
|
-
sql +=
|
|
1654
|
+
sql += `, CONSTRAINT "${primaryKeyName}" PRIMARY KEY (${columnNames})`;
|
|
2554
1655
|
}
|
|
2555
|
-
sql +=
|
|
1656
|
+
sql += `)`;
|
|
2556
1657
|
return new Query_1.Query(sql);
|
|
2557
|
-
}
|
|
1658
|
+
}
|
|
2558
1659
|
/**
|
|
2559
1660
|
* Builds drop table sql.
|
|
2560
1661
|
*/
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
?
|
|
2564
|
-
:
|
|
1662
|
+
dropTableSql(tableOrName, ifExist) {
|
|
1663
|
+
const query = ifExist
|
|
1664
|
+
? `DROP TABLE IF EXISTS ${this.escapePath(tableOrName)}`
|
|
1665
|
+
: `DROP TABLE ${this.escapePath(tableOrName)}`;
|
|
2565
1666
|
return new Query_1.Query(query);
|
|
2566
|
-
}
|
|
2567
|
-
|
|
2568
|
-
|
|
1667
|
+
}
|
|
1668
|
+
createViewSql(view) {
|
|
1669
|
+
const materializedClause = view.materialized ? "MATERIALIZED " : "";
|
|
2569
1670
|
if (typeof view.expression === "string") {
|
|
2570
|
-
return new Query_1.Query(
|
|
1671
|
+
return new Query_1.Query(`CREATE ${materializedClause}VIEW ${this.escapePath(view)} AS ${view.expression}`);
|
|
2571
1672
|
}
|
|
2572
1673
|
else {
|
|
2573
|
-
return new Query_1.Query(
|
|
1674
|
+
return new Query_1.Query(`CREATE ${materializedClause}VIEW ${this.escapePath(view)} AS ${view.expression(this.connection).getQuery()}`);
|
|
2574
1675
|
}
|
|
2575
|
-
}
|
|
2576
|
-
|
|
2577
|
-
|
|
1676
|
+
}
|
|
1677
|
+
insertViewDefinitionSql(view) {
|
|
1678
|
+
const expression = typeof view.expression === "string"
|
|
2578
1679
|
? view.expression.trim()
|
|
2579
1680
|
: view.expression(this.connection).getQuery();
|
|
2580
|
-
|
|
1681
|
+
const type = view.materialized
|
|
2581
1682
|
? MetadataTableType_1.MetadataTableType.MATERIALIZED_VIEW
|
|
2582
1683
|
: MetadataTableType_1.MetadataTableType.VIEW;
|
|
2583
1684
|
return this.insertTypeormMetadataSql({
|
|
@@ -2585,136 +1686,136 @@ var OracleQueryRunner = /** @class */ (function (_super) {
|
|
|
2585
1686
|
name: view.name,
|
|
2586
1687
|
value: expression,
|
|
2587
1688
|
});
|
|
2588
|
-
}
|
|
1689
|
+
}
|
|
2589
1690
|
/**
|
|
2590
1691
|
* Builds drop view sql.
|
|
2591
1692
|
*/
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
return new Query_1.Query(
|
|
2595
|
-
}
|
|
1693
|
+
dropViewSql(view) {
|
|
1694
|
+
const materializedClause = view.materialized ? "MATERIALIZED " : "";
|
|
1695
|
+
return new Query_1.Query(`DROP ${materializedClause}VIEW ${this.escapePath(view)}`);
|
|
1696
|
+
}
|
|
2596
1697
|
/**
|
|
2597
1698
|
* Builds remove view sql.
|
|
2598
1699
|
*/
|
|
2599
|
-
|
|
2600
|
-
|
|
1700
|
+
deleteViewDefinitionSql(view) {
|
|
1701
|
+
const type = view.materialized
|
|
2601
1702
|
? MetadataTableType_1.MetadataTableType.MATERIALIZED_VIEW
|
|
2602
1703
|
: MetadataTableType_1.MetadataTableType.VIEW;
|
|
2603
|
-
return this.deleteTypeormMetadataSql({ type
|
|
2604
|
-
}
|
|
1704
|
+
return this.deleteTypeormMetadataSql({ type, name: view.name });
|
|
1705
|
+
}
|
|
2605
1706
|
/**
|
|
2606
1707
|
* Builds create index sql.
|
|
2607
1708
|
*/
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
.map(
|
|
1709
|
+
createIndexSql(table, index) {
|
|
1710
|
+
const columns = index.columnNames
|
|
1711
|
+
.map((columnName) => `"${columnName}"`)
|
|
2611
1712
|
.join(", ");
|
|
2612
|
-
return new Query_1.Query(
|
|
2613
|
-
}
|
|
1713
|
+
return new Query_1.Query(`CREATE ${index.isUnique ? "UNIQUE " : ""}INDEX "${index.name}" ON ${this.escapePath(table)} (${columns})`);
|
|
1714
|
+
}
|
|
2614
1715
|
/**
|
|
2615
1716
|
* Builds drop index sql.
|
|
2616
1717
|
*/
|
|
2617
|
-
|
|
2618
|
-
|
|
1718
|
+
dropIndexSql(indexOrName) {
|
|
1719
|
+
let indexName = InstanceChecker_1.InstanceChecker.isTableIndex(indexOrName)
|
|
2619
1720
|
? indexOrName.name
|
|
2620
1721
|
: indexOrName;
|
|
2621
|
-
return new Query_1.Query(
|
|
2622
|
-
}
|
|
1722
|
+
return new Query_1.Query(`DROP INDEX "${indexName}"`);
|
|
1723
|
+
}
|
|
2623
1724
|
/**
|
|
2624
1725
|
* Builds create primary key sql.
|
|
2625
1726
|
*/
|
|
2626
|
-
|
|
2627
|
-
|
|
1727
|
+
createPrimaryKeySql(table, columnNames, constraintName) {
|
|
1728
|
+
const primaryKeyName = constraintName
|
|
2628
1729
|
? constraintName
|
|
2629
1730
|
: this.connection.namingStrategy.primaryKeyName(table, columnNames);
|
|
2630
|
-
|
|
2631
|
-
.map(
|
|
1731
|
+
const columnNamesString = columnNames
|
|
1732
|
+
.map((columnName) => `"${columnName}"`)
|
|
2632
1733
|
.join(", ");
|
|
2633
|
-
return new Query_1.Query(
|
|
2634
|
-
}
|
|
1734
|
+
return new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} ADD CONSTRAINT "${primaryKeyName}" PRIMARY KEY (${columnNamesString})`);
|
|
1735
|
+
}
|
|
2635
1736
|
/**
|
|
2636
1737
|
* Builds drop primary key sql.
|
|
2637
1738
|
*/
|
|
2638
|
-
|
|
1739
|
+
dropPrimaryKeySql(table) {
|
|
2639
1740
|
if (!table.primaryColumns.length)
|
|
2640
|
-
throw new error_1.TypeORMError(
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
|
|
1741
|
+
throw new error_1.TypeORMError(`Table ${table} has no primary keys.`);
|
|
1742
|
+
const columnNames = table.primaryColumns.map((column) => column.name);
|
|
1743
|
+
const constraintName = table.primaryColumns[0].primaryKeyConstraintName;
|
|
1744
|
+
const primaryKeyName = constraintName
|
|
2644
1745
|
? constraintName
|
|
2645
1746
|
: this.connection.namingStrategy.primaryKeyName(table, columnNames);
|
|
2646
|
-
return new Query_1.Query(
|
|
2647
|
-
}
|
|
1747
|
+
return new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} DROP CONSTRAINT "${primaryKeyName}"`);
|
|
1748
|
+
}
|
|
2648
1749
|
/**
|
|
2649
1750
|
* Builds create unique constraint sql.
|
|
2650
1751
|
*/
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
.map(
|
|
1752
|
+
createUniqueConstraintSql(table, uniqueConstraint) {
|
|
1753
|
+
const columnNames = uniqueConstraint.columnNames
|
|
1754
|
+
.map((column) => `"` + column + `"`)
|
|
2654
1755
|
.join(", ");
|
|
2655
|
-
return new Query_1.Query(
|
|
2656
|
-
}
|
|
1756
|
+
return new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} ADD CONSTRAINT "${uniqueConstraint.name}" UNIQUE (${columnNames})`);
|
|
1757
|
+
}
|
|
2657
1758
|
/**
|
|
2658
1759
|
* Builds drop unique constraint sql.
|
|
2659
1760
|
*/
|
|
2660
|
-
|
|
2661
|
-
|
|
1761
|
+
dropUniqueConstraintSql(table, uniqueOrName) {
|
|
1762
|
+
const uniqueName = InstanceChecker_1.InstanceChecker.isTableUnique(uniqueOrName)
|
|
2662
1763
|
? uniqueOrName.name
|
|
2663
1764
|
: uniqueOrName;
|
|
2664
|
-
return new Query_1.Query(
|
|
2665
|
-
}
|
|
1765
|
+
return new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} DROP CONSTRAINT "${uniqueName}"`);
|
|
1766
|
+
}
|
|
2666
1767
|
/**
|
|
2667
1768
|
* Builds create check constraint sql.
|
|
2668
1769
|
*/
|
|
2669
|
-
|
|
2670
|
-
return new Query_1.Query(
|
|
2671
|
-
}
|
|
1770
|
+
createCheckConstraintSql(table, checkConstraint) {
|
|
1771
|
+
return new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} ADD CONSTRAINT "${checkConstraint.name}" CHECK (${checkConstraint.expression})`);
|
|
1772
|
+
}
|
|
2672
1773
|
/**
|
|
2673
1774
|
* Builds drop check constraint sql.
|
|
2674
1775
|
*/
|
|
2675
|
-
|
|
2676
|
-
|
|
1776
|
+
dropCheckConstraintSql(table, checkOrName) {
|
|
1777
|
+
const checkName = InstanceChecker_1.InstanceChecker.isTableCheck(checkOrName)
|
|
2677
1778
|
? checkOrName.name
|
|
2678
1779
|
: checkOrName;
|
|
2679
|
-
return new Query_1.Query(
|
|
2680
|
-
}
|
|
1780
|
+
return new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} DROP CONSTRAINT "${checkName}"`);
|
|
1781
|
+
}
|
|
2681
1782
|
/**
|
|
2682
1783
|
* Builds create foreign key sql.
|
|
2683
1784
|
*/
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
.map(
|
|
1785
|
+
createForeignKeySql(table, foreignKey) {
|
|
1786
|
+
const columnNames = foreignKey.columnNames
|
|
1787
|
+
.map((column) => `"` + column + `"`)
|
|
2687
1788
|
.join(", ");
|
|
2688
|
-
|
|
2689
|
-
.map(
|
|
1789
|
+
const referencedColumnNames = foreignKey.referencedColumnNames
|
|
1790
|
+
.map((column) => `"` + column + `"`)
|
|
2690
1791
|
.join(",");
|
|
2691
|
-
|
|
2692
|
-
|
|
1792
|
+
let sql = `ALTER TABLE ${this.escapePath(table)} ADD CONSTRAINT "${foreignKey.name}" FOREIGN KEY (${columnNames}) ` +
|
|
1793
|
+
`REFERENCES ${this.escapePath(this.getTablePath(foreignKey))} (${referencedColumnNames})`;
|
|
2693
1794
|
// Oracle does not support NO ACTION, but we set NO ACTION by default in EntityMetadata
|
|
2694
1795
|
if (foreignKey.onDelete && foreignKey.onDelete !== "NO ACTION")
|
|
2695
|
-
sql +=
|
|
1796
|
+
sql += ` ON DELETE ${foreignKey.onDelete}`;
|
|
2696
1797
|
return new Query_1.Query(sql);
|
|
2697
|
-
}
|
|
1798
|
+
}
|
|
2698
1799
|
/**
|
|
2699
1800
|
* Builds drop foreign key sql.
|
|
2700
1801
|
*/
|
|
2701
|
-
|
|
2702
|
-
|
|
1802
|
+
dropForeignKeySql(table, foreignKeyOrName) {
|
|
1803
|
+
const foreignKeyName = InstanceChecker_1.InstanceChecker.isTableForeignKey(foreignKeyOrName)
|
|
2703
1804
|
? foreignKeyOrName.name
|
|
2704
1805
|
: foreignKeyOrName;
|
|
2705
|
-
return new Query_1.Query(
|
|
2706
|
-
}
|
|
1806
|
+
return new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} DROP CONSTRAINT "${foreignKeyName}"`);
|
|
1807
|
+
}
|
|
2707
1808
|
/**
|
|
2708
1809
|
* Builds a query for create column.
|
|
2709
1810
|
*/
|
|
2710
|
-
|
|
2711
|
-
|
|
1811
|
+
buildCreateColumnSql(column) {
|
|
1812
|
+
let c = `"${column.name}" ` + this.connection.driver.createFullType(column);
|
|
2712
1813
|
if (column.charset)
|
|
2713
1814
|
c += " CHARACTER SET " + column.charset;
|
|
2714
1815
|
if (column.collation)
|
|
2715
1816
|
c += " COLLATE " + column.collation;
|
|
2716
1817
|
if (column.asExpression)
|
|
2717
|
-
c +=
|
|
1818
|
+
c += ` AS (${column.asExpression}) VIRTUAL`;
|
|
2718
1819
|
if (column.default !== undefined && column.default !== null)
|
|
2719
1820
|
// DEFAULT must be placed before NOT NULL
|
|
2720
1821
|
c += " DEFAULT " + column.default;
|
|
@@ -2725,20 +1826,19 @@ var OracleQueryRunner = /** @class */ (function (_super) {
|
|
|
2725
1826
|
column.generationStrategy === "increment")
|
|
2726
1827
|
c += " GENERATED BY DEFAULT AS IDENTITY";
|
|
2727
1828
|
return c;
|
|
2728
|
-
}
|
|
1829
|
+
}
|
|
2729
1830
|
/**
|
|
2730
1831
|
* Escapes given table or view path.
|
|
2731
1832
|
*/
|
|
2732
|
-
|
|
1833
|
+
escapePath(target) {
|
|
2733
1834
|
// Ignore database when escaping paths
|
|
2734
|
-
|
|
1835
|
+
const { schema, tableName } = this.driver.parseTableName(target);
|
|
2735
1836
|
if (schema && schema !== this.driver.schema) {
|
|
2736
|
-
return "
|
|
1837
|
+
return `"${schema}"."${tableName}"`;
|
|
2737
1838
|
}
|
|
2738
|
-
return "
|
|
2739
|
-
}
|
|
2740
|
-
|
|
2741
|
-
}(BaseQueryRunner_1.BaseQueryRunner));
|
|
1839
|
+
return `"${tableName}"`;
|
|
1840
|
+
}
|
|
1841
|
+
}
|
|
2742
1842
|
exports.OracleQueryRunner = OracleQueryRunner;
|
|
2743
1843
|
//#endregion
|
|
2744
1844
|
//# sourceMappingURL=OracleQueryRunner.js.map
|