feat: add indexable multi-name entities, add check constraints to rateable and multi-named entity mixin

BREAKING CHANGE: delete old migrations for a new initial_migration
This commit is contained in:
Xymorot 2019-11-24 16:35:01 +01:00
parent b73e14f0ab
commit 34bd46d376
14 changed files with 788 additions and 437 deletions

View File

@ -1,10 +1,10 @@
import { Entity, ManyToMany } from 'typeorm';
import { BaseEntity } from '../base-entity';
import { MultiNamed } from './base/multi-named';
import { MultiName, MultiNamed } from './base/multi-named';
import { Book } from './book';
@Entity()
export class Author extends MultiNamed(BaseEntity) {
export class Author extends MultiNamed(BaseEntity, 'AuthorMultiName') {
@ManyToMany(() => Book, {
nullable: false,
onDelete: 'CASCADE',
@ -12,3 +12,6 @@ export class Author extends MultiNamed(BaseEntity) {
})
public books: Promise<Book[]>;
}
@Entity()
export class AuthorMultiName extends MultiName('Author') {}

View File

@ -1,14 +1,47 @@
import { Column, Entity } from 'typeorm';
import { Check, Column, Entity, ManyToOne, OneToMany } from 'typeorm';
import { BaseEntity } from '../../base-entity';
export function MultiNamed<T extends Constructor>(BaseClass: T) {
export interface IMultiNamed {
nameCanonical: string;
multiNames: Promise<IMultiName[]>;
}
export interface IMultiName {
name: string;
multiNamed: Promise<IMultiNamed>;
}
export function MultiNamed<T extends Constructor>(BaseClass: T = null, multiNameClass: string): T {
@Entity()
class MixinClass extends BaseClass {
@Check(`LENGTH(nameCanonical) > 0`)
class MixinClass extends BaseClass implements IMultiNamed {
@Column()
public nameCanonical: string;
@Column('simple-array')
public names: string[];
@OneToMany(multiNameClass, (multiName: IMultiName) => multiName.multiNamed, {
onDelete: 'CASCADE',
onUpdate: 'CASCADE',
})
public multiNames: Promise<IMultiName[]>;
}
return MixinClass;
}
export function MultiName(multiNamedClass: string): Constructor {
@Entity()
@Check(`LENGTH(name) > 0`)
class MultiNameClass extends BaseEntity implements IMultiName {
@Column()
public name: string;
@ManyToOne(multiNamedClass, (multiNamed: IMultiNamed) => multiNamed.multiNames, {
nullable: false,
onDelete: 'CASCADE',
onUpdate: 'CASCADE',
})
public multiNamed: Promise<IMultiNamed>;
}
return MultiNameClass;
}

View File

@ -1,8 +1,16 @@
import { Column, Entity } from 'typeorm';
import { Check, Column, Entity } from 'typeorm';
export function Rateable<T extends Constructor>(BaseClass: T) {
export const minValue = 0;
export const maxValue = Number.MAX_SAFE_INTEGER;
export interface IRateable {
rating: number;
}
export function Rateable<T extends Constructor>(BaseClass: T = null): T {
@Entity()
class MixinClass extends BaseClass {
@Check(`rating >= ${minValue} AND rating <= ${maxValue}`)
class MixinClass extends BaseClass implements IRateable {
@Column({ nullable: true })
public rating: number;
}

View File

@ -1,6 +0,0 @@
{
"extends": ["../../../../../tslint.json"],
"rules": {
"typedef": false
}
}

View File

@ -1,7 +1,7 @@
import { Entity, JoinTable, ManyToMany, OneToMany } from 'typeorm';
import { BaseEntity } from '../base-entity';
import { Author } from './author';
import { MultiNamed } from './base/multi-named';
import { MultiName, MultiNamed } from './base/multi-named';
import { Rateable } from './base/rateable';
import { Character } from './character';
import { Copy } from './copy';
@ -9,7 +9,7 @@ import { Fiction } from './fiction';
import { Tag } from './tag';
@Entity()
export class Book extends Rateable(MultiNamed(BaseEntity)) {
export class Book extends Rateable(MultiNamed(BaseEntity, 'BookMultiName')) {
@OneToMany(
() => Copy,
(copy: Copy) => copy.original,
@ -53,3 +53,6 @@ export class Book extends Rateable(MultiNamed(BaseEntity)) {
@JoinTable()
public tags: Promise<Tag[]>;
}
@Entity()
export class BookMultiName extends MultiName('Book') {}

View File

@ -1,11 +1,11 @@
import { Entity, ManyToMany } from 'typeorm';
import { BaseEntity } from '../base-entity';
import { MultiNamed } from './base/multi-named';
import { MultiName, MultiNamed } from './base/multi-named';
import { Book } from './book';
import { Fiction } from './fiction';
@Entity()
export class Character extends MultiNamed(BaseEntity) {
export class Character extends MultiNamed(BaseEntity, 'CharacterMultiName') {
@ManyToMany(() => Book, {
nullable: false,
onDelete: 'CASCADE',
@ -20,3 +20,6 @@ export class Character extends MultiNamed(BaseEntity) {
})
public fictions: Promise<Fiction[]>;
}
@Entity()
export class CharacterMultiName extends MultiName('Character') {}

View File

@ -1,11 +1,11 @@
import { Entity, ManyToMany } from 'typeorm';
import { BaseEntity } from '../base-entity';
import { MultiNamed } from './base/multi-named';
import { MultiName, MultiNamed } from './base/multi-named';
import { Book } from './book';
import { Character } from './character';
@Entity()
export class Fiction extends MultiNamed(BaseEntity) {
export class Fiction extends MultiNamed(BaseEntity, 'FictionMultiName') {
@ManyToMany(() => Book, {
nullable: false,
onDelete: 'CASCADE',
@ -20,3 +20,6 @@ export class Fiction extends MultiNamed(BaseEntity) {
})
public characters: Promise<Character[]>;
}
@Entity()
export class FictionMultiName extends MultiName('Fiction') {}

View File

@ -1,10 +1,10 @@
import { Entity, OneToMany } from 'typeorm';
import { BaseEntity } from '../base-entity';
import { MultiNamed } from './base/multi-named';
import { MultiName, MultiNamed } from './base/multi-named';
import { Source } from './source';
@Entity()
export class Site extends MultiNamed(BaseEntity) {
export class Site extends MultiNamed(BaseEntity, 'SiteMultiName') {
@OneToMany(
() => Source,
(source: Source) => source.site,
@ -16,3 +16,6 @@ export class Site extends MultiNamed(BaseEntity) {
)
public sources: Promise<Source[]>;
}
@Entity()
export class SiteMultiName extends MultiName('Site') {}

View File

@ -1,10 +1,10 @@
import { Entity, ManyToMany } from 'typeorm';
import { BaseEntity } from '../base-entity';
import { MultiNamed } from './base/multi-named';
import { MultiName, MultiNamed } from './base/multi-named';
import { Book } from './book';
@Entity()
export class Tag extends MultiNamed(BaseEntity) {
export class Tag extends MultiNamed(BaseEntity, 'TagMultiName') {
@ManyToMany(() => Book, {
nullable: false,
onDelete: 'CASCADE',
@ -12,3 +12,6 @@ export class Tag extends MultiNamed(BaseEntity) {
})
public books: Promise<Book[]>;
}
@Entity()
export class TagMultiName extends MultiName('Tag') {}

View File

@ -1,10 +1,10 @@
import { Entity, ManyToMany } from 'typeorm';
import { BaseEntity } from '../base-entity';
import { MultiNamed } from './base/multi-named';
import { MultiName, MultiNamed } from './base/multi-named';
import { Copy } from './copy';
@Entity()
export class Translator extends MultiNamed(BaseEntity) {
export class Translator extends MultiNamed(BaseEntity, 'TranslatorMultiName') {
@ManyToMany(() => Copy, {
nullable: false,
onDelete: 'CASCADE',
@ -12,3 +12,6 @@ export class Translator extends MultiNamed(BaseEntity) {
})
public copies: Promise<Copy[]>;
}
@Entity()
export class TranslatorMultiName extends MultiName('Translator') {}

View File

@ -0,0 +1,6 @@
{
"extends": ["../../../tslint.json"],
"rules": {
"max-classes-per-file": false
}
}

View File

@ -1,358 +0,0 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
// tslint:disable-next-line: class-name
export class initialMigration1561296682728 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<any> {
await queryRunner.query(
`CREATE TABLE "fiction" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "nameCanonical" varchar NOT NULL, "names" text NOT NULL)`
);
await queryRunner.query(
`CREATE TABLE "character" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "nameCanonical" varchar NOT NULL, "names" text NOT NULL)`
);
await queryRunner.query(
`CREATE TABLE "copy_type" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "type" varchar NOT NULL, "comment" varchar, "copyId" integer NOT NULL)`
);
await queryRunner.query(
`CREATE TABLE "language" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "code" varchar NOT NULL, CONSTRAINT "UQ_465b3173cdddf0ac2d3fe73a33c" UNIQUE ("code"))`
);
await queryRunner.query(
`CREATE TABLE "site" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "nameCanonical" varchar NOT NULL, "names" text NOT NULL)`
);
await queryRunner.query(
`CREATE TABLE "source" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "uri" varchar NOT NULL, "siteId" integer NOT NULL, CONSTRAINT "UQ_028f4c3a05a9bfcddb95a4916b9" UNIQUE ("uri"))`
);
await queryRunner.query(
`CREATE TABLE "translator" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "nameCanonical" varchar NOT NULL, "names" text NOT NULL)`
);
await queryRunner.query(
`CREATE TABLE "copy" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "favorited" boolean NOT NULL DEFAULT (0), "isDigital" boolean NOT NULL, "originalId" integer NOT NULL)`
);
await queryRunner.query(
`CREATE TABLE "tag" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "nameCanonical" varchar NOT NULL, "names" text NOT NULL)`
);
await queryRunner.query(
`CREATE TABLE "book" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "nameCanonical" varchar NOT NULL, "names" text NOT NULL)`
);
await queryRunner.query(
`CREATE TABLE "author" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "nameCanonical" varchar NOT NULL, "names" text NOT NULL)`
);
await queryRunner.query(
`CREATE TABLE "intellectual_property" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "nameCanonical" varchar NOT NULL, "names" text 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 "copy_languages_language" ("copyId" integer NOT NULL, "languageId" integer NOT NULL, PRIMARY KEY ("copyId", "languageId"))`
);
await queryRunner.query(`CREATE INDEX "IDX_056de447bd9e4b2efdf5eafe49" ON "copy_languages_language" ("copyId") `);
await queryRunner.query(
`CREATE INDEX "IDX_c6adacfab107dc725d4fb5864b" ON "copy_languages_language" ("languageId") `
);
await queryRunner.query(
`CREATE TABLE "copy_translators_translator" ("copyId" integer NOT NULL, "translatorId" integer NOT NULL, PRIMARY KEY ("copyId", "translatorId"))`
);
await queryRunner.query(
`CREATE INDEX "IDX_2a20d8eaf28ebc28438271899f" ON "copy_translators_translator" ("copyId") `
);
await queryRunner.query(
`CREATE INDEX "IDX_e19e5193f168ce07f52f15be06" ON "copy_translators_translator" ("translatorId") `
);
await queryRunner.query(
`CREATE TABLE "book_authors_author" ("bookId" integer NOT NULL, "authorId" integer NOT NULL, PRIMARY KEY ("bookId", "authorId"))`
);
await queryRunner.query(`CREATE INDEX "IDX_9bf58ffb2a12a8609a738ee8ca" ON "book_authors_author" ("bookId") `);
await queryRunner.query(`CREATE INDEX "IDX_a4cafdf2ec9974524a5321c751" ON "book_authors_author" ("authorId") `);
await queryRunner.query(
`CREATE TABLE "book_fictions_fiction" ("bookId" integer NOT NULL, "fictionId" integer NOT NULL, PRIMARY KEY ("bookId", "fictionId"))`
);
await queryRunner.query(`CREATE INDEX "IDX_893dfbd84bd3a5a62e8a0758b3" ON "book_fictions_fiction" ("bookId") `);
await queryRunner.query(`CREATE INDEX "IDX_842bd3a8cb49dc7a92058b7f7a" ON "book_fictions_fiction" ("fictionId") `);
await queryRunner.query(
`CREATE TABLE "book_characters_character" ("bookId" integer NOT NULL, "characterId" integer NOT NULL, PRIMARY KEY ("bookId", "characterId"))`
);
await queryRunner.query(`CREATE INDEX "IDX_261dcea7cb50a485906440f91f" ON "book_characters_character" ("bookId") `);
await queryRunner.query(
`CREATE INDEX "IDX_51615a52cc3ef773766afbcc43" ON "book_characters_character" ("characterId") `
);
await queryRunner.query(
`CREATE TABLE "book_tags_tag" ("bookId" integer NOT NULL, "tagId" integer NOT NULL, PRIMARY KEY ("bookId", "tagId"))`
);
await queryRunner.query(`CREATE INDEX "IDX_918a7b7552fe5fd66f328d4fe8" ON "book_tags_tag" ("bookId") `);
await queryRunner.query(`CREATE INDEX "IDX_5274aca0a1468ed55afdfaba24" ON "book_tags_tag" ("tagId") `);
await queryRunner.query(
`CREATE TABLE "temporary_copy_type" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "type" varchar NOT NULL, "comment" varchar, "copyId" integer NOT NULL, CONSTRAINT "FK_156b15213d57b5dbbbc33e94050" FOREIGN KEY ("copyId") REFERENCES "copy" ("id") ON DELETE CASCADE ON UPDATE CASCADE)`
);
await queryRunner.query(
`INSERT INTO "temporary_copy_type"("id", "type", "comment", "copyId") SELECT "id", "type", "comment", "copyId" FROM "copy_type"`
);
await queryRunner.query(`DROP TABLE "copy_type"`);
await queryRunner.query(`ALTER TABLE "temporary_copy_type" RENAME TO "copy_type"`);
await queryRunner.query(
`CREATE TABLE "temporary_source" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "uri" varchar NOT NULL, "siteId" integer NOT NULL, CONSTRAINT "UQ_028f4c3a05a9bfcddb95a4916b9" UNIQUE ("uri"), CONSTRAINT "FK_73b253e679f350d140bdb104e49" FOREIGN KEY ("siteId") REFERENCES "site" ("id") ON DELETE CASCADE 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, "favorited" boolean NOT NULL DEFAULT (0), "isDigital" boolean NOT NULL, "originalId" integer NOT NULL, CONSTRAINT "FK_e8ce0011cf0a8b9fdc8ad908a44" FOREIGN KEY ("originalId") REFERENCES "book" ("id") ON DELETE CASCADE ON UPDATE CASCADE)`
);
await queryRunner.query(
`INSERT INTO "temporary_copy"("id", "favorited", "isDigital", "originalId") SELECT "id", "favorited", "isDigital", "originalId" FROM "copy"`
);
await queryRunner.query(`DROP TABLE "copy"`);
await queryRunner.query(`ALTER TABLE "temporary_copy" RENAME TO "copy"`);
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_056de447bd9e4b2efdf5eafe49"`);
await queryRunner.query(`DROP INDEX "IDX_c6adacfab107dc725d4fb5864b"`);
await queryRunner.query(
`CREATE TABLE "temporary_copy_languages_language" ("copyId" integer NOT NULL, "languageId" integer NOT NULL, CONSTRAINT "FK_056de447bd9e4b2efdf5eafe497" FOREIGN KEY ("copyId") REFERENCES "copy" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, CONSTRAINT "FK_c6adacfab107dc725d4fb5864be" FOREIGN KEY ("languageId") REFERENCES "language" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, PRIMARY KEY ("copyId", "languageId"))`
);
await queryRunner.query(
`INSERT INTO "temporary_copy_languages_language"("copyId", "languageId") SELECT "copyId", "languageId" FROM "copy_languages_language"`
);
await queryRunner.query(`DROP TABLE "copy_languages_language"`);
await queryRunner.query(`ALTER TABLE "temporary_copy_languages_language" RENAME TO "copy_languages_language"`);
await queryRunner.query(`CREATE INDEX "IDX_056de447bd9e4b2efdf5eafe49" ON "copy_languages_language" ("copyId") `);
await queryRunner.query(
`CREATE INDEX "IDX_c6adacfab107dc725d4fb5864b" ON "copy_languages_language" ("languageId") `
);
await queryRunner.query(`DROP INDEX "IDX_2a20d8eaf28ebc28438271899f"`);
await queryRunner.query(`DROP INDEX "IDX_e19e5193f168ce07f52f15be06"`);
await queryRunner.query(
`CREATE TABLE "temporary_copy_translators_translator" ("copyId" integer NOT NULL, "translatorId" integer NOT NULL, CONSTRAINT "FK_2a20d8eaf28ebc28438271899f5" FOREIGN KEY ("copyId") REFERENCES "copy" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, CONSTRAINT "FK_e19e5193f168ce07f52f15be068" FOREIGN KEY ("translatorId") REFERENCES "translator" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, PRIMARY KEY ("copyId", "translatorId"))`
);
await queryRunner.query(
`INSERT INTO "temporary_copy_translators_translator"("copyId", "translatorId") SELECT "copyId", "translatorId" FROM "copy_translators_translator"`
);
await queryRunner.query(`DROP TABLE "copy_translators_translator"`);
await queryRunner.query(
`ALTER TABLE "temporary_copy_translators_translator" RENAME TO "copy_translators_translator"`
);
await queryRunner.query(
`CREATE INDEX "IDX_2a20d8eaf28ebc28438271899f" ON "copy_translators_translator" ("copyId") `
);
await queryRunner.query(
`CREATE INDEX "IDX_e19e5193f168ce07f52f15be06" ON "copy_translators_translator" ("translatorId") `
);
await queryRunner.query(`DROP INDEX "IDX_9bf58ffb2a12a8609a738ee8ca"`);
await queryRunner.query(`DROP INDEX "IDX_a4cafdf2ec9974524a5321c751"`);
await queryRunner.query(
`CREATE TABLE "temporary_book_authors_author" ("bookId" integer NOT NULL, "authorId" integer NOT NULL, CONSTRAINT "FK_9bf58ffb2a12a8609a738ee8cae" FOREIGN KEY ("bookId") REFERENCES "book" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, CONSTRAINT "FK_a4cafdf2ec9974524a5321c7516" FOREIGN KEY ("authorId") REFERENCES "author" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, PRIMARY KEY ("bookId", "authorId"))`
);
await queryRunner.query(
`INSERT INTO "temporary_book_authors_author"("bookId", "authorId") SELECT "bookId", "authorId" FROM "book_authors_author"`
);
await queryRunner.query(`DROP TABLE "book_authors_author"`);
await queryRunner.query(`ALTER TABLE "temporary_book_authors_author" RENAME TO "book_authors_author"`);
await queryRunner.query(`CREATE INDEX "IDX_9bf58ffb2a12a8609a738ee8ca" ON "book_authors_author" ("bookId") `);
await queryRunner.query(`CREATE INDEX "IDX_a4cafdf2ec9974524a5321c751" ON "book_authors_author" ("authorId") `);
await queryRunner.query(`DROP INDEX "IDX_893dfbd84bd3a5a62e8a0758b3"`);
await queryRunner.query(`DROP INDEX "IDX_842bd3a8cb49dc7a92058b7f7a"`);
await queryRunner.query(
`CREATE TABLE "temporary_book_fictions_fiction" ("bookId" integer NOT NULL, "fictionId" integer NOT NULL, CONSTRAINT "FK_893dfbd84bd3a5a62e8a0758b3f" FOREIGN KEY ("bookId") REFERENCES "book" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, CONSTRAINT "FK_842bd3a8cb49dc7a92058b7f7aa" FOREIGN KEY ("fictionId") REFERENCES "fiction" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, PRIMARY KEY ("bookId", "fictionId"))`
);
await queryRunner.query(
`INSERT INTO "temporary_book_fictions_fiction"("bookId", "fictionId") SELECT "bookId", "fictionId" FROM "book_fictions_fiction"`
);
await queryRunner.query(`DROP TABLE "book_fictions_fiction"`);
await queryRunner.query(`ALTER TABLE "temporary_book_fictions_fiction" RENAME TO "book_fictions_fiction"`);
await queryRunner.query(`CREATE INDEX "IDX_893dfbd84bd3a5a62e8a0758b3" ON "book_fictions_fiction" ("bookId") `);
await queryRunner.query(`CREATE INDEX "IDX_842bd3a8cb49dc7a92058b7f7a" ON "book_fictions_fiction" ("fictionId") `);
await queryRunner.query(`DROP INDEX "IDX_261dcea7cb50a485906440f91f"`);
await queryRunner.query(`DROP INDEX "IDX_51615a52cc3ef773766afbcc43"`);
await queryRunner.query(
`CREATE TABLE "temporary_book_characters_character" ("bookId" integer NOT NULL, "characterId" integer NOT NULL, CONSTRAINT "FK_261dcea7cb50a485906440f91f8" FOREIGN KEY ("bookId") REFERENCES "book" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, CONSTRAINT "FK_51615a52cc3ef773766afbcc433" FOREIGN KEY ("characterId") REFERENCES "character" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, PRIMARY KEY ("bookId", "characterId"))`
);
await queryRunner.query(
`INSERT INTO "temporary_book_characters_character"("bookId", "characterId") SELECT "bookId", "characterId" FROM "book_characters_character"`
);
await queryRunner.query(`DROP TABLE "book_characters_character"`);
await queryRunner.query(`ALTER TABLE "temporary_book_characters_character" RENAME TO "book_characters_character"`);
await queryRunner.query(`CREATE INDEX "IDX_261dcea7cb50a485906440f91f" ON "book_characters_character" ("bookId") `);
await queryRunner.query(
`CREATE INDEX "IDX_51615a52cc3ef773766afbcc43" ON "book_characters_character" ("characterId") `
);
await queryRunner.query(`DROP INDEX "IDX_918a7b7552fe5fd66f328d4fe8"`);
await queryRunner.query(`DROP INDEX "IDX_5274aca0a1468ed55afdfaba24"`);
await queryRunner.query(
`CREATE TABLE "temporary_book_tags_tag" ("bookId" integer NOT NULL, "tagId" integer NOT NULL, CONSTRAINT "FK_918a7b7552fe5fd66f328d4fe84" FOREIGN KEY ("bookId") REFERENCES "book" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, CONSTRAINT "FK_5274aca0a1468ed55afdfaba244" FOREIGN KEY ("tagId") REFERENCES "tag" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, PRIMARY KEY ("bookId", "tagId"))`
);
await queryRunner.query(
`INSERT INTO "temporary_book_tags_tag"("bookId", "tagId") SELECT "bookId", "tagId" FROM "book_tags_tag"`
);
await queryRunner.query(`DROP TABLE "book_tags_tag"`);
await queryRunner.query(`ALTER TABLE "temporary_book_tags_tag" RENAME TO "book_tags_tag"`);
await queryRunner.query(`CREATE INDEX "IDX_918a7b7552fe5fd66f328d4fe8" ON "book_tags_tag" ("bookId") `);
await queryRunner.query(`CREATE INDEX "IDX_5274aca0a1468ed55afdfaba24" ON "book_tags_tag" ("tagId") `);
}
public async down(queryRunner: QueryRunner): Promise<any> {
await queryRunner.query(`DROP INDEX "IDX_5274aca0a1468ed55afdfaba24"`);
await queryRunner.query(`DROP INDEX "IDX_918a7b7552fe5fd66f328d4fe8"`);
await queryRunner.query(`ALTER TABLE "book_tags_tag" RENAME TO "temporary_book_tags_tag"`);
await queryRunner.query(
`CREATE TABLE "book_tags_tag" ("bookId" integer NOT NULL, "tagId" integer NOT NULL, PRIMARY KEY ("bookId", "tagId"))`
);
await queryRunner.query(
`INSERT INTO "book_tags_tag"("bookId", "tagId") SELECT "bookId", "tagId" FROM "temporary_book_tags_tag"`
);
await queryRunner.query(`DROP TABLE "temporary_book_tags_tag"`);
await queryRunner.query(`CREATE INDEX "IDX_5274aca0a1468ed55afdfaba24" ON "book_tags_tag" ("tagId") `);
await queryRunner.query(`CREATE INDEX "IDX_918a7b7552fe5fd66f328d4fe8" ON "book_tags_tag" ("bookId") `);
await queryRunner.query(`DROP INDEX "IDX_51615a52cc3ef773766afbcc43"`);
await queryRunner.query(`DROP INDEX "IDX_261dcea7cb50a485906440f91f"`);
await queryRunner.query(`ALTER TABLE "book_characters_character" RENAME TO "temporary_book_characters_character"`);
await queryRunner.query(
`CREATE TABLE "book_characters_character" ("bookId" integer NOT NULL, "characterId" integer NOT NULL, PRIMARY KEY ("bookId", "characterId"))`
);
await queryRunner.query(
`INSERT INTO "book_characters_character"("bookId", "characterId") SELECT "bookId", "characterId" FROM "temporary_book_characters_character"`
);
await queryRunner.query(`DROP TABLE "temporary_book_characters_character"`);
await queryRunner.query(
`CREATE INDEX "IDX_51615a52cc3ef773766afbcc43" ON "book_characters_character" ("characterId") `
);
await queryRunner.query(`CREATE INDEX "IDX_261dcea7cb50a485906440f91f" ON "book_characters_character" ("bookId") `);
await queryRunner.query(`DROP INDEX "IDX_842bd3a8cb49dc7a92058b7f7a"`);
await queryRunner.query(`DROP INDEX "IDX_893dfbd84bd3a5a62e8a0758b3"`);
await queryRunner.query(`ALTER TABLE "book_fictions_fiction" RENAME TO "temporary_book_fictions_fiction"`);
await queryRunner.query(
`CREATE TABLE "book_fictions_fiction" ("bookId" integer NOT NULL, "fictionId" integer NOT NULL, PRIMARY KEY ("bookId", "fictionId"))`
);
await queryRunner.query(
`INSERT INTO "book_fictions_fiction"("bookId", "fictionId") SELECT "bookId", "fictionId" FROM "temporary_book_fictions_fiction"`
);
await queryRunner.query(`DROP TABLE "temporary_book_fictions_fiction"`);
await queryRunner.query(`CREATE INDEX "IDX_842bd3a8cb49dc7a92058b7f7a" ON "book_fictions_fiction" ("fictionId") `);
await queryRunner.query(`CREATE INDEX "IDX_893dfbd84bd3a5a62e8a0758b3" ON "book_fictions_fiction" ("bookId") `);
await queryRunner.query(`DROP INDEX "IDX_a4cafdf2ec9974524a5321c751"`);
await queryRunner.query(`DROP INDEX "IDX_9bf58ffb2a12a8609a738ee8ca"`);
await queryRunner.query(`ALTER TABLE "book_authors_author" RENAME TO "temporary_book_authors_author"`);
await queryRunner.query(
`CREATE TABLE "book_authors_author" ("bookId" integer NOT NULL, "authorId" integer NOT NULL, PRIMARY KEY ("bookId", "authorId"))`
);
await queryRunner.query(
`INSERT INTO "book_authors_author"("bookId", "authorId") SELECT "bookId", "authorId" FROM "temporary_book_authors_author"`
);
await queryRunner.query(`DROP TABLE "temporary_book_authors_author"`);
await queryRunner.query(`CREATE INDEX "IDX_a4cafdf2ec9974524a5321c751" ON "book_authors_author" ("authorId") `);
await queryRunner.query(`CREATE INDEX "IDX_9bf58ffb2a12a8609a738ee8ca" ON "book_authors_author" ("bookId") `);
await queryRunner.query(`DROP INDEX "IDX_e19e5193f168ce07f52f15be06"`);
await queryRunner.query(`DROP INDEX "IDX_2a20d8eaf28ebc28438271899f"`);
await queryRunner.query(
`ALTER TABLE "copy_translators_translator" RENAME TO "temporary_copy_translators_translator"`
);
await queryRunner.query(
`CREATE TABLE "copy_translators_translator" ("copyId" integer NOT NULL, "translatorId" integer NOT NULL, PRIMARY KEY ("copyId", "translatorId"))`
);
await queryRunner.query(
`INSERT INTO "copy_translators_translator"("copyId", "translatorId") SELECT "copyId", "translatorId" FROM "temporary_copy_translators_translator"`
);
await queryRunner.query(`DROP TABLE "temporary_copy_translators_translator"`);
await queryRunner.query(
`CREATE INDEX "IDX_e19e5193f168ce07f52f15be06" ON "copy_translators_translator" ("translatorId") `
);
await queryRunner.query(
`CREATE INDEX "IDX_2a20d8eaf28ebc28438271899f" ON "copy_translators_translator" ("copyId") `
);
await queryRunner.query(`DROP INDEX "IDX_c6adacfab107dc725d4fb5864b"`);
await queryRunner.query(`DROP INDEX "IDX_056de447bd9e4b2efdf5eafe49"`);
await queryRunner.query(`ALTER TABLE "copy_languages_language" RENAME TO "temporary_copy_languages_language"`);
await queryRunner.query(
`CREATE TABLE "copy_languages_language" ("copyId" integer NOT NULL, "languageId" integer NOT NULL, PRIMARY KEY ("copyId", "languageId"))`
);
await queryRunner.query(
`INSERT INTO "copy_languages_language"("copyId", "languageId") SELECT "copyId", "languageId" FROM "temporary_copy_languages_language"`
);
await queryRunner.query(`DROP TABLE "temporary_copy_languages_language"`);
await queryRunner.query(
`CREATE INDEX "IDX_c6adacfab107dc725d4fb5864b" ON "copy_languages_language" ("languageId") `
);
await queryRunner.query(`CREATE INDEX "IDX_056de447bd9e4b2efdf5eafe49" ON "copy_languages_language" ("copyId") `);
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 "copy" RENAME TO "temporary_copy"`);
await queryRunner.query(
`CREATE TABLE "copy" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "favorited" boolean NOT NULL DEFAULT (0), "isDigital" boolean NOT NULL, "originalId" integer NOT NULL)`
);
await queryRunner.query(
`INSERT INTO "copy"("id", "favorited", "isDigital", "originalId") SELECT "id", "favorited", "isDigital", "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, "siteId" integer NOT NULL, CONSTRAINT "UQ_028f4c3a05a9bfcddb95a4916b9" UNIQUE ("uri"))`
);
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 "copy_type" RENAME TO "temporary_copy_type"`);
await queryRunner.query(
`CREATE TABLE "copy_type" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "type" varchar NOT NULL, "comment" varchar, "copyId" integer NOT NULL)`
);
await queryRunner.query(
`INSERT INTO "copy_type"("id", "type", "comment", "copyId") SELECT "id", "type", "comment", "copyId" FROM "temporary_copy_type"`
);
await queryRunner.query(`DROP TABLE "temporary_copy_type"`);
await queryRunner.query(`DROP INDEX "IDX_5274aca0a1468ed55afdfaba24"`);
await queryRunner.query(`DROP INDEX "IDX_918a7b7552fe5fd66f328d4fe8"`);
await queryRunner.query(`DROP TABLE "book_tags_tag"`);
await queryRunner.query(`DROP INDEX "IDX_51615a52cc3ef773766afbcc43"`);
await queryRunner.query(`DROP INDEX "IDX_261dcea7cb50a485906440f91f"`);
await queryRunner.query(`DROP TABLE "book_characters_character"`);
await queryRunner.query(`DROP INDEX "IDX_842bd3a8cb49dc7a92058b7f7a"`);
await queryRunner.query(`DROP INDEX "IDX_893dfbd84bd3a5a62e8a0758b3"`);
await queryRunner.query(`DROP TABLE "book_fictions_fiction"`);
await queryRunner.query(`DROP INDEX "IDX_a4cafdf2ec9974524a5321c751"`);
await queryRunner.query(`DROP INDEX "IDX_9bf58ffb2a12a8609a738ee8ca"`);
await queryRunner.query(`DROP TABLE "book_authors_author"`);
await queryRunner.query(`DROP INDEX "IDX_e19e5193f168ce07f52f15be06"`);
await queryRunner.query(`DROP INDEX "IDX_2a20d8eaf28ebc28438271899f"`);
await queryRunner.query(`DROP TABLE "copy_translators_translator"`);
await queryRunner.query(`DROP INDEX "IDX_c6adacfab107dc725d4fb5864b"`);
await queryRunner.query(`DROP INDEX "IDX_056de447bd9e4b2efdf5eafe49"`);
await queryRunner.query(`DROP TABLE "copy_languages_language"`);
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 "intellectual_property"`);
await queryRunner.query(`DROP TABLE "author"`);
await queryRunner.query(`DROP TABLE "book"`);
await queryRunner.query(`DROP TABLE "tag"`);
await queryRunner.query(`DROP TABLE "copy"`);
await queryRunner.query(`DROP TABLE "translator"`);
await queryRunner.query(`DROP TABLE "source"`);
await queryRunner.query(`DROP TABLE "site"`);
await queryRunner.query(`DROP TABLE "language"`);
await queryRunner.query(`DROP TABLE "copy_type"`);
await queryRunner.query(`DROP TABLE "character"`);
await queryRunner.query(`DROP TABLE "fiction"`);
}
}

View File

@ -1,51 +0,0 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class addRating1574452206367 implements MigrationInterface {
name = 'addRating1574452206367';
public async up(queryRunner: QueryRunner): Promise<any> {
await queryRunner.query(
`CREATE TABLE "temporary_copy" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "favorited" boolean NOT NULL DEFAULT (0), "isDigital" boolean NOT NULL, "originalId" integer NOT NULL, "rating" integer, CONSTRAINT "FK_e8ce0011cf0a8b9fdc8ad908a44" FOREIGN KEY ("originalId") REFERENCES "book" ("id") ON DELETE CASCADE ON UPDATE CASCADE)`,
undefined
);
await queryRunner.query(
`INSERT INTO "temporary_copy"("id", "favorited", "isDigital", "originalId") SELECT "id", "favorited", "isDigital", "originalId" FROM "copy"`,
undefined
);
await queryRunner.query(`DROP TABLE "copy"`, undefined);
await queryRunner.query(`ALTER TABLE "temporary_copy" RENAME TO "copy"`, undefined);
await queryRunner.query(
`CREATE TABLE "temporary_book" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "nameCanonical" varchar NOT NULL, "names" text NOT NULL, "rating" integer)`,
undefined
);
await queryRunner.query(
`INSERT INTO "temporary_book"("id", "nameCanonical", "names") SELECT "id", "nameCanonical", "names" FROM "book"`,
undefined
);
await queryRunner.query(`DROP TABLE "book"`, undefined);
await queryRunner.query(`ALTER TABLE "temporary_book" RENAME TO "book"`, undefined);
}
public async down(queryRunner: QueryRunner): Promise<any> {
await queryRunner.query(`ALTER TABLE "book" RENAME TO "temporary_book"`, undefined);
await queryRunner.query(
`CREATE TABLE "book" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "nameCanonical" varchar NOT NULL, "names" text NOT NULL)`,
undefined
);
await queryRunner.query(
`INSERT INTO "book"("id", "nameCanonical", "names") SELECT "id", "nameCanonical", "names" FROM "temporary_book"`,
undefined
);
await queryRunner.query(`DROP TABLE "temporary_book"`, undefined);
await queryRunner.query(`ALTER TABLE "copy" RENAME TO "temporary_copy"`, undefined);
await queryRunner.query(
`CREATE TABLE "copy" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "favorited" boolean NOT NULL DEFAULT (0), "isDigital" boolean NOT NULL, "originalId" integer NOT NULL, CONSTRAINT "FK_e8ce0011cf0a8b9fdc8ad908a44" FOREIGN KEY ("originalId") REFERENCES "book" ("id") ON DELETE CASCADE ON UPDATE CASCADE)`,
undefined
);
await queryRunner.query(
`INSERT INTO "copy"("id", "favorited", "isDigital", "originalId") SELECT "id", "favorited", "isDigital", "originalId" FROM "temporary_copy"`,
undefined
);
await queryRunner.query(`DROP TABLE "temporary_copy"`, undefined);
}
}

View File

@ -0,0 +1,698 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class initialMigration1574609063879 implements MigrationInterface {
name = 'initialMigration1574609063879';
public async up(queryRunner: QueryRunner): Promise<any> {
await queryRunner.query(
`CREATE TABLE "fiction" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "nameCanonical" varchar NOT NULL, CONSTRAINT "CHK_ece48040a8ab27691c59392255" CHECK (LENGTH(nameCanonical) > 0))`,
undefined
);
await queryRunner.query(
`CREATE TABLE "fiction_multi_name" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL, "multiNamedId" integer NOT NULL, CONSTRAINT "CHK_39f907c54d00784d2468156af2" CHECK (LENGTH(name) > 0))`,
undefined
);
await queryRunner.query(
`CREATE TABLE "character" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "nameCanonical" varchar NOT NULL, CONSTRAINT "CHK_2c5dc413ea252434cf75507f97" CHECK (LENGTH(nameCanonical) > 0))`,
undefined
);
await queryRunner.query(
`CREATE TABLE "character_multi_name" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL, "multiNamedId" integer NOT NULL, CONSTRAINT "CHK_8f6325928e3a0cc9b78b52f6dc" CHECK (LENGTH(name) > 0))`,
undefined
);
await queryRunner.query(
`CREATE TABLE "copy_type" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "type" varchar NOT NULL, "comment" varchar, "copyId" integer NOT NULL)`,
undefined
);
await queryRunner.query(
`CREATE TABLE "language" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "code" varchar NOT NULL, CONSTRAINT "UQ_465b3173cdddf0ac2d3fe73a33c" UNIQUE ("code"))`,
undefined
);
await queryRunner.query(
`CREATE TABLE "site" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "nameCanonical" varchar NOT NULL, CONSTRAINT "CHK_2e45adb601d323481a26a5d747" CHECK (LENGTH(nameCanonical) > 0))`,
undefined
);
await queryRunner.query(
`CREATE TABLE "site_multi_name" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL, "multiNamedId" integer NOT NULL, CONSTRAINT "CHK_8dc8533fce07e041aa8474da05" CHECK (LENGTH(name) > 0))`,
undefined
);
await queryRunner.query(
`CREATE TABLE "source" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "uri" varchar NOT NULL, "siteId" integer NOT NULL, CONSTRAINT "UQ_028f4c3a05a9bfcddb95a4916b9" UNIQUE ("uri"))`,
undefined
);
await queryRunner.query(
`CREATE TABLE "translator" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "nameCanonical" varchar NOT NULL, CONSTRAINT "CHK_4889d3449c1587168e8dcea2ec" CHECK (LENGTH(nameCanonical) > 0))`,
undefined
);
await queryRunner.query(
`CREATE TABLE "translator_multi_name" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL, "multiNamedId" integer NOT NULL, CONSTRAINT "CHK_0652150dacaf6454a4cd6811de" CHECK (LENGTH(name) > 0))`,
undefined
);
await queryRunner.query(
`CREATE TABLE "copy" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "rating" integer, "favorited" boolean NOT NULL DEFAULT (0), "isDigital" boolean NOT NULL, "originalId" integer NOT NULL, CONSTRAINT "CHK_f6e0d7b6b3e80ad96e2a1dda43" CHECK (rating >= 0 AND rating <= 9007199254740991))`,
undefined
);
await queryRunner.query(
`CREATE TABLE "tag" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "nameCanonical" varchar NOT NULL, CONSTRAINT "CHK_572e2fc78872b516f62ff02a88" CHECK (LENGTH(nameCanonical) > 0))`,
undefined
);
await queryRunner.query(
`CREATE TABLE "tag_multi_name" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL, "multiNamedId" integer NOT NULL, CONSTRAINT "CHK_ab521dd46cf7699c4abf75b76b" CHECK (LENGTH(name) > 0))`,
undefined
);
await queryRunner.query(
`CREATE TABLE "book" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "nameCanonical" varchar NOT NULL, "rating" integer, CONSTRAINT "CHK_bbef8dbd3571ec559f7a980fc5" CHECK (LENGTH(nameCanonical) > 0), CONSTRAINT "CHK_62ebe0be1f2d31406118960aa5" CHECK (rating >= 0 AND rating <= 9007199254740991))`,
undefined
);
await queryRunner.query(
`CREATE TABLE "book_multi_name" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL, "multiNamedId" integer NOT NULL, CONSTRAINT "CHK_f989db6a159c4614d635ad6ad5" CHECK (LENGTH(name) > 0))`,
undefined
);
await queryRunner.query(
`CREATE TABLE "author" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "nameCanonical" varchar NOT NULL, CONSTRAINT "CHK_6fb4af6989bffdf1b04f3724a4" CHECK (LENGTH(nameCanonical) > 0))`,
undefined
);
await queryRunner.query(
`CREATE TABLE "author_multi_name" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL, "multiNamedId" integer NOT NULL, CONSTRAINT "CHK_4d153aa4b33f8254933d224fe0" CHECK (LENGTH(name) > 0))`,
undefined
);
await queryRunner.query(
`CREATE TABLE "copy_sources_source" ("copyId" integer NOT NULL, "sourceId" integer NOT NULL, PRIMARY KEY ("copyId", "sourceId"))`,
undefined
);
await queryRunner.query(
`CREATE INDEX "IDX_653c33c5db26b8736e592ff3f6" ON "copy_sources_source" ("copyId") `,
undefined
);
await queryRunner.query(
`CREATE INDEX "IDX_946af3644f779b7cc7e7eb04eb" ON "copy_sources_source" ("sourceId") `,
undefined
);
await queryRunner.query(
`CREATE TABLE "copy_languages_language" ("copyId" integer NOT NULL, "languageId" integer NOT NULL, PRIMARY KEY ("copyId", "languageId"))`,
undefined
);
await queryRunner.query(
`CREATE INDEX "IDX_056de447bd9e4b2efdf5eafe49" ON "copy_languages_language" ("copyId") `,
undefined
);
await queryRunner.query(
`CREATE INDEX "IDX_c6adacfab107dc725d4fb5864b" ON "copy_languages_language" ("languageId") `,
undefined
);
await queryRunner.query(
`CREATE TABLE "copy_translators_translator" ("copyId" integer NOT NULL, "translatorId" integer NOT NULL, PRIMARY KEY ("copyId", "translatorId"))`,
undefined
);
await queryRunner.query(
`CREATE INDEX "IDX_2a20d8eaf28ebc28438271899f" ON "copy_translators_translator" ("copyId") `,
undefined
);
await queryRunner.query(
`CREATE INDEX "IDX_e19e5193f168ce07f52f15be06" ON "copy_translators_translator" ("translatorId") `,
undefined
);
await queryRunner.query(
`CREATE TABLE "book_authors_author" ("bookId" integer NOT NULL, "authorId" integer NOT NULL, PRIMARY KEY ("bookId", "authorId"))`,
undefined
);
await queryRunner.query(
`CREATE INDEX "IDX_9bf58ffb2a12a8609a738ee8ca" ON "book_authors_author" ("bookId") `,
undefined
);
await queryRunner.query(
`CREATE INDEX "IDX_a4cafdf2ec9974524a5321c751" ON "book_authors_author" ("authorId") `,
undefined
);
await queryRunner.query(
`CREATE TABLE "book_fictions_fiction" ("bookId" integer NOT NULL, "fictionId" integer NOT NULL, PRIMARY KEY ("bookId", "fictionId"))`,
undefined
);
await queryRunner.query(
`CREATE INDEX "IDX_893dfbd84bd3a5a62e8a0758b3" ON "book_fictions_fiction" ("bookId") `,
undefined
);
await queryRunner.query(
`CREATE INDEX "IDX_842bd3a8cb49dc7a92058b7f7a" ON "book_fictions_fiction" ("fictionId") `,
undefined
);
await queryRunner.query(
`CREATE TABLE "book_characters_character" ("bookId" integer NOT NULL, "characterId" integer NOT NULL, PRIMARY KEY ("bookId", "characterId"))`,
undefined
);
await queryRunner.query(
`CREATE INDEX "IDX_261dcea7cb50a485906440f91f" ON "book_characters_character" ("bookId") `,
undefined
);
await queryRunner.query(
`CREATE INDEX "IDX_51615a52cc3ef773766afbcc43" ON "book_characters_character" ("characterId") `,
undefined
);
await queryRunner.query(
`CREATE TABLE "book_tags_tag" ("bookId" integer NOT NULL, "tagId" integer NOT NULL, PRIMARY KEY ("bookId", "tagId"))`,
undefined
);
await queryRunner.query(`CREATE INDEX "IDX_918a7b7552fe5fd66f328d4fe8" ON "book_tags_tag" ("bookId") `, undefined);
await queryRunner.query(`CREATE INDEX "IDX_5274aca0a1468ed55afdfaba24" ON "book_tags_tag" ("tagId") `, undefined);
await queryRunner.query(
`CREATE TABLE "temporary_fiction_multi_name" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL, "multiNamedId" integer NOT NULL, CONSTRAINT "CHK_39f907c54d00784d2468156af2" CHECK (LENGTH(name) > 0), CONSTRAINT "FK_c95f6982a15bf8adc487e554d9d" FOREIGN KEY ("multiNamedId") REFERENCES "fiction" ("id") ON DELETE CASCADE ON UPDATE CASCADE)`,
undefined
);
await queryRunner.query(
`INSERT INTO "temporary_fiction_multi_name"("id", "name", "multiNamedId") SELECT "id", "name", "multiNamedId" FROM "fiction_multi_name"`,
undefined
);
await queryRunner.query(`DROP TABLE "fiction_multi_name"`, undefined);
await queryRunner.query(`ALTER TABLE "temporary_fiction_multi_name" RENAME TO "fiction_multi_name"`, undefined);
await queryRunner.query(
`CREATE TABLE "temporary_character_multi_name" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL, "multiNamedId" integer NOT NULL, CONSTRAINT "CHK_8f6325928e3a0cc9b78b52f6dc" CHECK (LENGTH(name) > 0), CONSTRAINT "FK_85051dd2e242ae03efab36fba2d" FOREIGN KEY ("multiNamedId") REFERENCES "character" ("id") ON DELETE CASCADE ON UPDATE CASCADE)`,
undefined
);
await queryRunner.query(
`INSERT INTO "temporary_character_multi_name"("id", "name", "multiNamedId") SELECT "id", "name", "multiNamedId" FROM "character_multi_name"`,
undefined
);
await queryRunner.query(`DROP TABLE "character_multi_name"`, undefined);
await queryRunner.query(`ALTER TABLE "temporary_character_multi_name" RENAME TO "character_multi_name"`, undefined);
await queryRunner.query(
`CREATE TABLE "temporary_copy_type" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "type" varchar NOT NULL, "comment" varchar, "copyId" integer NOT NULL, CONSTRAINT "FK_156b15213d57b5dbbbc33e94050" FOREIGN KEY ("copyId") REFERENCES "copy" ("id") ON DELETE CASCADE ON UPDATE CASCADE)`,
undefined
);
await queryRunner.query(
`INSERT INTO "temporary_copy_type"("id", "type", "comment", "copyId") SELECT "id", "type", "comment", "copyId" FROM "copy_type"`,
undefined
);
await queryRunner.query(`DROP TABLE "copy_type"`, undefined);
await queryRunner.query(`ALTER TABLE "temporary_copy_type" RENAME TO "copy_type"`, undefined);
await queryRunner.query(
`CREATE TABLE "temporary_site_multi_name" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL, "multiNamedId" integer NOT NULL, CONSTRAINT "CHK_8dc8533fce07e041aa8474da05" CHECK (LENGTH(name) > 0), CONSTRAINT "FK_d5ebcbd5364c68cad5d1d517b6a" FOREIGN KEY ("multiNamedId") REFERENCES "site" ("id") ON DELETE CASCADE ON UPDATE CASCADE)`,
undefined
);
await queryRunner.query(
`INSERT INTO "temporary_site_multi_name"("id", "name", "multiNamedId") SELECT "id", "name", "multiNamedId" FROM "site_multi_name"`,
undefined
);
await queryRunner.query(`DROP TABLE "site_multi_name"`, undefined);
await queryRunner.query(`ALTER TABLE "temporary_site_multi_name" RENAME TO "site_multi_name"`, undefined);
await queryRunner.query(
`CREATE TABLE "temporary_source" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "uri" varchar NOT NULL, "siteId" integer NOT NULL, CONSTRAINT "UQ_028f4c3a05a9bfcddb95a4916b9" UNIQUE ("uri"), CONSTRAINT "FK_73b253e679f350d140bdb104e49" FOREIGN KEY ("siteId") REFERENCES "site" ("id") ON DELETE CASCADE ON UPDATE CASCADE)`,
undefined
);
await queryRunner.query(
`INSERT INTO "temporary_source"("id", "uri", "siteId") SELECT "id", "uri", "siteId" FROM "source"`,
undefined
);
await queryRunner.query(`DROP TABLE "source"`, undefined);
await queryRunner.query(`ALTER TABLE "temporary_source" RENAME TO "source"`, undefined);
await queryRunner.query(
`CREATE TABLE "temporary_translator_multi_name" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL, "multiNamedId" integer NOT NULL, CONSTRAINT "CHK_0652150dacaf6454a4cd6811de" CHECK (LENGTH(name) > 0), CONSTRAINT "FK_24720bc98312cb5ccd89c096dd4" FOREIGN KEY ("multiNamedId") REFERENCES "translator" ("id") ON DELETE CASCADE ON UPDATE CASCADE)`,
undefined
);
await queryRunner.query(
`INSERT INTO "temporary_translator_multi_name"("id", "name", "multiNamedId") SELECT "id", "name", "multiNamedId" FROM "translator_multi_name"`,
undefined
);
await queryRunner.query(`DROP TABLE "translator_multi_name"`, undefined);
await queryRunner.query(
`ALTER TABLE "temporary_translator_multi_name" RENAME TO "translator_multi_name"`,
undefined
);
await queryRunner.query(
`CREATE TABLE "temporary_copy" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "rating" integer, "favorited" boolean NOT NULL DEFAULT (0), "isDigital" boolean NOT NULL, "originalId" integer NOT NULL, CONSTRAINT "CHK_f6e0d7b6b3e80ad96e2a1dda43" CHECK (rating >= 0 AND rating <= 9007199254740991), CONSTRAINT "FK_e8ce0011cf0a8b9fdc8ad908a44" FOREIGN KEY ("originalId") REFERENCES "book" ("id") ON DELETE CASCADE ON UPDATE CASCADE)`,
undefined
);
await queryRunner.query(
`INSERT INTO "temporary_copy"("id", "rating", "favorited", "isDigital", "originalId") SELECT "id", "rating", "favorited", "isDigital", "originalId" FROM "copy"`,
undefined
);
await queryRunner.query(`DROP TABLE "copy"`, undefined);
await queryRunner.query(`ALTER TABLE "temporary_copy" RENAME TO "copy"`, undefined);
await queryRunner.query(
`CREATE TABLE "temporary_tag_multi_name" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL, "multiNamedId" integer NOT NULL, CONSTRAINT "CHK_ab521dd46cf7699c4abf75b76b" CHECK (LENGTH(name) > 0), CONSTRAINT "FK_34c0efcd4e11775f6e781708bda" FOREIGN KEY ("multiNamedId") REFERENCES "tag" ("id") ON DELETE CASCADE ON UPDATE CASCADE)`,
undefined
);
await queryRunner.query(
`INSERT INTO "temporary_tag_multi_name"("id", "name", "multiNamedId") SELECT "id", "name", "multiNamedId" FROM "tag_multi_name"`,
undefined
);
await queryRunner.query(`DROP TABLE "tag_multi_name"`, undefined);
await queryRunner.query(`ALTER TABLE "temporary_tag_multi_name" RENAME TO "tag_multi_name"`, undefined);
await queryRunner.query(
`CREATE TABLE "temporary_book_multi_name" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL, "multiNamedId" integer NOT NULL, CONSTRAINT "CHK_f989db6a159c4614d635ad6ad5" CHECK (LENGTH(name) > 0), CONSTRAINT "FK_191d56679fe812b502a6ac24cc7" FOREIGN KEY ("multiNamedId") REFERENCES "book" ("id") ON DELETE CASCADE ON UPDATE CASCADE)`,
undefined
);
await queryRunner.query(
`INSERT INTO "temporary_book_multi_name"("id", "name", "multiNamedId") SELECT "id", "name", "multiNamedId" FROM "book_multi_name"`,
undefined
);
await queryRunner.query(`DROP TABLE "book_multi_name"`, undefined);
await queryRunner.query(`ALTER TABLE "temporary_book_multi_name" RENAME TO "book_multi_name"`, undefined);
await queryRunner.query(
`CREATE TABLE "temporary_author_multi_name" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL, "multiNamedId" integer NOT NULL, CONSTRAINT "CHK_4d153aa4b33f8254933d224fe0" CHECK (LENGTH(name) > 0), CONSTRAINT "FK_f3aad920c89bea8e5e7ef67d887" FOREIGN KEY ("multiNamedId") REFERENCES "author" ("id") ON DELETE CASCADE ON UPDATE CASCADE)`,
undefined
);
await queryRunner.query(
`INSERT INTO "temporary_author_multi_name"("id", "name", "multiNamedId") SELECT "id", "name", "multiNamedId" FROM "author_multi_name"`,
undefined
);
await queryRunner.query(`DROP TABLE "author_multi_name"`, undefined);
await queryRunner.query(`ALTER TABLE "temporary_author_multi_name" RENAME TO "author_multi_name"`, undefined);
await queryRunner.query(`DROP INDEX "IDX_653c33c5db26b8736e592ff3f6"`, undefined);
await queryRunner.query(`DROP INDEX "IDX_946af3644f779b7cc7e7eb04eb"`, undefined);
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"))`,
undefined
);
await queryRunner.query(
`INSERT INTO "temporary_copy_sources_source"("copyId", "sourceId") SELECT "copyId", "sourceId" FROM "copy_sources_source"`,
undefined
);
await queryRunner.query(`DROP TABLE "copy_sources_source"`, undefined);
await queryRunner.query(`ALTER TABLE "temporary_copy_sources_source" RENAME TO "copy_sources_source"`, undefined);
await queryRunner.query(
`CREATE INDEX "IDX_653c33c5db26b8736e592ff3f6" ON "copy_sources_source" ("copyId") `,
undefined
);
await queryRunner.query(
`CREATE INDEX "IDX_946af3644f779b7cc7e7eb04eb" ON "copy_sources_source" ("sourceId") `,
undefined
);
await queryRunner.query(`DROP INDEX "IDX_056de447bd9e4b2efdf5eafe49"`, undefined);
await queryRunner.query(`DROP INDEX "IDX_c6adacfab107dc725d4fb5864b"`, undefined);
await queryRunner.query(
`CREATE TABLE "temporary_copy_languages_language" ("copyId" integer NOT NULL, "languageId" integer NOT NULL, CONSTRAINT "FK_056de447bd9e4b2efdf5eafe497" FOREIGN KEY ("copyId") REFERENCES "copy" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, CONSTRAINT "FK_c6adacfab107dc725d4fb5864be" FOREIGN KEY ("languageId") REFERENCES "language" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, PRIMARY KEY ("copyId", "languageId"))`,
undefined
);
await queryRunner.query(
`INSERT INTO "temporary_copy_languages_language"("copyId", "languageId") SELECT "copyId", "languageId" FROM "copy_languages_language"`,
undefined
);
await queryRunner.query(`DROP TABLE "copy_languages_language"`, undefined);
await queryRunner.query(
`ALTER TABLE "temporary_copy_languages_language" RENAME TO "copy_languages_language"`,
undefined
);
await queryRunner.query(
`CREATE INDEX "IDX_056de447bd9e4b2efdf5eafe49" ON "copy_languages_language" ("copyId") `,
undefined
);
await queryRunner.query(
`CREATE INDEX "IDX_c6adacfab107dc725d4fb5864b" ON "copy_languages_language" ("languageId") `,
undefined
);
await queryRunner.query(`DROP INDEX "IDX_2a20d8eaf28ebc28438271899f"`, undefined);
await queryRunner.query(`DROP INDEX "IDX_e19e5193f168ce07f52f15be06"`, undefined);
await queryRunner.query(
`CREATE TABLE "temporary_copy_translators_translator" ("copyId" integer NOT NULL, "translatorId" integer NOT NULL, CONSTRAINT "FK_2a20d8eaf28ebc28438271899f5" FOREIGN KEY ("copyId") REFERENCES "copy" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, CONSTRAINT "FK_e19e5193f168ce07f52f15be068" FOREIGN KEY ("translatorId") REFERENCES "translator" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, PRIMARY KEY ("copyId", "translatorId"))`,
undefined
);
await queryRunner.query(
`INSERT INTO "temporary_copy_translators_translator"("copyId", "translatorId") SELECT "copyId", "translatorId" FROM "copy_translators_translator"`,
undefined
);
await queryRunner.query(`DROP TABLE "copy_translators_translator"`, undefined);
await queryRunner.query(
`ALTER TABLE "temporary_copy_translators_translator" RENAME TO "copy_translators_translator"`,
undefined
);
await queryRunner.query(
`CREATE INDEX "IDX_2a20d8eaf28ebc28438271899f" ON "copy_translators_translator" ("copyId") `,
undefined
);
await queryRunner.query(
`CREATE INDEX "IDX_e19e5193f168ce07f52f15be06" ON "copy_translators_translator" ("translatorId") `,
undefined
);
await queryRunner.query(`DROP INDEX "IDX_9bf58ffb2a12a8609a738ee8ca"`, undefined);
await queryRunner.query(`DROP INDEX "IDX_a4cafdf2ec9974524a5321c751"`, undefined);
await queryRunner.query(
`CREATE TABLE "temporary_book_authors_author" ("bookId" integer NOT NULL, "authorId" integer NOT NULL, CONSTRAINT "FK_9bf58ffb2a12a8609a738ee8cae" FOREIGN KEY ("bookId") REFERENCES "book" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, CONSTRAINT "FK_a4cafdf2ec9974524a5321c7516" FOREIGN KEY ("authorId") REFERENCES "author" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, PRIMARY KEY ("bookId", "authorId"))`,
undefined
);
await queryRunner.query(
`INSERT INTO "temporary_book_authors_author"("bookId", "authorId") SELECT "bookId", "authorId" FROM "book_authors_author"`,
undefined
);
await queryRunner.query(`DROP TABLE "book_authors_author"`, undefined);
await queryRunner.query(`ALTER TABLE "temporary_book_authors_author" RENAME TO "book_authors_author"`, undefined);
await queryRunner.query(
`CREATE INDEX "IDX_9bf58ffb2a12a8609a738ee8ca" ON "book_authors_author" ("bookId") `,
undefined
);
await queryRunner.query(
`CREATE INDEX "IDX_a4cafdf2ec9974524a5321c751" ON "book_authors_author" ("authorId") `,
undefined
);
await queryRunner.query(`DROP INDEX "IDX_893dfbd84bd3a5a62e8a0758b3"`, undefined);
await queryRunner.query(`DROP INDEX "IDX_842bd3a8cb49dc7a92058b7f7a"`, undefined);
await queryRunner.query(
`CREATE TABLE "temporary_book_fictions_fiction" ("bookId" integer NOT NULL, "fictionId" integer NOT NULL, CONSTRAINT "FK_893dfbd84bd3a5a62e8a0758b3f" FOREIGN KEY ("bookId") REFERENCES "book" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, CONSTRAINT "FK_842bd3a8cb49dc7a92058b7f7aa" FOREIGN KEY ("fictionId") REFERENCES "fiction" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, PRIMARY KEY ("bookId", "fictionId"))`,
undefined
);
await queryRunner.query(
`INSERT INTO "temporary_book_fictions_fiction"("bookId", "fictionId") SELECT "bookId", "fictionId" FROM "book_fictions_fiction"`,
undefined
);
await queryRunner.query(`DROP TABLE "book_fictions_fiction"`, undefined);
await queryRunner.query(
`ALTER TABLE "temporary_book_fictions_fiction" RENAME TO "book_fictions_fiction"`,
undefined
);
await queryRunner.query(
`CREATE INDEX "IDX_893dfbd84bd3a5a62e8a0758b3" ON "book_fictions_fiction" ("bookId") `,
undefined
);
await queryRunner.query(
`CREATE INDEX "IDX_842bd3a8cb49dc7a92058b7f7a" ON "book_fictions_fiction" ("fictionId") `,
undefined
);
await queryRunner.query(`DROP INDEX "IDX_261dcea7cb50a485906440f91f"`, undefined);
await queryRunner.query(`DROP INDEX "IDX_51615a52cc3ef773766afbcc43"`, undefined);
await queryRunner.query(
`CREATE TABLE "temporary_book_characters_character" ("bookId" integer NOT NULL, "characterId" integer NOT NULL, CONSTRAINT "FK_261dcea7cb50a485906440f91f8" FOREIGN KEY ("bookId") REFERENCES "book" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, CONSTRAINT "FK_51615a52cc3ef773766afbcc433" FOREIGN KEY ("characterId") REFERENCES "character" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, PRIMARY KEY ("bookId", "characterId"))`,
undefined
);
await queryRunner.query(
`INSERT INTO "temporary_book_characters_character"("bookId", "characterId") SELECT "bookId", "characterId" FROM "book_characters_character"`,
undefined
);
await queryRunner.query(`DROP TABLE "book_characters_character"`, undefined);
await queryRunner.query(
`ALTER TABLE "temporary_book_characters_character" RENAME TO "book_characters_character"`,
undefined
);
await queryRunner.query(
`CREATE INDEX "IDX_261dcea7cb50a485906440f91f" ON "book_characters_character" ("bookId") `,
undefined
);
await queryRunner.query(
`CREATE INDEX "IDX_51615a52cc3ef773766afbcc43" ON "book_characters_character" ("characterId") `,
undefined
);
await queryRunner.query(`DROP INDEX "IDX_918a7b7552fe5fd66f328d4fe8"`, undefined);
await queryRunner.query(`DROP INDEX "IDX_5274aca0a1468ed55afdfaba24"`, undefined);
await queryRunner.query(
`CREATE TABLE "temporary_book_tags_tag" ("bookId" integer NOT NULL, "tagId" integer NOT NULL, CONSTRAINT "FK_918a7b7552fe5fd66f328d4fe84" FOREIGN KEY ("bookId") REFERENCES "book" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, CONSTRAINT "FK_5274aca0a1468ed55afdfaba244" FOREIGN KEY ("tagId") REFERENCES "tag" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, PRIMARY KEY ("bookId", "tagId"))`,
undefined
);
await queryRunner.query(
`INSERT INTO "temporary_book_tags_tag"("bookId", "tagId") SELECT "bookId", "tagId" FROM "book_tags_tag"`,
undefined
);
await queryRunner.query(`DROP TABLE "book_tags_tag"`, undefined);
await queryRunner.query(`ALTER TABLE "temporary_book_tags_tag" RENAME TO "book_tags_tag"`, undefined);
await queryRunner.query(`CREATE INDEX "IDX_918a7b7552fe5fd66f328d4fe8" ON "book_tags_tag" ("bookId") `, undefined);
await queryRunner.query(`CREATE INDEX "IDX_5274aca0a1468ed55afdfaba24" ON "book_tags_tag" ("tagId") `, undefined);
}
public async down(queryRunner: QueryRunner): Promise<any> {
await queryRunner.query(`DROP INDEX "IDX_5274aca0a1468ed55afdfaba24"`, undefined);
await queryRunner.query(`DROP INDEX "IDX_918a7b7552fe5fd66f328d4fe8"`, undefined);
await queryRunner.query(`ALTER TABLE "book_tags_tag" RENAME TO "temporary_book_tags_tag"`, undefined);
await queryRunner.query(
`CREATE TABLE "book_tags_tag" ("bookId" integer NOT NULL, "tagId" integer NOT NULL, PRIMARY KEY ("bookId", "tagId"))`,
undefined
);
await queryRunner.query(
`INSERT INTO "book_tags_tag"("bookId", "tagId") SELECT "bookId", "tagId" FROM "temporary_book_tags_tag"`,
undefined
);
await queryRunner.query(`DROP TABLE "temporary_book_tags_tag"`, undefined);
await queryRunner.query(`CREATE INDEX "IDX_5274aca0a1468ed55afdfaba24" ON "book_tags_tag" ("tagId") `, undefined);
await queryRunner.query(`CREATE INDEX "IDX_918a7b7552fe5fd66f328d4fe8" ON "book_tags_tag" ("bookId") `, undefined);
await queryRunner.query(`DROP INDEX "IDX_51615a52cc3ef773766afbcc43"`, undefined);
await queryRunner.query(`DROP INDEX "IDX_261dcea7cb50a485906440f91f"`, undefined);
await queryRunner.query(
`ALTER TABLE "book_characters_character" RENAME TO "temporary_book_characters_character"`,
undefined
);
await queryRunner.query(
`CREATE TABLE "book_characters_character" ("bookId" integer NOT NULL, "characterId" integer NOT NULL, PRIMARY KEY ("bookId", "characterId"))`,
undefined
);
await queryRunner.query(
`INSERT INTO "book_characters_character"("bookId", "characterId") SELECT "bookId", "characterId" FROM "temporary_book_characters_character"`,
undefined
);
await queryRunner.query(`DROP TABLE "temporary_book_characters_character"`, undefined);
await queryRunner.query(
`CREATE INDEX "IDX_51615a52cc3ef773766afbcc43" ON "book_characters_character" ("characterId") `,
undefined
);
await queryRunner.query(
`CREATE INDEX "IDX_261dcea7cb50a485906440f91f" ON "book_characters_character" ("bookId") `,
undefined
);
await queryRunner.query(`DROP INDEX "IDX_842bd3a8cb49dc7a92058b7f7a"`, undefined);
await queryRunner.query(`DROP INDEX "IDX_893dfbd84bd3a5a62e8a0758b3"`, undefined);
await queryRunner.query(
`ALTER TABLE "book_fictions_fiction" RENAME TO "temporary_book_fictions_fiction"`,
undefined
);
await queryRunner.query(
`CREATE TABLE "book_fictions_fiction" ("bookId" integer NOT NULL, "fictionId" integer NOT NULL, PRIMARY KEY ("bookId", "fictionId"))`,
undefined
);
await queryRunner.query(
`INSERT INTO "book_fictions_fiction"("bookId", "fictionId") SELECT "bookId", "fictionId" FROM "temporary_book_fictions_fiction"`,
undefined
);
await queryRunner.query(`DROP TABLE "temporary_book_fictions_fiction"`, undefined);
await queryRunner.query(
`CREATE INDEX "IDX_842bd3a8cb49dc7a92058b7f7a" ON "book_fictions_fiction" ("fictionId") `,
undefined
);
await queryRunner.query(
`CREATE INDEX "IDX_893dfbd84bd3a5a62e8a0758b3" ON "book_fictions_fiction" ("bookId") `,
undefined
);
await queryRunner.query(`DROP INDEX "IDX_a4cafdf2ec9974524a5321c751"`, undefined);
await queryRunner.query(`DROP INDEX "IDX_9bf58ffb2a12a8609a738ee8ca"`, undefined);
await queryRunner.query(`ALTER TABLE "book_authors_author" RENAME TO "temporary_book_authors_author"`, undefined);
await queryRunner.query(
`CREATE TABLE "book_authors_author" ("bookId" integer NOT NULL, "authorId" integer NOT NULL, PRIMARY KEY ("bookId", "authorId"))`,
undefined
);
await queryRunner.query(
`INSERT INTO "book_authors_author"("bookId", "authorId") SELECT "bookId", "authorId" FROM "temporary_book_authors_author"`,
undefined
);
await queryRunner.query(`DROP TABLE "temporary_book_authors_author"`, undefined);
await queryRunner.query(
`CREATE INDEX "IDX_a4cafdf2ec9974524a5321c751" ON "book_authors_author" ("authorId") `,
undefined
);
await queryRunner.query(
`CREATE INDEX "IDX_9bf58ffb2a12a8609a738ee8ca" ON "book_authors_author" ("bookId") `,
undefined
);
await queryRunner.query(`DROP INDEX "IDX_e19e5193f168ce07f52f15be06"`, undefined);
await queryRunner.query(`DROP INDEX "IDX_2a20d8eaf28ebc28438271899f"`, undefined);
await queryRunner.query(
`ALTER TABLE "copy_translators_translator" RENAME TO "temporary_copy_translators_translator"`,
undefined
);
await queryRunner.query(
`CREATE TABLE "copy_translators_translator" ("copyId" integer NOT NULL, "translatorId" integer NOT NULL, PRIMARY KEY ("copyId", "translatorId"))`,
undefined
);
await queryRunner.query(
`INSERT INTO "copy_translators_translator"("copyId", "translatorId") SELECT "copyId", "translatorId" FROM "temporary_copy_translators_translator"`,
undefined
);
await queryRunner.query(`DROP TABLE "temporary_copy_translators_translator"`, undefined);
await queryRunner.query(
`CREATE INDEX "IDX_e19e5193f168ce07f52f15be06" ON "copy_translators_translator" ("translatorId") `,
undefined
);
await queryRunner.query(
`CREATE INDEX "IDX_2a20d8eaf28ebc28438271899f" ON "copy_translators_translator" ("copyId") `,
undefined
);
await queryRunner.query(`DROP INDEX "IDX_c6adacfab107dc725d4fb5864b"`, undefined);
await queryRunner.query(`DROP INDEX "IDX_056de447bd9e4b2efdf5eafe49"`, undefined);
await queryRunner.query(
`ALTER TABLE "copy_languages_language" RENAME TO "temporary_copy_languages_language"`,
undefined
);
await queryRunner.query(
`CREATE TABLE "copy_languages_language" ("copyId" integer NOT NULL, "languageId" integer NOT NULL, PRIMARY KEY ("copyId", "languageId"))`,
undefined
);
await queryRunner.query(
`INSERT INTO "copy_languages_language"("copyId", "languageId") SELECT "copyId", "languageId" FROM "temporary_copy_languages_language"`,
undefined
);
await queryRunner.query(`DROP TABLE "temporary_copy_languages_language"`, undefined);
await queryRunner.query(
`CREATE INDEX "IDX_c6adacfab107dc725d4fb5864b" ON "copy_languages_language" ("languageId") `,
undefined
);
await queryRunner.query(
`CREATE INDEX "IDX_056de447bd9e4b2efdf5eafe49" ON "copy_languages_language" ("copyId") `,
undefined
);
await queryRunner.query(`DROP INDEX "IDX_946af3644f779b7cc7e7eb04eb"`, undefined);
await queryRunner.query(`DROP INDEX "IDX_653c33c5db26b8736e592ff3f6"`, undefined);
await queryRunner.query(`ALTER TABLE "copy_sources_source" RENAME TO "temporary_copy_sources_source"`, undefined);
await queryRunner.query(
`CREATE TABLE "copy_sources_source" ("copyId" integer NOT NULL, "sourceId" integer NOT NULL, PRIMARY KEY ("copyId", "sourceId"))`,
undefined
);
await queryRunner.query(
`INSERT INTO "copy_sources_source"("copyId", "sourceId") SELECT "copyId", "sourceId" FROM "temporary_copy_sources_source"`,
undefined
);
await queryRunner.query(`DROP TABLE "temporary_copy_sources_source"`, undefined);
await queryRunner.query(
`CREATE INDEX "IDX_946af3644f779b7cc7e7eb04eb" ON "copy_sources_source" ("sourceId") `,
undefined
);
await queryRunner.query(
`CREATE INDEX "IDX_653c33c5db26b8736e592ff3f6" ON "copy_sources_source" ("copyId") `,
undefined
);
await queryRunner.query(`ALTER TABLE "author_multi_name" RENAME TO "temporary_author_multi_name"`, undefined);
await queryRunner.query(
`CREATE TABLE "author_multi_name" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL, "multiNamedId" integer NOT NULL, CONSTRAINT "CHK_4d153aa4b33f8254933d224fe0" CHECK (LENGTH(name) > 0))`,
undefined
);
await queryRunner.query(
`INSERT INTO "author_multi_name"("id", "name", "multiNamedId") SELECT "id", "name", "multiNamedId" FROM "temporary_author_multi_name"`,
undefined
);
await queryRunner.query(`DROP TABLE "temporary_author_multi_name"`, undefined);
await queryRunner.query(`ALTER TABLE "book_multi_name" RENAME TO "temporary_book_multi_name"`, undefined);
await queryRunner.query(
`CREATE TABLE "book_multi_name" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL, "multiNamedId" integer NOT NULL, CONSTRAINT "CHK_f989db6a159c4614d635ad6ad5" CHECK (LENGTH(name) > 0))`,
undefined
);
await queryRunner.query(
`INSERT INTO "book_multi_name"("id", "name", "multiNamedId") SELECT "id", "name", "multiNamedId" FROM "temporary_book_multi_name"`,
undefined
);
await queryRunner.query(`DROP TABLE "temporary_book_multi_name"`, undefined);
await queryRunner.query(`ALTER TABLE "tag_multi_name" RENAME TO "temporary_tag_multi_name"`, undefined);
await queryRunner.query(
`CREATE TABLE "tag_multi_name" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL, "multiNamedId" integer NOT NULL, CONSTRAINT "CHK_ab521dd46cf7699c4abf75b76b" CHECK (LENGTH(name) > 0))`,
undefined
);
await queryRunner.query(
`INSERT INTO "tag_multi_name"("id", "name", "multiNamedId") SELECT "id", "name", "multiNamedId" FROM "temporary_tag_multi_name"`,
undefined
);
await queryRunner.query(`DROP TABLE "temporary_tag_multi_name"`, undefined);
await queryRunner.query(`ALTER TABLE "copy" RENAME TO "temporary_copy"`, undefined);
await queryRunner.query(
`CREATE TABLE "copy" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "rating" integer, "favorited" boolean NOT NULL DEFAULT (0), "isDigital" boolean NOT NULL, "originalId" integer NOT NULL, CONSTRAINT "CHK_f6e0d7b6b3e80ad96e2a1dda43" CHECK (rating >= 0 AND rating <= 9007199254740991))`,
undefined
);
await queryRunner.query(
`INSERT INTO "copy"("id", "rating", "favorited", "isDigital", "originalId") SELECT "id", "rating", "favorited", "isDigital", "originalId" FROM "temporary_copy"`,
undefined
);
await queryRunner.query(`DROP TABLE "temporary_copy"`, undefined);
await queryRunner.query(
`ALTER TABLE "translator_multi_name" RENAME TO "temporary_translator_multi_name"`,
undefined
);
await queryRunner.query(
`CREATE TABLE "translator_multi_name" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL, "multiNamedId" integer NOT NULL, CONSTRAINT "CHK_0652150dacaf6454a4cd6811de" CHECK (LENGTH(name) > 0))`,
undefined
);
await queryRunner.query(
`INSERT INTO "translator_multi_name"("id", "name", "multiNamedId") SELECT "id", "name", "multiNamedId" FROM "temporary_translator_multi_name"`,
undefined
);
await queryRunner.query(`DROP TABLE "temporary_translator_multi_name"`, undefined);
await queryRunner.query(`ALTER TABLE "source" RENAME TO "temporary_source"`, undefined);
await queryRunner.query(
`CREATE TABLE "source" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "uri" varchar NOT NULL, "siteId" integer NOT NULL, CONSTRAINT "UQ_028f4c3a05a9bfcddb95a4916b9" UNIQUE ("uri"))`,
undefined
);
await queryRunner.query(
`INSERT INTO "source"("id", "uri", "siteId") SELECT "id", "uri", "siteId" FROM "temporary_source"`,
undefined
);
await queryRunner.query(`DROP TABLE "temporary_source"`, undefined);
await queryRunner.query(`ALTER TABLE "site_multi_name" RENAME TO "temporary_site_multi_name"`, undefined);
await queryRunner.query(
`CREATE TABLE "site_multi_name" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL, "multiNamedId" integer NOT NULL, CONSTRAINT "CHK_8dc8533fce07e041aa8474da05" CHECK (LENGTH(name) > 0))`,
undefined
);
await queryRunner.query(
`INSERT INTO "site_multi_name"("id", "name", "multiNamedId") SELECT "id", "name", "multiNamedId" FROM "temporary_site_multi_name"`,
undefined
);
await queryRunner.query(`DROP TABLE "temporary_site_multi_name"`, undefined);
await queryRunner.query(`ALTER TABLE "copy_type" RENAME TO "temporary_copy_type"`, undefined);
await queryRunner.query(
`CREATE TABLE "copy_type" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "type" varchar NOT NULL, "comment" varchar, "copyId" integer NOT NULL)`,
undefined
);
await queryRunner.query(
`INSERT INTO "copy_type"("id", "type", "comment", "copyId") SELECT "id", "type", "comment", "copyId" FROM "temporary_copy_type"`,
undefined
);
await queryRunner.query(`DROP TABLE "temporary_copy_type"`, undefined);
await queryRunner.query(`ALTER TABLE "character_multi_name" RENAME TO "temporary_character_multi_name"`, undefined);
await queryRunner.query(
`CREATE TABLE "character_multi_name" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL, "multiNamedId" integer NOT NULL, CONSTRAINT "CHK_8f6325928e3a0cc9b78b52f6dc" CHECK (LENGTH(name) > 0))`,
undefined
);
await queryRunner.query(
`INSERT INTO "character_multi_name"("id", "name", "multiNamedId") SELECT "id", "name", "multiNamedId" FROM "temporary_character_multi_name"`,
undefined
);
await queryRunner.query(`DROP TABLE "temporary_character_multi_name"`, undefined);
await queryRunner.query(`ALTER TABLE "fiction_multi_name" RENAME TO "temporary_fiction_multi_name"`, undefined);
await queryRunner.query(
`CREATE TABLE "fiction_multi_name" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL, "multiNamedId" integer NOT NULL, CONSTRAINT "CHK_39f907c54d00784d2468156af2" CHECK (LENGTH(name) > 0))`,
undefined
);
await queryRunner.query(
`INSERT INTO "fiction_multi_name"("id", "name", "multiNamedId") SELECT "id", "name", "multiNamedId" FROM "temporary_fiction_multi_name"`,
undefined
);
await queryRunner.query(`DROP TABLE "temporary_fiction_multi_name"`, undefined);
await queryRunner.query(`DROP INDEX "IDX_5274aca0a1468ed55afdfaba24"`, undefined);
await queryRunner.query(`DROP INDEX "IDX_918a7b7552fe5fd66f328d4fe8"`, undefined);
await queryRunner.query(`DROP TABLE "book_tags_tag"`, undefined);
await queryRunner.query(`DROP INDEX "IDX_51615a52cc3ef773766afbcc43"`, undefined);
await queryRunner.query(`DROP INDEX "IDX_261dcea7cb50a485906440f91f"`, undefined);
await queryRunner.query(`DROP TABLE "book_characters_character"`, undefined);
await queryRunner.query(`DROP INDEX "IDX_842bd3a8cb49dc7a92058b7f7a"`, undefined);
await queryRunner.query(`DROP INDEX "IDX_893dfbd84bd3a5a62e8a0758b3"`, undefined);
await queryRunner.query(`DROP TABLE "book_fictions_fiction"`, undefined);
await queryRunner.query(`DROP INDEX "IDX_a4cafdf2ec9974524a5321c751"`, undefined);
await queryRunner.query(`DROP INDEX "IDX_9bf58ffb2a12a8609a738ee8ca"`, undefined);
await queryRunner.query(`DROP TABLE "book_authors_author"`, undefined);
await queryRunner.query(`DROP INDEX "IDX_e19e5193f168ce07f52f15be06"`, undefined);
await queryRunner.query(`DROP INDEX "IDX_2a20d8eaf28ebc28438271899f"`, undefined);
await queryRunner.query(`DROP TABLE "copy_translators_translator"`, undefined);
await queryRunner.query(`DROP INDEX "IDX_c6adacfab107dc725d4fb5864b"`, undefined);
await queryRunner.query(`DROP INDEX "IDX_056de447bd9e4b2efdf5eafe49"`, undefined);
await queryRunner.query(`DROP TABLE "copy_languages_language"`, undefined);
await queryRunner.query(`DROP INDEX "IDX_946af3644f779b7cc7e7eb04eb"`, undefined);
await queryRunner.query(`DROP INDEX "IDX_653c33c5db26b8736e592ff3f6"`, undefined);
await queryRunner.query(`DROP TABLE "copy_sources_source"`, undefined);
await queryRunner.query(`DROP TABLE "author_multi_name"`, undefined);
await queryRunner.query(`DROP TABLE "author"`, undefined);
await queryRunner.query(`DROP TABLE "book_multi_name"`, undefined);
await queryRunner.query(`DROP TABLE "book"`, undefined);
await queryRunner.query(`DROP TABLE "tag_multi_name"`, undefined);
await queryRunner.query(`DROP TABLE "tag"`, undefined);
await queryRunner.query(`DROP TABLE "copy"`, undefined);
await queryRunner.query(`DROP TABLE "translator_multi_name"`, undefined);
await queryRunner.query(`DROP TABLE "translator"`, undefined);
await queryRunner.query(`DROP TABLE "source"`, undefined);
await queryRunner.query(`DROP TABLE "site_multi_name"`, undefined);
await queryRunner.query(`DROP TABLE "site"`, undefined);
await queryRunner.query(`DROP TABLE "language"`, undefined);
await queryRunner.query(`DROP TABLE "copy_type"`, undefined);
await queryRunner.query(`DROP TABLE "character_multi_name"`, undefined);
await queryRunner.query(`DROP TABLE "character"`, undefined);
await queryRunner.query(`DROP TABLE "fiction_multi_name"`, undefined);
await queryRunner.query(`DROP TABLE "fiction"`, undefined);
}
}