import { MigrationInterface, QueryRunner } from 'typeorm';

export class initialMigration1597705000730 implements MigrationInterface {
  name = 'initialMigration1597705000730';

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `CREATE TABLE "author_role_name" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL DEFAULT (''), "entityId" integer NOT NULL)`
    );
    await queryRunner.query(
      `CREATE TABLE "author_role" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "nameCanonical" varchar NOT NULL DEFAULT (''), "description" varchar NOT NULL DEFAULT (''))`
    );
    await queryRunner.query(
      `CREATE TABLE "collection_name" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL DEFAULT (''), "entityId" integer NOT NULL)`
    );
    await queryRunner.query(
      `CREATE TABLE "collection" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "nameCanonical" varchar NOT NULL DEFAULT (''))`
    );
    await queryRunner.query(
      `CREATE TABLE "collection_part" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "order" integer NOT NULL DEFAULT (0), "collectionId" integer NOT NULL, "workId" integer NOT NULL)`
    );
    await queryRunner.query(
      `CREATE TABLE "site_name" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL DEFAULT (''), "entityId" integer NOT NULL)`
    );
    await queryRunner.query(
      `CREATE TABLE "site" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "nameCanonical" varchar NOT NULL DEFAULT (''))`
    );
    await queryRunner.query(
      `CREATE TABLE "source" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "uri" varchar NOT NULL DEFAULT (''), "siteId" integer)`
    );
    await queryRunner.query(
      `CREATE TABLE "copy" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "hash" varchar NOT NULL DEFAULT (''), "location" text, "ranking" integer NOT NULL DEFAULT (0), "originalId" integer NOT NULL)`
    );
    await queryRunner.query(`CREATE TABLE "language" ("code" varchar PRIMARY KEY NOT NULL)`);
    await queryRunner.query(
      `CREATE TABLE "transformation_type_name" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL DEFAULT (''), "entityId" integer NOT NULL)`
    );
    await queryRunner.query(
      `CREATE TABLE "transformation_type" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "nameCanonical" varchar NOT NULL DEFAULT (''), "description" varchar NOT NULL DEFAULT (''), "conservesTags" boolean NOT NULL DEFAULT (0))`
    );
    await queryRunner.query(
      `CREATE TABLE "transformation" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "order" integer NOT NULL DEFAULT (0), "byWorkId" integer NOT NULL, "typeId" integer NOT NULL, "ofWorkId" integer NOT NULL)`
    );
    await queryRunner.query(
      `CREATE TABLE "interaction_tag" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "weight" integer, "tagId" integer NOT NULL, CONSTRAINT "weight needs to be between 0 and 9007199254740991" CHECK (weight >= 0 AND weight <= 9007199254740991))`
    );
    await queryRunner.query(
      `CREATE TABLE "tag_name" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL DEFAULT (''), "entityId" integer NOT NULL)`
    );
    await queryRunner.query(
      `CREATE TABLE "work_tag" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "weight" integer, "tagId" integer NOT NULL, "workId" integer NOT NULL, CONSTRAINT "weight needs to be between 0 and 9007199254740991" CHECK (weight >= 0 AND weight <= 9007199254740991))`
    );
    await queryRunner.query(
      `CREATE TABLE "tag" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "nameCanonical" varchar NOT NULL DEFAULT (''), "description" varchar NOT NULL DEFAULT (''))`
    );
    await queryRunner.query(
      `CREATE TABLE "character_tag" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "weight" integer, "workCharacterId" integer NOT NULL, "tagId" integer NOT NULL, CONSTRAINT "weight needs to be between 0 and 9007199254740991" CHECK (weight >= 0 AND weight <= 9007199254740991))`
    );
    await queryRunner.query(
      `CREATE TABLE "work_character_name" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL DEFAULT (''), "entityId" integer NOT NULL)`
    );
    await queryRunner.query(
      `CREATE TABLE "world_name" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL DEFAULT (''), "entityId" integer NOT NULL)`
    );
    await queryRunner.query(
      `CREATE TABLE "world" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "nameCanonical" varchar NOT NULL DEFAULT (''))`
    );
    await queryRunner.query(
      `CREATE TABLE "world_character_name" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL DEFAULT (''), "entityId" integer NOT NULL)`
    );
    await queryRunner.query(
      `CREATE TABLE "world_character" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "nameCanonical" varchar NOT NULL DEFAULT (''))`
    );
    await queryRunner.query(
      `CREATE TABLE "work_character" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "nameCanonical" varchar NOT NULL DEFAULT (''))`
    );
    await queryRunner.query(
      `CREATE TABLE "work_name" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL DEFAULT (''), "entityId" integer NOT NULL)`
    );
    await queryRunner.query(
      `CREATE TABLE "work" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "nameCanonical" varchar NOT NULL DEFAULT (''), "isCanonical" boolean NOT NULL DEFAULT (0), "rating" integer, "releaseDate" date, CONSTRAINT "rating needs to be between 0 and 9007199254740991" CHECK (rating >= 0 AND rating <= 9007199254740991))`
    );
    await queryRunner.query(
      `CREATE TABLE "work_author" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "order" integer NOT NULL DEFAULT (0), "workId" integer NOT NULL, "authorId" integer NOT NULL)`
    );
    await queryRunner.query(
      `CREATE TABLE "author" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "nameCanonical" varchar NOT NULL DEFAULT (''))`
    );
    await queryRunner.query(
      `CREATE TABLE "author_name" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL DEFAULT (''), "entityId" integer NOT NULL)`
    );
    await queryRunner.query(
      `CREATE TABLE "copy_sources_source" ("copyId" integer NOT NULL, "sourceId" integer NOT NULL, PRIMARY KEY ("copyId", "sourceId"))`
    );
    await queryRunner.query(`CREATE INDEX "IDX_653c33c5db26b8736e592ff3f6" ON "copy_sources_source" ("copyId") `);
    await queryRunner.query(`CREATE INDEX "IDX_946af3644f779b7cc7e7eb04eb" ON "copy_sources_source" ("sourceId") `);
    await queryRunner.query(
      `CREATE TABLE "tag_parents_tag" ("tagId_1" integer NOT NULL, "tagId_2" integer NOT NULL, PRIMARY KEY ("tagId_1", "tagId_2"))`
    );
    await queryRunner.query(`CREATE INDEX "IDX_a56aff619335e19bd07e252d11" ON "tag_parents_tag" ("tagId_1") `);
    await queryRunner.query(`CREATE INDEX "IDX_1850c401823bc25103bb621657" ON "tag_parents_tag" ("tagId_2") `);
    await queryRunner.query(
      `CREATE TABLE "world_world_characters_world_character" ("worldId" integer NOT NULL, "worldCharacterId" integer NOT NULL, PRIMARY KEY ("worldId", "worldCharacterId"))`
    );
    await queryRunner.query(
      `CREATE INDEX "IDX_6024260e0f5118a2379be24a3f" ON "world_world_characters_world_character" ("worldId") `
    );
    await queryRunner.query(
      `CREATE INDEX "IDX_ded86f18df3574ee221fff525c" ON "world_world_characters_world_character" ("worldCharacterId") `
    );
    await queryRunner.query(
      `CREATE TABLE "world_parents_world" ("worldId_1" integer NOT NULL, "worldId_2" integer NOT NULL, PRIMARY KEY ("worldId_1", "worldId_2"))`
    );
    await queryRunner.query(`CREATE INDEX "IDX_7864295ed996ae9d36db032c70" ON "world_parents_world" ("worldId_1") `);
    await queryRunner.query(`CREATE INDEX "IDX_63bee78016e6eb0188abded4b5" ON "world_parents_world" ("worldId_2") `);
    await queryRunner.query(
      `CREATE TABLE "world_character_parents_world_character" ("worldCharacterId_1" integer NOT NULL, "worldCharacterId_2" integer NOT NULL, PRIMARY KEY ("worldCharacterId_1", "worldCharacterId_2"))`
    );
    await queryRunner.query(
      `CREATE INDEX "IDX_51a5b3b73ad0f5af3da0018e16" ON "world_character_parents_world_character" ("worldCharacterId_1") `
    );
    await queryRunner.query(
      `CREATE INDEX "IDX_617d4b51c57be06e915f41df7c" ON "world_character_parents_world_character" ("worldCharacterId_2") `
    );
    await queryRunner.query(
      `CREATE TABLE "work_character_interact_with_interaction_tag" ("workCharacterId" integer NOT NULL, "interactionTagId" integer NOT NULL, PRIMARY KEY ("workCharacterId", "interactionTagId"))`
    );
    await queryRunner.query(
      `CREATE INDEX "IDX_ea7223119791621d218a057fed" ON "work_character_interact_with_interaction_tag" ("workCharacterId") `
    );
    await queryRunner.query(
      `CREATE INDEX "IDX_afd120250d0daa21d1f444a7f5" ON "work_character_interact_with_interaction_tag" ("interactionTagId") `
    );
    await queryRunner.query(
      `CREATE TABLE "work_character_interacted_by_interaction_tag" ("workCharacterId" integer NOT NULL, "interactionTagId" integer NOT NULL, PRIMARY KEY ("workCharacterId", "interactionTagId"))`
    );
    await queryRunner.query(
      `CREATE INDEX "IDX_a10591bbdbfb5335497e9304b2" ON "work_character_interacted_by_interaction_tag" ("workCharacterId") `
    );
    await queryRunner.query(
      `CREATE INDEX "IDX_63813d9b11cd5a55afc0e91a89" ON "work_character_interacted_by_interaction_tag" ("interactionTagId") `
    );
    await queryRunner.query(
      `CREATE TABLE "work_character_world_characters_world_character" ("workCharacterId" integer NOT NULL, "worldCharacterId" integer NOT NULL, PRIMARY KEY ("workCharacterId", "worldCharacterId"))`
    );
    await queryRunner.query(
      `CREATE INDEX "IDX_1664b7580fcb1d7abb64f6e966" ON "work_character_world_characters_world_character" ("workCharacterId") `
    );
    await queryRunner.query(
      `CREATE INDEX "IDX_a08cc5365ab334c6e7069956e4" ON "work_character_world_characters_world_character" ("worldCharacterId") `
    );
    await queryRunner.query(
      `CREATE TABLE "work_work_characters_work_character" ("workId" integer NOT NULL, "workCharacterId" integer NOT NULL, PRIMARY KEY ("workId", "workCharacterId"))`
    );
    await queryRunner.query(
      `CREATE INDEX "IDX_20407f9e6a1233ba7b259e0b5d" ON "work_work_characters_work_character" ("workId") `
    );
    await queryRunner.query(
      `CREATE INDEX "IDX_a5d9f2079722eae5a50d10d7df" ON "work_work_characters_work_character" ("workCharacterId") `
    );
    await queryRunner.query(
      `CREATE TABLE "work_worlds_world" ("workId" integer NOT NULL, "worldId" integer NOT NULL, PRIMARY KEY ("workId", "worldId"))`
    );
    await queryRunner.query(`CREATE INDEX "IDX_4406a0c9878a37f1ad0925c8cb" ON "work_worlds_world" ("workId") `);
    await queryRunner.query(`CREATE INDEX "IDX_2d04b8685d3b47ce211bc3dc64" ON "work_worlds_world" ("worldId") `);
    await queryRunner.query(
      `CREATE TABLE "work_languages_language" ("workId" integer NOT NULL, "languageCode" varchar NOT NULL, PRIMARY KEY ("workId", "languageCode"))`
    );
    await queryRunner.query(`CREATE INDEX "IDX_3cb2ff97f8d87838282acaf2ca" ON "work_languages_language" ("workId") `);
    await queryRunner.query(
      `CREATE INDEX "IDX_59f68c6bf6a70cdce720966eee" ON "work_languages_language" ("languageCode") `
    );
    await queryRunner.query(
      `CREATE TABLE "work_author_author_roles_author_role" ("workAuthorId" integer NOT NULL, "authorRoleId" integer NOT NULL, PRIMARY KEY ("workAuthorId", "authorRoleId"))`
    );
    await queryRunner.query(
      `CREATE INDEX "IDX_ad6eb15a9e307bbc0071e45584" ON "work_author_author_roles_author_role" ("workAuthorId") `
    );
    await queryRunner.query(
      `CREATE INDEX "IDX_1f53233757f73a30345a845b36" ON "work_author_author_roles_author_role" ("authorRoleId") `
    );
    await queryRunner.query(
      `CREATE TABLE "temporary_author_role_name" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL DEFAULT (''), "entityId" integer NOT NULL, CONSTRAINT "FK_53007d787184883d4f88f518213" FOREIGN KEY ("entityId") REFERENCES "author_role" ("id") ON DELETE CASCADE ON UPDATE CASCADE)`
    );
    await queryRunner.query(
      `INSERT INTO "temporary_author_role_name"("id", "name", "entityId") SELECT "id", "name", "entityId" FROM "author_role_name"`
    );
    await queryRunner.query(`DROP TABLE "author_role_name"`);
    await queryRunner.query(`ALTER TABLE "temporary_author_role_name" RENAME TO "author_role_name"`);
    await queryRunner.query(
      `CREATE TABLE "temporary_collection_name" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL DEFAULT (''), "entityId" integer NOT NULL, CONSTRAINT "FK_e32c613ebf793bdec166b99c67c" FOREIGN KEY ("entityId") REFERENCES "collection" ("id") ON DELETE CASCADE ON UPDATE CASCADE)`
    );
    await queryRunner.query(
      `INSERT INTO "temporary_collection_name"("id", "name", "entityId") SELECT "id", "name", "entityId" FROM "collection_name"`
    );
    await queryRunner.query(`DROP TABLE "collection_name"`);
    await queryRunner.query(`ALTER TABLE "temporary_collection_name" RENAME TO "collection_name"`);
    await queryRunner.query(
      `CREATE TABLE "temporary_collection_part" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "order" integer NOT NULL DEFAULT (0), "collectionId" integer NOT NULL, "workId" integer NOT NULL, CONSTRAINT "FK_a331dfd7f97355b0241aabbe9dd" FOREIGN KEY ("collectionId") REFERENCES "collection" ("id") ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT "FK_76bf2490e80346af774adb9f0f0" FOREIGN KEY ("workId") REFERENCES "work" ("id") ON DELETE CASCADE ON UPDATE CASCADE)`
    );
    await queryRunner.query(
      `INSERT INTO "temporary_collection_part"("id", "order", "collectionId", "workId") SELECT "id", "order", "collectionId", "workId" FROM "collection_part"`
    );
    await queryRunner.query(`DROP TABLE "collection_part"`);
    await queryRunner.query(`ALTER TABLE "temporary_collection_part" RENAME TO "collection_part"`);
    await queryRunner.query(
      `CREATE TABLE "temporary_site_name" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL DEFAULT (''), "entityId" integer NOT NULL, CONSTRAINT "FK_320041fe1c2631a761b25d4446a" FOREIGN KEY ("entityId") REFERENCES "site" ("id") ON DELETE CASCADE ON UPDATE CASCADE)`
    );
    await queryRunner.query(
      `INSERT INTO "temporary_site_name"("id", "name", "entityId") SELECT "id", "name", "entityId" FROM "site_name"`
    );
    await queryRunner.query(`DROP TABLE "site_name"`);
    await queryRunner.query(`ALTER TABLE "temporary_site_name" RENAME TO "site_name"`);
    await queryRunner.query(
      `CREATE TABLE "temporary_source" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "uri" varchar NOT NULL DEFAULT (''), "siteId" integer, CONSTRAINT "FK_73b253e679f350d140bdb104e49" FOREIGN KEY ("siteId") REFERENCES "site" ("id") ON DELETE RESTRICT ON UPDATE CASCADE)`
    );
    await queryRunner.query(
      `INSERT INTO "temporary_source"("id", "uri", "siteId") SELECT "id", "uri", "siteId" FROM "source"`
    );
    await queryRunner.query(`DROP TABLE "source"`);
    await queryRunner.query(`ALTER TABLE "temporary_source" RENAME TO "source"`);
    await queryRunner.query(
      `CREATE TABLE "temporary_copy" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "hash" varchar NOT NULL DEFAULT (''), "location" text, "ranking" integer NOT NULL DEFAULT (0), "originalId" integer NOT NULL, CONSTRAINT "FK_e8ce0011cf0a8b9fdc8ad908a44" FOREIGN KEY ("originalId") REFERENCES "work" ("id") ON DELETE CASCADE ON UPDATE CASCADE)`
    );
    await queryRunner.query(
      `INSERT INTO "temporary_copy"("id", "hash", "location", "ranking", "originalId") SELECT "id", "hash", "location", "ranking", "originalId" FROM "copy"`
    );
    await queryRunner.query(`DROP TABLE "copy"`);
    await queryRunner.query(`ALTER TABLE "temporary_copy" RENAME TO "copy"`);
    await queryRunner.query(
      `CREATE TABLE "temporary_transformation_type_name" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL DEFAULT (''), "entityId" integer NOT NULL, CONSTRAINT "FK_5bc54ac960e6587c39297194ec6" FOREIGN KEY ("entityId") REFERENCES "transformation_type" ("id") ON DELETE CASCADE ON UPDATE CASCADE)`
    );
    await queryRunner.query(
      `INSERT INTO "temporary_transformation_type_name"("id", "name", "entityId") SELECT "id", "name", "entityId" FROM "transformation_type_name"`
    );
    await queryRunner.query(`DROP TABLE "transformation_type_name"`);
    await queryRunner.query(`ALTER TABLE "temporary_transformation_type_name" RENAME TO "transformation_type_name"`);
    await queryRunner.query(
      `CREATE TABLE "temporary_transformation" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "order" integer NOT NULL DEFAULT (0), "byWorkId" integer NOT NULL, "typeId" integer NOT NULL, "ofWorkId" integer NOT NULL, CONSTRAINT "FK_263a368f9017f5725c4fa12351b" FOREIGN KEY ("byWorkId") REFERENCES "work" ("id") ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT "FK_4deb36ce15d6547c1ed7e994720" FOREIGN KEY ("typeId") REFERENCES "transformation_type" ("id") ON DELETE RESTRICT ON UPDATE CASCADE, CONSTRAINT "FK_d41fc0471e72b5d1dda372a662c" FOREIGN KEY ("ofWorkId") REFERENCES "work" ("id") ON DELETE CASCADE ON UPDATE CASCADE)`
    );
    await queryRunner.query(
      `INSERT INTO "temporary_transformation"("id", "order", "byWorkId", "typeId", "ofWorkId") SELECT "id", "order", "byWorkId", "typeId", "ofWorkId" FROM "transformation"`
    );
    await queryRunner.query(`DROP TABLE "transformation"`);
    await queryRunner.query(`ALTER TABLE "temporary_transformation" RENAME TO "transformation"`);
    await queryRunner.query(
      `CREATE TABLE "temporary_interaction_tag" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "weight" integer, "tagId" integer NOT NULL, CONSTRAINT "weight needs to be between 0 and 9007199254740991" CHECK (weight >= 0 AND weight <= 9007199254740991), CONSTRAINT "FK_af4c7e7219611f6b6025b8276f0" FOREIGN KEY ("tagId") REFERENCES "tag" ("id") ON DELETE CASCADE ON UPDATE CASCADE)`
    );
    await queryRunner.query(
      `INSERT INTO "temporary_interaction_tag"("id", "weight", "tagId") SELECT "id", "weight", "tagId" FROM "interaction_tag"`
    );
    await queryRunner.query(`DROP TABLE "interaction_tag"`);
    await queryRunner.query(`ALTER TABLE "temporary_interaction_tag" RENAME TO "interaction_tag"`);
    await queryRunner.query(
      `CREATE TABLE "temporary_tag_name" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL DEFAULT (''), "entityId" integer NOT NULL, CONSTRAINT "FK_94c570315f982d2434046c30dc1" FOREIGN KEY ("entityId") REFERENCES "tag" ("id") ON DELETE CASCADE ON UPDATE CASCADE)`
    );
    await queryRunner.query(
      `INSERT INTO "temporary_tag_name"("id", "name", "entityId") SELECT "id", "name", "entityId" FROM "tag_name"`
    );
    await queryRunner.query(`DROP TABLE "tag_name"`);
    await queryRunner.query(`ALTER TABLE "temporary_tag_name" RENAME TO "tag_name"`);
    await queryRunner.query(
      `CREATE TABLE "temporary_work_tag" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "weight" integer, "tagId" integer NOT NULL, "workId" integer NOT NULL, CONSTRAINT "weight needs to be between 0 and 9007199254740991" CHECK (weight >= 0 AND weight <= 9007199254740991), CONSTRAINT "FK_8428f32a2c63df16b605e77326e" FOREIGN KEY ("tagId") REFERENCES "tag" ("id") ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT "FK_13dd6d2f7b58c451636bf28b4f8" FOREIGN KEY ("workId") REFERENCES "work" ("id") ON DELETE CASCADE ON UPDATE CASCADE)`
    );
    await queryRunner.query(
      `INSERT INTO "temporary_work_tag"("id", "weight", "tagId", "workId") SELECT "id", "weight", "tagId", "workId" FROM "work_tag"`
    );
    await queryRunner.query(`DROP TABLE "work_tag"`);
    await queryRunner.query(`ALTER TABLE "temporary_work_tag" RENAME TO "work_tag"`);
    await queryRunner.query(
      `CREATE TABLE "temporary_character_tag" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "weight" integer, "workCharacterId" integer NOT NULL, "tagId" integer NOT NULL, CONSTRAINT "weight needs to be between 0 and 9007199254740991" CHECK (weight >= 0 AND weight <= 9007199254740991), CONSTRAINT "FK_0c27931804d469fba75a2c5d357" FOREIGN KEY ("workCharacterId") REFERENCES "work_character" ("id") ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT "FK_14ffc3712f3341e793668b2cd61" FOREIGN KEY ("tagId") REFERENCES "tag" ("id") ON DELETE CASCADE ON UPDATE CASCADE)`
    );
    await queryRunner.query(
      `INSERT INTO "temporary_character_tag"("id", "weight", "workCharacterId", "tagId") SELECT "id", "weight", "workCharacterId", "tagId" FROM "character_tag"`
    );
    await queryRunner.query(`DROP TABLE "character_tag"`);
    await queryRunner.query(`ALTER TABLE "temporary_character_tag" RENAME TO "character_tag"`);
    await queryRunner.query(
      `CREATE TABLE "temporary_work_character_name" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL DEFAULT (''), "entityId" integer NOT NULL, CONSTRAINT "FK_0f95e554fd5bd674937f733f219" FOREIGN KEY ("entityId") REFERENCES "work_character" ("id") ON DELETE CASCADE ON UPDATE CASCADE)`
    );
    await queryRunner.query(
      `INSERT INTO "temporary_work_character_name"("id", "name", "entityId") SELECT "id", "name", "entityId" FROM "work_character_name"`
    );
    await queryRunner.query(`DROP TABLE "work_character_name"`);
    await queryRunner.query(`ALTER TABLE "temporary_work_character_name" RENAME TO "work_character_name"`);
    await queryRunner.query(
      `CREATE TABLE "temporary_world_name" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL DEFAULT (''), "entityId" integer NOT NULL, CONSTRAINT "FK_1147cb1b497ecbf3b8d3c2ac1b3" FOREIGN KEY ("entityId") REFERENCES "world" ("id") ON DELETE CASCADE ON UPDATE CASCADE)`
    );
    await queryRunner.query(
      `INSERT INTO "temporary_world_name"("id", "name", "entityId") SELECT "id", "name", "entityId" FROM "world_name"`
    );
    await queryRunner.query(`DROP TABLE "world_name"`);
    await queryRunner.query(`ALTER TABLE "temporary_world_name" RENAME TO "world_name"`);
    await queryRunner.query(
      `CREATE TABLE "temporary_world_character_name" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL DEFAULT (''), "entityId" integer NOT NULL, CONSTRAINT "FK_00fb48ee8ded5c6bc3061c83cbb" FOREIGN KEY ("entityId") REFERENCES "world_character" ("id") ON DELETE CASCADE ON UPDATE CASCADE)`
    );
    await queryRunner.query(
      `INSERT INTO "temporary_world_character_name"("id", "name", "entityId") SELECT "id", "name", "entityId" FROM "world_character_name"`
    );
    await queryRunner.query(`DROP TABLE "world_character_name"`);
    await queryRunner.query(`ALTER TABLE "temporary_world_character_name" RENAME TO "world_character_name"`);
    await queryRunner.query(
      `CREATE TABLE "temporary_work_name" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL DEFAULT (''), "entityId" integer NOT NULL, CONSTRAINT "FK_e9887937be670e7056b2ce480d2" FOREIGN KEY ("entityId") REFERENCES "work" ("id") ON DELETE CASCADE ON UPDATE CASCADE)`
    );
    await queryRunner.query(
      `INSERT INTO "temporary_work_name"("id", "name", "entityId") SELECT "id", "name", "entityId" FROM "work_name"`
    );
    await queryRunner.query(`DROP TABLE "work_name"`);
    await queryRunner.query(`ALTER TABLE "temporary_work_name" RENAME TO "work_name"`);
    await queryRunner.query(
      `CREATE TABLE "temporary_work_author" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "order" integer NOT NULL DEFAULT (0), "workId" integer NOT NULL, "authorId" integer NOT NULL, CONSTRAINT "FK_661d8f5cdb4bd215ad16301e0b1" FOREIGN KEY ("workId") REFERENCES "work" ("id") ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT "FK_a2045b9fc41c357d2c98d5a9d60" FOREIGN KEY ("authorId") REFERENCES "author" ("id") ON DELETE RESTRICT ON UPDATE CASCADE)`
    );
    await queryRunner.query(
      `INSERT INTO "temporary_work_author"("id", "order", "workId", "authorId") SELECT "id", "order", "workId", "authorId" FROM "work_author"`
    );
    await queryRunner.query(`DROP TABLE "work_author"`);
    await queryRunner.query(`ALTER TABLE "temporary_work_author" RENAME TO "work_author"`);
    await queryRunner.query(
      `CREATE TABLE "temporary_author_name" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL DEFAULT (''), "entityId" integer NOT NULL, CONSTRAINT "FK_fb4e8ac4593d1c4d5b10c013d41" FOREIGN KEY ("entityId") REFERENCES "author" ("id") ON DELETE CASCADE ON UPDATE CASCADE)`
    );
    await queryRunner.query(
      `INSERT INTO "temporary_author_name"("id", "name", "entityId") SELECT "id", "name", "entityId" FROM "author_name"`
    );
    await queryRunner.query(`DROP TABLE "author_name"`);
    await queryRunner.query(`ALTER TABLE "temporary_author_name" RENAME TO "author_name"`);
    await queryRunner.query(`DROP INDEX "IDX_653c33c5db26b8736e592ff3f6"`);
    await queryRunner.query(`DROP INDEX "IDX_946af3644f779b7cc7e7eb04eb"`);
    await queryRunner.query(
      `CREATE TABLE "temporary_copy_sources_source" ("copyId" integer NOT NULL, "sourceId" integer NOT NULL, CONSTRAINT "FK_653c33c5db26b8736e592ff3f65" FOREIGN KEY ("copyId") REFERENCES "copy" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, CONSTRAINT "FK_946af3644f779b7cc7e7eb04eb7" FOREIGN KEY ("sourceId") REFERENCES "source" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, PRIMARY KEY ("copyId", "sourceId"))`
    );
    await queryRunner.query(
      `INSERT INTO "temporary_copy_sources_source"("copyId", "sourceId") SELECT "copyId", "sourceId" FROM "copy_sources_source"`
    );
    await queryRunner.query(`DROP TABLE "copy_sources_source"`);
    await queryRunner.query(`ALTER TABLE "temporary_copy_sources_source" RENAME TO "copy_sources_source"`);
    await queryRunner.query(`CREATE INDEX "IDX_653c33c5db26b8736e592ff3f6" ON "copy_sources_source" ("copyId") `);
    await queryRunner.query(`CREATE INDEX "IDX_946af3644f779b7cc7e7eb04eb" ON "copy_sources_source" ("sourceId") `);
    await queryRunner.query(`DROP INDEX "IDX_a56aff619335e19bd07e252d11"`);
    await queryRunner.query(`DROP INDEX "IDX_1850c401823bc25103bb621657"`);
    await queryRunner.query(
      `CREATE TABLE "temporary_tag_parents_tag" ("tagId_1" integer NOT NULL, "tagId_2" integer NOT NULL, CONSTRAINT "FK_a56aff619335e19bd07e252d115" FOREIGN KEY ("tagId_1") REFERENCES "tag" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, CONSTRAINT "FK_1850c401823bc25103bb6216578" FOREIGN KEY ("tagId_2") REFERENCES "tag" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, PRIMARY KEY ("tagId_1", "tagId_2"))`
    );
    await queryRunner.query(
      `INSERT INTO "temporary_tag_parents_tag"("tagId_1", "tagId_2") SELECT "tagId_1", "tagId_2" FROM "tag_parents_tag"`
    );
    await queryRunner.query(`DROP TABLE "tag_parents_tag"`);
    await queryRunner.query(`ALTER TABLE "temporary_tag_parents_tag" RENAME TO "tag_parents_tag"`);
    await queryRunner.query(`CREATE INDEX "IDX_a56aff619335e19bd07e252d11" ON "tag_parents_tag" ("tagId_1") `);
    await queryRunner.query(`CREATE INDEX "IDX_1850c401823bc25103bb621657" ON "tag_parents_tag" ("tagId_2") `);
    await queryRunner.query(`DROP INDEX "IDX_6024260e0f5118a2379be24a3f"`);
    await queryRunner.query(`DROP INDEX "IDX_ded86f18df3574ee221fff525c"`);
    await queryRunner.query(
      `CREATE TABLE "temporary_world_world_characters_world_character" ("worldId" integer NOT NULL, "worldCharacterId" integer NOT NULL, CONSTRAINT "FK_6024260e0f5118a2379be24a3fe" FOREIGN KEY ("worldId") REFERENCES "world" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, CONSTRAINT "FK_ded86f18df3574ee221fff525cd" FOREIGN KEY ("worldCharacterId") REFERENCES "world_character" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, PRIMARY KEY ("worldId", "worldCharacterId"))`
    );
    await queryRunner.query(
      `INSERT INTO "temporary_world_world_characters_world_character"("worldId", "worldCharacterId") SELECT "worldId", "worldCharacterId" FROM "world_world_characters_world_character"`
    );
    await queryRunner.query(`DROP TABLE "world_world_characters_world_character"`);
    await queryRunner.query(
      `ALTER TABLE "temporary_world_world_characters_world_character" RENAME TO "world_world_characters_world_character"`
    );
    await queryRunner.query(
      `CREATE INDEX "IDX_6024260e0f5118a2379be24a3f" ON "world_world_characters_world_character" ("worldId") `
    );
    await queryRunner.query(
      `CREATE INDEX "IDX_ded86f18df3574ee221fff525c" ON "world_world_characters_world_character" ("worldCharacterId") `
    );
    await queryRunner.query(`DROP INDEX "IDX_7864295ed996ae9d36db032c70"`);
    await queryRunner.query(`DROP INDEX "IDX_63bee78016e6eb0188abded4b5"`);
    await queryRunner.query(
      `CREATE TABLE "temporary_world_parents_world" ("worldId_1" integer NOT NULL, "worldId_2" integer NOT NULL, CONSTRAINT "FK_7864295ed996ae9d36db032c708" FOREIGN KEY ("worldId_1") REFERENCES "world" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, CONSTRAINT "FK_63bee78016e6eb0188abded4b50" FOREIGN KEY ("worldId_2") REFERENCES "world" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, PRIMARY KEY ("worldId_1", "worldId_2"))`
    );
    await queryRunner.query(
      `INSERT INTO "temporary_world_parents_world"("worldId_1", "worldId_2") SELECT "worldId_1", "worldId_2" FROM "world_parents_world"`
    );
    await queryRunner.query(`DROP TABLE "world_parents_world"`);
    await queryRunner.query(`ALTER TABLE "temporary_world_parents_world" RENAME TO "world_parents_world"`);
    await queryRunner.query(`CREATE INDEX "IDX_7864295ed996ae9d36db032c70" ON "world_parents_world" ("worldId_1") `);
    await queryRunner.query(`CREATE INDEX "IDX_63bee78016e6eb0188abded4b5" ON "world_parents_world" ("worldId_2") `);
    await queryRunner.query(`DROP INDEX "IDX_51a5b3b73ad0f5af3da0018e16"`);
    await queryRunner.query(`DROP INDEX "IDX_617d4b51c57be06e915f41df7c"`);
    await queryRunner.query(
      `CREATE TABLE "temporary_world_character_parents_world_character" ("worldCharacterId_1" integer NOT NULL, "worldCharacterId_2" integer NOT NULL, CONSTRAINT "FK_51a5b3b73ad0f5af3da0018e164" FOREIGN KEY ("worldCharacterId_1") REFERENCES "world_character" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, CONSTRAINT "FK_617d4b51c57be06e915f41df7ce" FOREIGN KEY ("worldCharacterId_2") REFERENCES "world_character" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, PRIMARY KEY ("worldCharacterId_1", "worldCharacterId_2"))`
    );
    await queryRunner.query(
      `INSERT INTO "temporary_world_character_parents_world_character"("worldCharacterId_1", "worldCharacterId_2") SELECT "worldCharacterId_1", "worldCharacterId_2" FROM "world_character_parents_world_character"`
    );
    await queryRunner.query(`DROP TABLE "world_character_parents_world_character"`);
    await queryRunner.query(
      `ALTER TABLE "temporary_world_character_parents_world_character" RENAME TO "world_character_parents_world_character"`
    );
    await queryRunner.query(
      `CREATE INDEX "IDX_51a5b3b73ad0f5af3da0018e16" ON "world_character_parents_world_character" ("worldCharacterId_1") `
    );
    await queryRunner.query(
      `CREATE INDEX "IDX_617d4b51c57be06e915f41df7c" ON "world_character_parents_world_character" ("worldCharacterId_2") `
    );
    await queryRunner.query(`DROP INDEX "IDX_ea7223119791621d218a057fed"`);
    await queryRunner.query(`DROP INDEX "IDX_afd120250d0daa21d1f444a7f5"`);
    await queryRunner.query(
      `CREATE TABLE "temporary_work_character_interact_with_interaction_tag" ("workCharacterId" integer NOT NULL, "interactionTagId" integer NOT NULL, CONSTRAINT "FK_ea7223119791621d218a057fed2" FOREIGN KEY ("workCharacterId") REFERENCES "work_character" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, CONSTRAINT "FK_afd120250d0daa21d1f444a7f59" FOREIGN KEY ("interactionTagId") REFERENCES "interaction_tag" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, PRIMARY KEY ("workCharacterId", "interactionTagId"))`
    );
    await queryRunner.query(
      `INSERT INTO "temporary_work_character_interact_with_interaction_tag"("workCharacterId", "interactionTagId") SELECT "workCharacterId", "interactionTagId" FROM "work_character_interact_with_interaction_tag"`
    );
    await queryRunner.query(`DROP TABLE "work_character_interact_with_interaction_tag"`);
    await queryRunner.query(
      `ALTER TABLE "temporary_work_character_interact_with_interaction_tag" RENAME TO "work_character_interact_with_interaction_tag"`
    );
    await queryRunner.query(
      `CREATE INDEX "IDX_ea7223119791621d218a057fed" ON "work_character_interact_with_interaction_tag" ("workCharacterId") `
    );
    await queryRunner.query(
      `CREATE INDEX "IDX_afd120250d0daa21d1f444a7f5" ON "work_character_interact_with_interaction_tag" ("interactionTagId") `
    );
    await queryRunner.query(`DROP INDEX "IDX_a10591bbdbfb5335497e9304b2"`);
    await queryRunner.query(`DROP INDEX "IDX_63813d9b11cd5a55afc0e91a89"`);
    await queryRunner.query(
      `CREATE TABLE "temporary_work_character_interacted_by_interaction_tag" ("workCharacterId" integer NOT NULL, "interactionTagId" integer NOT NULL, CONSTRAINT "FK_a10591bbdbfb5335497e9304b27" FOREIGN KEY ("workCharacterId") REFERENCES "work_character" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, CONSTRAINT "FK_63813d9b11cd5a55afc0e91a89f" FOREIGN KEY ("interactionTagId") REFERENCES "interaction_tag" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, PRIMARY KEY ("workCharacterId", "interactionTagId"))`
    );
    await queryRunner.query(
      `INSERT INTO "temporary_work_character_interacted_by_interaction_tag"("workCharacterId", "interactionTagId") SELECT "workCharacterId", "interactionTagId" FROM "work_character_interacted_by_interaction_tag"`
    );
    await queryRunner.query(`DROP TABLE "work_character_interacted_by_interaction_tag"`);
    await queryRunner.query(
      `ALTER TABLE "temporary_work_character_interacted_by_interaction_tag" RENAME TO "work_character_interacted_by_interaction_tag"`
    );
    await queryRunner.query(
      `CREATE INDEX "IDX_a10591bbdbfb5335497e9304b2" ON "work_character_interacted_by_interaction_tag" ("workCharacterId") `
    );
    await queryRunner.query(
      `CREATE INDEX "IDX_63813d9b11cd5a55afc0e91a89" ON "work_character_interacted_by_interaction_tag" ("interactionTagId") `
    );
    await queryRunner.query(`DROP INDEX "IDX_1664b7580fcb1d7abb64f6e966"`);
    await queryRunner.query(`DROP INDEX "IDX_a08cc5365ab334c6e7069956e4"`);
    await queryRunner.query(
      `CREATE TABLE "temporary_work_character_world_characters_world_character" ("workCharacterId" integer NOT NULL, "worldCharacterId" integer NOT NULL, CONSTRAINT "FK_1664b7580fcb1d7abb64f6e9665" FOREIGN KEY ("workCharacterId") REFERENCES "work_character" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, CONSTRAINT "FK_a08cc5365ab334c6e7069956e46" FOREIGN KEY ("worldCharacterId") REFERENCES "world_character" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, PRIMARY KEY ("workCharacterId", "worldCharacterId"))`
    );
    await queryRunner.query(
      `INSERT INTO "temporary_work_character_world_characters_world_character"("workCharacterId", "worldCharacterId") SELECT "workCharacterId", "worldCharacterId" FROM "work_character_world_characters_world_character"`
    );
    await queryRunner.query(`DROP TABLE "work_character_world_characters_world_character"`);
    await queryRunner.query(
      `ALTER TABLE "temporary_work_character_world_characters_world_character" RENAME TO "work_character_world_characters_world_character"`
    );
    await queryRunner.query(
      `CREATE INDEX "IDX_1664b7580fcb1d7abb64f6e966" ON "work_character_world_characters_world_character" ("workCharacterId") `
    );
    await queryRunner.query(
      `CREATE INDEX "IDX_a08cc5365ab334c6e7069956e4" ON "work_character_world_characters_world_character" ("worldCharacterId") `
    );
    await queryRunner.query(`DROP INDEX "IDX_20407f9e6a1233ba7b259e0b5d"`);
    await queryRunner.query(`DROP INDEX "IDX_a5d9f2079722eae5a50d10d7df"`);
    await queryRunner.query(
      `CREATE TABLE "temporary_work_work_characters_work_character" ("workId" integer NOT NULL, "workCharacterId" integer NOT NULL, CONSTRAINT "FK_20407f9e6a1233ba7b259e0b5da" FOREIGN KEY ("workId") REFERENCES "work" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, CONSTRAINT "FK_a5d9f2079722eae5a50d10d7dfd" FOREIGN KEY ("workCharacterId") REFERENCES "work_character" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, PRIMARY KEY ("workId", "workCharacterId"))`
    );
    await queryRunner.query(
      `INSERT INTO "temporary_work_work_characters_work_character"("workId", "workCharacterId") SELECT "workId", "workCharacterId" FROM "work_work_characters_work_character"`
    );
    await queryRunner.query(`DROP TABLE "work_work_characters_work_character"`);
    await queryRunner.query(
      `ALTER TABLE "temporary_work_work_characters_work_character" RENAME TO "work_work_characters_work_character"`
    );
    await queryRunner.query(
      `CREATE INDEX "IDX_20407f9e6a1233ba7b259e0b5d" ON "work_work_characters_work_character" ("workId") `
    );
    await queryRunner.query(
      `CREATE INDEX "IDX_a5d9f2079722eae5a50d10d7df" ON "work_work_characters_work_character" ("workCharacterId") `
    );
    await queryRunner.query(`DROP INDEX "IDX_4406a0c9878a37f1ad0925c8cb"`);
    await queryRunner.query(`DROP INDEX "IDX_2d04b8685d3b47ce211bc3dc64"`);
    await queryRunner.query(
      `CREATE TABLE "temporary_work_worlds_world" ("workId" integer NOT NULL, "worldId" integer NOT NULL, CONSTRAINT "FK_4406a0c9878a37f1ad0925c8cb2" FOREIGN KEY ("workId") REFERENCES "work" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, CONSTRAINT "FK_2d04b8685d3b47ce211bc3dc648" FOREIGN KEY ("worldId") REFERENCES "world" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, PRIMARY KEY ("workId", "worldId"))`
    );
    await queryRunner.query(
      `INSERT INTO "temporary_work_worlds_world"("workId", "worldId") SELECT "workId", "worldId" FROM "work_worlds_world"`
    );
    await queryRunner.query(`DROP TABLE "work_worlds_world"`);
    await queryRunner.query(`ALTER TABLE "temporary_work_worlds_world" RENAME TO "work_worlds_world"`);
    await queryRunner.query(`CREATE INDEX "IDX_4406a0c9878a37f1ad0925c8cb" ON "work_worlds_world" ("workId") `);
    await queryRunner.query(`CREATE INDEX "IDX_2d04b8685d3b47ce211bc3dc64" ON "work_worlds_world" ("worldId") `);
    await queryRunner.query(`DROP INDEX "IDX_3cb2ff97f8d87838282acaf2ca"`);
    await queryRunner.query(`DROP INDEX "IDX_59f68c6bf6a70cdce720966eee"`);
    await queryRunner.query(
      `CREATE TABLE "temporary_work_languages_language" ("workId" integer NOT NULL, "languageCode" varchar NOT NULL, CONSTRAINT "FK_3cb2ff97f8d87838282acaf2ca3" FOREIGN KEY ("workId") REFERENCES "work" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, CONSTRAINT "FK_59f68c6bf6a70cdce720966eee6" FOREIGN KEY ("languageCode") REFERENCES "language" ("code") ON DELETE CASCADE ON UPDATE NO ACTION, PRIMARY KEY ("workId", "languageCode"))`
    );
    await queryRunner.query(
      `INSERT INTO "temporary_work_languages_language"("workId", "languageCode") SELECT "workId", "languageCode" FROM "work_languages_language"`
    );
    await queryRunner.query(`DROP TABLE "work_languages_language"`);
    await queryRunner.query(`ALTER TABLE "temporary_work_languages_language" RENAME TO "work_languages_language"`);
    await queryRunner.query(`CREATE INDEX "IDX_3cb2ff97f8d87838282acaf2ca" ON "work_languages_language" ("workId") `);
    await queryRunner.query(
      `CREATE INDEX "IDX_59f68c6bf6a70cdce720966eee" ON "work_languages_language" ("languageCode") `
    );
    await queryRunner.query(`DROP INDEX "IDX_ad6eb15a9e307bbc0071e45584"`);
    await queryRunner.query(`DROP INDEX "IDX_1f53233757f73a30345a845b36"`);
    await queryRunner.query(
      `CREATE TABLE "temporary_work_author_author_roles_author_role" ("workAuthorId" integer NOT NULL, "authorRoleId" integer NOT NULL, CONSTRAINT "FK_ad6eb15a9e307bbc0071e455843" FOREIGN KEY ("workAuthorId") REFERENCES "work_author" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, CONSTRAINT "FK_1f53233757f73a30345a845b36d" FOREIGN KEY ("authorRoleId") REFERENCES "author_role" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, PRIMARY KEY ("workAuthorId", "authorRoleId"))`
    );
    await queryRunner.query(
      `INSERT INTO "temporary_work_author_author_roles_author_role"("workAuthorId", "authorRoleId") SELECT "workAuthorId", "authorRoleId" FROM "work_author_author_roles_author_role"`
    );
    await queryRunner.query(`DROP TABLE "work_author_author_roles_author_role"`);
    await queryRunner.query(
      `ALTER TABLE "temporary_work_author_author_roles_author_role" RENAME TO "work_author_author_roles_author_role"`
    );
    await queryRunner.query(
      `CREATE INDEX "IDX_ad6eb15a9e307bbc0071e45584" ON "work_author_author_roles_author_role" ("workAuthorId") `
    );
    await queryRunner.query(
      `CREATE INDEX "IDX_1f53233757f73a30345a845b36" ON "work_author_author_roles_author_role" ("authorRoleId") `
    );
    await queryRunner.query(
      `CREATE TABLE "query-result-cache" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "identifier" varchar, "time" bigint NOT NULL, "duration" integer NOT NULL, "query" text NOT NULL, "result" text NOT NULL)`
    );
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(`DROP TABLE "query-result-cache"`);
    await queryRunner.query(`DROP INDEX "IDX_1f53233757f73a30345a845b36"`);
    await queryRunner.query(`DROP INDEX "IDX_ad6eb15a9e307bbc0071e45584"`);
    await queryRunner.query(
      `ALTER TABLE "work_author_author_roles_author_role" RENAME TO "temporary_work_author_author_roles_author_role"`
    );
    await queryRunner.query(
      `CREATE TABLE "work_author_author_roles_author_role" ("workAuthorId" integer NOT NULL, "authorRoleId" integer NOT NULL, PRIMARY KEY ("workAuthorId", "authorRoleId"))`
    );
    await queryRunner.query(
      `INSERT INTO "work_author_author_roles_author_role"("workAuthorId", "authorRoleId") SELECT "workAuthorId", "authorRoleId" FROM "temporary_work_author_author_roles_author_role"`
    );
    await queryRunner.query(`DROP TABLE "temporary_work_author_author_roles_author_role"`);
    await queryRunner.query(
      `CREATE INDEX "IDX_1f53233757f73a30345a845b36" ON "work_author_author_roles_author_role" ("authorRoleId") `
    );
    await queryRunner.query(
      `CREATE INDEX "IDX_ad6eb15a9e307bbc0071e45584" ON "work_author_author_roles_author_role" ("workAuthorId") `
    );
    await queryRunner.query(`DROP INDEX "IDX_59f68c6bf6a70cdce720966eee"`);
    await queryRunner.query(`DROP INDEX "IDX_3cb2ff97f8d87838282acaf2ca"`);
    await queryRunner.query(`ALTER TABLE "work_languages_language" RENAME TO "temporary_work_languages_language"`);
    await queryRunner.query(
      `CREATE TABLE "work_languages_language" ("workId" integer NOT NULL, "languageCode" varchar NOT NULL, PRIMARY KEY ("workId", "languageCode"))`
    );
    await queryRunner.query(
      `INSERT INTO "work_languages_language"("workId", "languageCode") SELECT "workId", "languageCode" FROM "temporary_work_languages_language"`
    );
    await queryRunner.query(`DROP TABLE "temporary_work_languages_language"`);
    await queryRunner.query(
      `CREATE INDEX "IDX_59f68c6bf6a70cdce720966eee" ON "work_languages_language" ("languageCode") `
    );
    await queryRunner.query(`CREATE INDEX "IDX_3cb2ff97f8d87838282acaf2ca" ON "work_languages_language" ("workId") `);
    await queryRunner.query(`DROP INDEX "IDX_2d04b8685d3b47ce211bc3dc64"`);
    await queryRunner.query(`DROP INDEX "IDX_4406a0c9878a37f1ad0925c8cb"`);
    await queryRunner.query(`ALTER TABLE "work_worlds_world" RENAME TO "temporary_work_worlds_world"`);
    await queryRunner.query(
      `CREATE TABLE "work_worlds_world" ("workId" integer NOT NULL, "worldId" integer NOT NULL, PRIMARY KEY ("workId", "worldId"))`
    );
    await queryRunner.query(
      `INSERT INTO "work_worlds_world"("workId", "worldId") SELECT "workId", "worldId" FROM "temporary_work_worlds_world"`
    );
    await queryRunner.query(`DROP TABLE "temporary_work_worlds_world"`);
    await queryRunner.query(`CREATE INDEX "IDX_2d04b8685d3b47ce211bc3dc64" ON "work_worlds_world" ("worldId") `);
    await queryRunner.query(`CREATE INDEX "IDX_4406a0c9878a37f1ad0925c8cb" ON "work_worlds_world" ("workId") `);
    await queryRunner.query(`DROP INDEX "IDX_a5d9f2079722eae5a50d10d7df"`);
    await queryRunner.query(`DROP INDEX "IDX_20407f9e6a1233ba7b259e0b5d"`);
    await queryRunner.query(
      `ALTER TABLE "work_work_characters_work_character" RENAME TO "temporary_work_work_characters_work_character"`
    );
    await queryRunner.query(
      `CREATE TABLE "work_work_characters_work_character" ("workId" integer NOT NULL, "workCharacterId" integer NOT NULL, PRIMARY KEY ("workId", "workCharacterId"))`
    );
    await queryRunner.query(
      `INSERT INTO "work_work_characters_work_character"("workId", "workCharacterId") SELECT "workId", "workCharacterId" FROM "temporary_work_work_characters_work_character"`
    );
    await queryRunner.query(`DROP TABLE "temporary_work_work_characters_work_character"`);
    await queryRunner.query(
      `CREATE INDEX "IDX_a5d9f2079722eae5a50d10d7df" ON "work_work_characters_work_character" ("workCharacterId") `
    );
    await queryRunner.query(
      `CREATE INDEX "IDX_20407f9e6a1233ba7b259e0b5d" ON "work_work_characters_work_character" ("workId") `
    );
    await queryRunner.query(`DROP INDEX "IDX_a08cc5365ab334c6e7069956e4"`);
    await queryRunner.query(`DROP INDEX "IDX_1664b7580fcb1d7abb64f6e966"`);
    await queryRunner.query(
      `ALTER TABLE "work_character_world_characters_world_character" RENAME TO "temporary_work_character_world_characters_world_character"`
    );
    await queryRunner.query(
      `CREATE TABLE "work_character_world_characters_world_character" ("workCharacterId" integer NOT NULL, "worldCharacterId" integer NOT NULL, PRIMARY KEY ("workCharacterId", "worldCharacterId"))`
    );
    await queryRunner.query(
      `INSERT INTO "work_character_world_characters_world_character"("workCharacterId", "worldCharacterId") SELECT "workCharacterId", "worldCharacterId" FROM "temporary_work_character_world_characters_world_character"`
    );
    await queryRunner.query(`DROP TABLE "temporary_work_character_world_characters_world_character"`);
    await queryRunner.query(
      `CREATE INDEX "IDX_a08cc5365ab334c6e7069956e4" ON "work_character_world_characters_world_character" ("worldCharacterId") `
    );
    await queryRunner.query(
      `CREATE INDEX "IDX_1664b7580fcb1d7abb64f6e966" ON "work_character_world_characters_world_character" ("workCharacterId") `
    );
    await queryRunner.query(`DROP INDEX "IDX_63813d9b11cd5a55afc0e91a89"`);
    await queryRunner.query(`DROP INDEX "IDX_a10591bbdbfb5335497e9304b2"`);
    await queryRunner.query(
      `ALTER TABLE "work_character_interacted_by_interaction_tag" RENAME TO "temporary_work_character_interacted_by_interaction_tag"`
    );
    await queryRunner.query(
      `CREATE TABLE "work_character_interacted_by_interaction_tag" ("workCharacterId" integer NOT NULL, "interactionTagId" integer NOT NULL, PRIMARY KEY ("workCharacterId", "interactionTagId"))`
    );
    await queryRunner.query(
      `INSERT INTO "work_character_interacted_by_interaction_tag"("workCharacterId", "interactionTagId") SELECT "workCharacterId", "interactionTagId" FROM "temporary_work_character_interacted_by_interaction_tag"`
    );
    await queryRunner.query(`DROP TABLE "temporary_work_character_interacted_by_interaction_tag"`);
    await queryRunner.query(
      `CREATE INDEX "IDX_63813d9b11cd5a55afc0e91a89" ON "work_character_interacted_by_interaction_tag" ("interactionTagId") `
    );
    await queryRunner.query(
      `CREATE INDEX "IDX_a10591bbdbfb5335497e9304b2" ON "work_character_interacted_by_interaction_tag" ("workCharacterId") `
    );
    await queryRunner.query(`DROP INDEX "IDX_afd120250d0daa21d1f444a7f5"`);
    await queryRunner.query(`DROP INDEX "IDX_ea7223119791621d218a057fed"`);
    await queryRunner.query(
      `ALTER TABLE "work_character_interact_with_interaction_tag" RENAME TO "temporary_work_character_interact_with_interaction_tag"`
    );
    await queryRunner.query(
      `CREATE TABLE "work_character_interact_with_interaction_tag" ("workCharacterId" integer NOT NULL, "interactionTagId" integer NOT NULL, PRIMARY KEY ("workCharacterId", "interactionTagId"))`
    );
    await queryRunner.query(
      `INSERT INTO "work_character_interact_with_interaction_tag"("workCharacterId", "interactionTagId") SELECT "workCharacterId", "interactionTagId" FROM "temporary_work_character_interact_with_interaction_tag"`
    );
    await queryRunner.query(`DROP TABLE "temporary_work_character_interact_with_interaction_tag"`);
    await queryRunner.query(
      `CREATE INDEX "IDX_afd120250d0daa21d1f444a7f5" ON "work_character_interact_with_interaction_tag" ("interactionTagId") `
    );
    await queryRunner.query(
      `CREATE INDEX "IDX_ea7223119791621d218a057fed" ON "work_character_interact_with_interaction_tag" ("workCharacterId") `
    );
    await queryRunner.query(`DROP INDEX "IDX_617d4b51c57be06e915f41df7c"`);
    await queryRunner.query(`DROP INDEX "IDX_51a5b3b73ad0f5af3da0018e16"`);
    await queryRunner.query(
      `ALTER TABLE "world_character_parents_world_character" RENAME TO "temporary_world_character_parents_world_character"`
    );
    await queryRunner.query(
      `CREATE TABLE "world_character_parents_world_character" ("worldCharacterId_1" integer NOT NULL, "worldCharacterId_2" integer NOT NULL, PRIMARY KEY ("worldCharacterId_1", "worldCharacterId_2"))`
    );
    await queryRunner.query(
      `INSERT INTO "world_character_parents_world_character"("worldCharacterId_1", "worldCharacterId_2") SELECT "worldCharacterId_1", "worldCharacterId_2" FROM "temporary_world_character_parents_world_character"`
    );
    await queryRunner.query(`DROP TABLE "temporary_world_character_parents_world_character"`);
    await queryRunner.query(
      `CREATE INDEX "IDX_617d4b51c57be06e915f41df7c" ON "world_character_parents_world_character" ("worldCharacterId_2") `
    );
    await queryRunner.query(
      `CREATE INDEX "IDX_51a5b3b73ad0f5af3da0018e16" ON "world_character_parents_world_character" ("worldCharacterId_1") `
    );
    await queryRunner.query(`DROP INDEX "IDX_63bee78016e6eb0188abded4b5"`);
    await queryRunner.query(`DROP INDEX "IDX_7864295ed996ae9d36db032c70"`);
    await queryRunner.query(`ALTER TABLE "world_parents_world" RENAME TO "temporary_world_parents_world"`);
    await queryRunner.query(
      `CREATE TABLE "world_parents_world" ("worldId_1" integer NOT NULL, "worldId_2" integer NOT NULL, PRIMARY KEY ("worldId_1", "worldId_2"))`
    );
    await queryRunner.query(
      `INSERT INTO "world_parents_world"("worldId_1", "worldId_2") SELECT "worldId_1", "worldId_2" FROM "temporary_world_parents_world"`
    );
    await queryRunner.query(`DROP TABLE "temporary_world_parents_world"`);
    await queryRunner.query(`CREATE INDEX "IDX_63bee78016e6eb0188abded4b5" ON "world_parents_world" ("worldId_2") `);
    await queryRunner.query(`CREATE INDEX "IDX_7864295ed996ae9d36db032c70" ON "world_parents_world" ("worldId_1") `);
    await queryRunner.query(`DROP INDEX "IDX_ded86f18df3574ee221fff525c"`);
    await queryRunner.query(`DROP INDEX "IDX_6024260e0f5118a2379be24a3f"`);
    await queryRunner.query(
      `ALTER TABLE "world_world_characters_world_character" RENAME TO "temporary_world_world_characters_world_character"`
    );
    await queryRunner.query(
      `CREATE TABLE "world_world_characters_world_character" ("worldId" integer NOT NULL, "worldCharacterId" integer NOT NULL, PRIMARY KEY ("worldId", "worldCharacterId"))`
    );
    await queryRunner.query(
      `INSERT INTO "world_world_characters_world_character"("worldId", "worldCharacterId") SELECT "worldId", "worldCharacterId" FROM "temporary_world_world_characters_world_character"`
    );
    await queryRunner.query(`DROP TABLE "temporary_world_world_characters_world_character"`);
    await queryRunner.query(
      `CREATE INDEX "IDX_ded86f18df3574ee221fff525c" ON "world_world_characters_world_character" ("worldCharacterId") `
    );
    await queryRunner.query(
      `CREATE INDEX "IDX_6024260e0f5118a2379be24a3f" ON "world_world_characters_world_character" ("worldId") `
    );
    await queryRunner.query(`DROP INDEX "IDX_1850c401823bc25103bb621657"`);
    await queryRunner.query(`DROP INDEX "IDX_a56aff619335e19bd07e252d11"`);
    await queryRunner.query(`ALTER TABLE "tag_parents_tag" RENAME TO "temporary_tag_parents_tag"`);
    await queryRunner.query(
      `CREATE TABLE "tag_parents_tag" ("tagId_1" integer NOT NULL, "tagId_2" integer NOT NULL, PRIMARY KEY ("tagId_1", "tagId_2"))`
    );
    await queryRunner.query(
      `INSERT INTO "tag_parents_tag"("tagId_1", "tagId_2") SELECT "tagId_1", "tagId_2" FROM "temporary_tag_parents_tag"`
    );
    await queryRunner.query(`DROP TABLE "temporary_tag_parents_tag"`);
    await queryRunner.query(`CREATE INDEX "IDX_1850c401823bc25103bb621657" ON "tag_parents_tag" ("tagId_2") `);
    await queryRunner.query(`CREATE INDEX "IDX_a56aff619335e19bd07e252d11" ON "tag_parents_tag" ("tagId_1") `);
    await queryRunner.query(`DROP INDEX "IDX_946af3644f779b7cc7e7eb04eb"`);
    await queryRunner.query(`DROP INDEX "IDX_653c33c5db26b8736e592ff3f6"`);
    await queryRunner.query(`ALTER TABLE "copy_sources_source" RENAME TO "temporary_copy_sources_source"`);
    await queryRunner.query(
      `CREATE TABLE "copy_sources_source" ("copyId" integer NOT NULL, "sourceId" integer NOT NULL, PRIMARY KEY ("copyId", "sourceId"))`
    );
    await queryRunner.query(
      `INSERT INTO "copy_sources_source"("copyId", "sourceId") SELECT "copyId", "sourceId" FROM "temporary_copy_sources_source"`
    );
    await queryRunner.query(`DROP TABLE "temporary_copy_sources_source"`);
    await queryRunner.query(`CREATE INDEX "IDX_946af3644f779b7cc7e7eb04eb" ON "copy_sources_source" ("sourceId") `);
    await queryRunner.query(`CREATE INDEX "IDX_653c33c5db26b8736e592ff3f6" ON "copy_sources_source" ("copyId") `);
    await queryRunner.query(`ALTER TABLE "author_name" RENAME TO "temporary_author_name"`);
    await queryRunner.query(
      `CREATE TABLE "author_name" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL DEFAULT (''), "entityId" integer NOT NULL)`
    );
    await queryRunner.query(
      `INSERT INTO "author_name"("id", "name", "entityId") SELECT "id", "name", "entityId" FROM "temporary_author_name"`
    );
    await queryRunner.query(`DROP TABLE "temporary_author_name"`);
    await queryRunner.query(`ALTER TABLE "work_author" RENAME TO "temporary_work_author"`);
    await queryRunner.query(
      `CREATE TABLE "work_author" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "order" integer NOT NULL DEFAULT (0), "workId" integer NOT NULL, "authorId" integer NOT NULL)`
    );
    await queryRunner.query(
      `INSERT INTO "work_author"("id", "order", "workId", "authorId") SELECT "id", "order", "workId", "authorId" FROM "temporary_work_author"`
    );
    await queryRunner.query(`DROP TABLE "temporary_work_author"`);
    await queryRunner.query(`ALTER TABLE "work_name" RENAME TO "temporary_work_name"`);
    await queryRunner.query(
      `CREATE TABLE "work_name" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL DEFAULT (''), "entityId" integer NOT NULL)`
    );
    await queryRunner.query(
      `INSERT INTO "work_name"("id", "name", "entityId") SELECT "id", "name", "entityId" FROM "temporary_work_name"`
    );
    await queryRunner.query(`DROP TABLE "temporary_work_name"`);
    await queryRunner.query(`ALTER TABLE "world_character_name" RENAME TO "temporary_world_character_name"`);
    await queryRunner.query(
      `CREATE TABLE "world_character_name" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL DEFAULT (''), "entityId" integer NOT NULL)`
    );
    await queryRunner.query(
      `INSERT INTO "world_character_name"("id", "name", "entityId") SELECT "id", "name", "entityId" FROM "temporary_world_character_name"`
    );
    await queryRunner.query(`DROP TABLE "temporary_world_character_name"`);
    await queryRunner.query(`ALTER TABLE "world_name" RENAME TO "temporary_world_name"`);
    await queryRunner.query(
      `CREATE TABLE "world_name" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL DEFAULT (''), "entityId" integer NOT NULL)`
    );
    await queryRunner.query(
      `INSERT INTO "world_name"("id", "name", "entityId") SELECT "id", "name", "entityId" FROM "temporary_world_name"`
    );
    await queryRunner.query(`DROP TABLE "temporary_world_name"`);
    await queryRunner.query(`ALTER TABLE "work_character_name" RENAME TO "temporary_work_character_name"`);
    await queryRunner.query(
      `CREATE TABLE "work_character_name" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL DEFAULT (''), "entityId" integer NOT NULL)`
    );
    await queryRunner.query(
      `INSERT INTO "work_character_name"("id", "name", "entityId") SELECT "id", "name", "entityId" FROM "temporary_work_character_name"`
    );
    await queryRunner.query(`DROP TABLE "temporary_work_character_name"`);
    await queryRunner.query(`ALTER TABLE "character_tag" RENAME TO "temporary_character_tag"`);
    await queryRunner.query(
      `CREATE TABLE "character_tag" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "weight" integer, "workCharacterId" integer NOT NULL, "tagId" integer NOT NULL, CONSTRAINT "weight needs to be between 0 and 9007199254740991" CHECK (weight >= 0 AND weight <= 9007199254740991))`
    );
    await queryRunner.query(
      `INSERT INTO "character_tag"("id", "weight", "workCharacterId", "tagId") SELECT "id", "weight", "workCharacterId", "tagId" FROM "temporary_character_tag"`
    );
    await queryRunner.query(`DROP TABLE "temporary_character_tag"`);
    await queryRunner.query(`ALTER TABLE "work_tag" RENAME TO "temporary_work_tag"`);
    await queryRunner.query(
      `CREATE TABLE "work_tag" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "weight" integer, "tagId" integer NOT NULL, "workId" integer NOT NULL, CONSTRAINT "weight needs to be between 0 and 9007199254740991" CHECK (weight >= 0 AND weight <= 9007199254740991))`
    );
    await queryRunner.query(
      `INSERT INTO "work_tag"("id", "weight", "tagId", "workId") SELECT "id", "weight", "tagId", "workId" FROM "temporary_work_tag"`
    );
    await queryRunner.query(`DROP TABLE "temporary_work_tag"`);
    await queryRunner.query(`ALTER TABLE "tag_name" RENAME TO "temporary_tag_name"`);
    await queryRunner.query(
      `CREATE TABLE "tag_name" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL DEFAULT (''), "entityId" integer NOT NULL)`
    );
    await queryRunner.query(
      `INSERT INTO "tag_name"("id", "name", "entityId") SELECT "id", "name", "entityId" FROM "temporary_tag_name"`
    );
    await queryRunner.query(`DROP TABLE "temporary_tag_name"`);
    await queryRunner.query(`ALTER TABLE "interaction_tag" RENAME TO "temporary_interaction_tag"`);
    await queryRunner.query(
      `CREATE TABLE "interaction_tag" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "weight" integer, "tagId" integer NOT NULL, CONSTRAINT "weight needs to be between 0 and 9007199254740991" CHECK (weight >= 0 AND weight <= 9007199254740991))`
    );
    await queryRunner.query(
      `INSERT INTO "interaction_tag"("id", "weight", "tagId") SELECT "id", "weight", "tagId" FROM "temporary_interaction_tag"`
    );
    await queryRunner.query(`DROP TABLE "temporary_interaction_tag"`);
    await queryRunner.query(`ALTER TABLE "transformation" RENAME TO "temporary_transformation"`);
    await queryRunner.query(
      `CREATE TABLE "transformation" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "order" integer NOT NULL DEFAULT (0), "byWorkId" integer NOT NULL, "typeId" integer NOT NULL, "ofWorkId" integer NOT NULL)`
    );
    await queryRunner.query(
      `INSERT INTO "transformation"("id", "order", "byWorkId", "typeId", "ofWorkId") SELECT "id", "order", "byWorkId", "typeId", "ofWorkId" FROM "temporary_transformation"`
    );
    await queryRunner.query(`DROP TABLE "temporary_transformation"`);
    await queryRunner.query(`ALTER TABLE "transformation_type_name" RENAME TO "temporary_transformation_type_name"`);
    await queryRunner.query(
      `CREATE TABLE "transformation_type_name" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL DEFAULT (''), "entityId" integer NOT NULL)`
    );
    await queryRunner.query(
      `INSERT INTO "transformation_type_name"("id", "name", "entityId") SELECT "id", "name", "entityId" FROM "temporary_transformation_type_name"`
    );
    await queryRunner.query(`DROP TABLE "temporary_transformation_type_name"`);
    await queryRunner.query(`ALTER TABLE "copy" RENAME TO "temporary_copy"`);
    await queryRunner.query(
      `CREATE TABLE "copy" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "hash" varchar NOT NULL DEFAULT (''), "location" text, "ranking" integer NOT NULL DEFAULT (0), "originalId" integer NOT NULL)`
    );
    await queryRunner.query(
      `INSERT INTO "copy"("id", "hash", "location", "ranking", "originalId") SELECT "id", "hash", "location", "ranking", "originalId" FROM "temporary_copy"`
    );
    await queryRunner.query(`DROP TABLE "temporary_copy"`);
    await queryRunner.query(`ALTER TABLE "source" RENAME TO "temporary_source"`);
    await queryRunner.query(
      `CREATE TABLE "source" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "uri" varchar NOT NULL DEFAULT (''), "siteId" integer)`
    );
    await queryRunner.query(
      `INSERT INTO "source"("id", "uri", "siteId") SELECT "id", "uri", "siteId" FROM "temporary_source"`
    );
    await queryRunner.query(`DROP TABLE "temporary_source"`);
    await queryRunner.query(`ALTER TABLE "site_name" RENAME TO "temporary_site_name"`);
    await queryRunner.query(
      `CREATE TABLE "site_name" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL DEFAULT (''), "entityId" integer NOT NULL)`
    );
    await queryRunner.query(
      `INSERT INTO "site_name"("id", "name", "entityId") SELECT "id", "name", "entityId" FROM "temporary_site_name"`
    );
    await queryRunner.query(`DROP TABLE "temporary_site_name"`);
    await queryRunner.query(`ALTER TABLE "collection_part" RENAME TO "temporary_collection_part"`);
    await queryRunner.query(
      `CREATE TABLE "collection_part" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "order" integer NOT NULL DEFAULT (0), "collectionId" integer NOT NULL, "workId" integer NOT NULL)`
    );
    await queryRunner.query(
      `INSERT INTO "collection_part"("id", "order", "collectionId", "workId") SELECT "id", "order", "collectionId", "workId" FROM "temporary_collection_part"`
    );
    await queryRunner.query(`DROP TABLE "temporary_collection_part"`);
    await queryRunner.query(`ALTER TABLE "collection_name" RENAME TO "temporary_collection_name"`);
    await queryRunner.query(
      `CREATE TABLE "collection_name" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL DEFAULT (''), "entityId" integer NOT NULL)`
    );
    await queryRunner.query(
      `INSERT INTO "collection_name"("id", "name", "entityId") SELECT "id", "name", "entityId" FROM "temporary_collection_name"`
    );
    await queryRunner.query(`DROP TABLE "temporary_collection_name"`);
    await queryRunner.query(`ALTER TABLE "author_role_name" RENAME TO "temporary_author_role_name"`);
    await queryRunner.query(
      `CREATE TABLE "author_role_name" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL DEFAULT (''), "entityId" integer NOT NULL)`
    );
    await queryRunner.query(
      `INSERT INTO "author_role_name"("id", "name", "entityId") SELECT "id", "name", "entityId" FROM "temporary_author_role_name"`
    );
    await queryRunner.query(`DROP TABLE "temporary_author_role_name"`);
    await queryRunner.query(`DROP INDEX "IDX_1f53233757f73a30345a845b36"`);
    await queryRunner.query(`DROP INDEX "IDX_ad6eb15a9e307bbc0071e45584"`);
    await queryRunner.query(`DROP TABLE "work_author_author_roles_author_role"`);
    await queryRunner.query(`DROP INDEX "IDX_59f68c6bf6a70cdce720966eee"`);
    await queryRunner.query(`DROP INDEX "IDX_3cb2ff97f8d87838282acaf2ca"`);
    await queryRunner.query(`DROP TABLE "work_languages_language"`);
    await queryRunner.query(`DROP INDEX "IDX_2d04b8685d3b47ce211bc3dc64"`);
    await queryRunner.query(`DROP INDEX "IDX_4406a0c9878a37f1ad0925c8cb"`);
    await queryRunner.query(`DROP TABLE "work_worlds_world"`);
    await queryRunner.query(`DROP INDEX "IDX_a5d9f2079722eae5a50d10d7df"`);
    await queryRunner.query(`DROP INDEX "IDX_20407f9e6a1233ba7b259e0b5d"`);
    await queryRunner.query(`DROP TABLE "work_work_characters_work_character"`);
    await queryRunner.query(`DROP INDEX "IDX_a08cc5365ab334c6e7069956e4"`);
    await queryRunner.query(`DROP INDEX "IDX_1664b7580fcb1d7abb64f6e966"`);
    await queryRunner.query(`DROP TABLE "work_character_world_characters_world_character"`);
    await queryRunner.query(`DROP INDEX "IDX_63813d9b11cd5a55afc0e91a89"`);
    await queryRunner.query(`DROP INDEX "IDX_a10591bbdbfb5335497e9304b2"`);
    await queryRunner.query(`DROP TABLE "work_character_interacted_by_interaction_tag"`);
    await queryRunner.query(`DROP INDEX "IDX_afd120250d0daa21d1f444a7f5"`);
    await queryRunner.query(`DROP INDEX "IDX_ea7223119791621d218a057fed"`);
    await queryRunner.query(`DROP TABLE "work_character_interact_with_interaction_tag"`);
    await queryRunner.query(`DROP INDEX "IDX_617d4b51c57be06e915f41df7c"`);
    await queryRunner.query(`DROP INDEX "IDX_51a5b3b73ad0f5af3da0018e16"`);
    await queryRunner.query(`DROP TABLE "world_character_parents_world_character"`);
    await queryRunner.query(`DROP INDEX "IDX_63bee78016e6eb0188abded4b5"`);
    await queryRunner.query(`DROP INDEX "IDX_7864295ed996ae9d36db032c70"`);
    await queryRunner.query(`DROP TABLE "world_parents_world"`);
    await queryRunner.query(`DROP INDEX "IDX_ded86f18df3574ee221fff525c"`);
    await queryRunner.query(`DROP INDEX "IDX_6024260e0f5118a2379be24a3f"`);
    await queryRunner.query(`DROP TABLE "world_world_characters_world_character"`);
    await queryRunner.query(`DROP INDEX "IDX_1850c401823bc25103bb621657"`);
    await queryRunner.query(`DROP INDEX "IDX_a56aff619335e19bd07e252d11"`);
    await queryRunner.query(`DROP TABLE "tag_parents_tag"`);
    await queryRunner.query(`DROP INDEX "IDX_946af3644f779b7cc7e7eb04eb"`);
    await queryRunner.query(`DROP INDEX "IDX_653c33c5db26b8736e592ff3f6"`);
    await queryRunner.query(`DROP TABLE "copy_sources_source"`);
    await queryRunner.query(`DROP TABLE "author_name"`);
    await queryRunner.query(`DROP TABLE "author"`);
    await queryRunner.query(`DROP TABLE "work_author"`);
    await queryRunner.query(`DROP TABLE "work"`);
    await queryRunner.query(`DROP TABLE "work_name"`);
    await queryRunner.query(`DROP TABLE "work_character"`);
    await queryRunner.query(`DROP TABLE "world_character"`);
    await queryRunner.query(`DROP TABLE "world_character_name"`);
    await queryRunner.query(`DROP TABLE "world"`);
    await queryRunner.query(`DROP TABLE "world_name"`);
    await queryRunner.query(`DROP TABLE "work_character_name"`);
    await queryRunner.query(`DROP TABLE "character_tag"`);
    await queryRunner.query(`DROP TABLE "tag"`);
    await queryRunner.query(`DROP TABLE "work_tag"`);
    await queryRunner.query(`DROP TABLE "tag_name"`);
    await queryRunner.query(`DROP TABLE "interaction_tag"`);
    await queryRunner.query(`DROP TABLE "transformation"`);
    await queryRunner.query(`DROP TABLE "transformation_type"`);
    await queryRunner.query(`DROP TABLE "transformation_type_name"`);
    await queryRunner.query(`DROP TABLE "language"`);
    await queryRunner.query(`DROP TABLE "copy"`);
    await queryRunner.query(`DROP TABLE "source"`);
    await queryRunner.query(`DROP TABLE "site"`);
    await queryRunner.query(`DROP TABLE "site_name"`);
    await queryRunner.query(`DROP TABLE "collection_part"`);
    await queryRunner.query(`DROP TABLE "collection"`);
    await queryRunner.query(`DROP TABLE "collection_name"`);
    await queryRunner.query(`DROP TABLE "author_role"`);
    await queryRunner.query(`DROP TABLE "author_role_name"`);
  }
}
