1689746527310-rename-key-message-identifier.ts 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { MigrationInterface, QueryRunner } from 'typeorm'
  2. export class RenameKeyMessageIdentifier1689746527310 implements MigrationInterface {
  3. name = 'RenameKeyMessageIdentifier1689746527310'
  4. public async up(queryRunner: QueryRunner): Promise<void> {
  5. await queryRunner.query('DROP INDEX "key_system_uuid_on_key_system_associations"')
  6. await queryRunner.query('DROP INDEX "item_uuid_on_key_system_associations"')
  7. await queryRunner.query(
  8. 'CREATE TABLE "temporary_key_system_associations" ("uuid" varchar PRIMARY KEY NOT NULL, "key_system_identifier" varchar(36) NOT NULL, "item_uuid" varchar(36) NOT NULL, "created_at_timestamp" bigint NOT NULL, "updated_at_timestamp" bigint NOT NULL)',
  9. )
  10. await queryRunner.query(
  11. 'INSERT INTO "temporary_key_system_associations"("uuid", "key_system_identifier", "item_uuid", "created_at_timestamp", "updated_at_timestamp") SELECT "uuid", "key_system_uuid", "item_uuid", "created_at_timestamp", "updated_at_timestamp" FROM "key_system_associations"',
  12. )
  13. await queryRunner.query('DROP TABLE "key_system_associations"')
  14. await queryRunner.query('ALTER TABLE "temporary_key_system_associations" RENAME TO "key_system_associations"')
  15. await queryRunner.query(
  16. 'CREATE INDEX "item_uuid_on_key_system_associations" ON "key_system_associations" ("item_uuid") ',
  17. )
  18. await queryRunner.query(
  19. 'CREATE INDEX "key_system_identifier_on_key_system_associations" ON "key_system_associations" ("key_system_identifier") ',
  20. )
  21. }
  22. public async down(queryRunner: QueryRunner): Promise<void> {
  23. await queryRunner.query('DROP INDEX "key_system_identifier_on_key_system_associations"')
  24. await queryRunner.query('DROP INDEX "item_uuid_on_key_system_associations"')
  25. await queryRunner.query('ALTER TABLE "key_system_associations" RENAME TO "temporary_key_system_associations"')
  26. await queryRunner.query(
  27. 'CREATE TABLE "key_system_associations" ("uuid" varchar PRIMARY KEY NOT NULL, "key_system_uuid" varchar(36) NOT NULL, "item_uuid" varchar(36) NOT NULL, "created_at_timestamp" bigint NOT NULL, "updated_at_timestamp" bigint NOT NULL)',
  28. )
  29. await queryRunner.query(
  30. 'INSERT INTO "key_system_associations"("uuid", "key_system_uuid", "item_uuid", "created_at_timestamp", "updated_at_timestamp") SELECT "uuid", "key_system_identifier", "item_uuid", "created_at_timestamp", "updated_at_timestamp" FROM "temporary_key_system_associations"',
  31. )
  32. await queryRunner.query('DROP TABLE "temporary_key_system_associations"')
  33. await queryRunner.query(
  34. 'CREATE INDEX "item_uuid_on_key_system_associations" ON "key_system_associations" ("item_uuid") ',
  35. )
  36. await queryRunner.query(
  37. 'CREATE INDEX "key_system_uuid_on_key_system_associations" ON "key_system_associations" ("key_system_uuid") ',
  38. )
  39. }
  40. }