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