(options?: ClearDatabaseOptions)
| 182 | } |
| 183 | |
| 184 | override async clear(options?: ClearDatabaseOptions): Promise<void> { |
| 185 | // truncate by default, so no value is considered as true |
| 186 | /* v8 ignore next */ |
| 187 | if (options?.truncate === false) { |
| 188 | return super.clear(options); |
| 189 | } |
| 190 | |
| 191 | if (this.options.disableForeignKeysForClear) { |
| 192 | await this.execute(this.helper.disableForeignKeysSQL()); |
| 193 | } |
| 194 | |
| 195 | const schema = options?.schema ?? this.config.get('schema', this.platform.getDefaultSchemaName()); |
| 196 | |
| 197 | for (const meta of this.getOrderedMetadataForClear(schema).reverse()) { |
| 198 | try { |
| 199 | await this.driver |
| 200 | .createQueryBuilder(meta.class, this.em?.getTransactionContext(), 'write', false) |
| 201 | .withSchema(schema) |
| 202 | .truncate() |
| 203 | .execute(); |
| 204 | } catch (e) { |
| 205 | if (this.platform.getExceptionConverter().convertException(e as Error) instanceof TableNotFoundException) { |
| 206 | continue; |
| 207 | } |
| 208 | |
| 209 | throw e; |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | if (this.options.disableForeignKeysForClear) { |
| 214 | await this.execute(this.helper.enableForeignKeysSQL()); |
| 215 | } |
| 216 | |
| 217 | if (options?.clearIdentityMap ?? true) { |
| 218 | this.clearIdentityMap(); |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | override async getDropSchemaSQL(options: Omit<DropSchemaOptions, 'dropDb'> = {}): Promise<string> { |
| 223 | await this.ensureDatabase(); |
no test coverage detected