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