1629964808297-drop_unused_indexes.ts 1.1 KB

123456789101112131415161718192021222324252627
  1. import { MigrationInterface, QueryRunner } from 'typeorm'
  2. export class dropUnusedIndexes1629964808297 implements MigrationInterface {
  3. name = 'dropUnusedIndexes1629964808297'
  4. public async up(queryRunner: QueryRunner): Promise<void> {
  5. const indexItemsOnUserAndTimestamp = await queryRunner.manager.query(
  6. 'SHOW INDEX FROM `items` where `key_name` = "index_items_on_user_uuid_and_updated_at_and_created_at"',
  7. )
  8. const indexItemsOnUserAndTimestampExists = indexItemsOnUserAndTimestamp && indexItemsOnUserAndTimestamp.length > 0
  9. if (indexItemsOnUserAndTimestampExists) {
  10. await queryRunner.query('ALTER TABLE `items` DROP INDEX index_items_on_user_uuid_and_updated_at_and_created_at')
  11. }
  12. const indexItemsOnUpdatedAt = await queryRunner.manager.query(
  13. 'SHOW INDEX FROM `items` where `key_name` = "index_items_on_updated_at"',
  14. )
  15. const indexItemsOnUpdatedAtExists = indexItemsOnUpdatedAt && indexItemsOnUpdatedAt.length > 0
  16. if (indexItemsOnUpdatedAtExists) {
  17. await queryRunner.query('ALTER TABLE `items` DROP INDEX index_items_on_updated_at')
  18. }
  19. }
  20. public async down(): Promise<void> {
  21. return
  22. }
  23. }