diff --git a/backend/migrations/1739650446621-add-library-item-created-at.ts b/backend/migrations/1739650446621-add-library-item-created-at.ts new file mode 100644 index 0000000..4c55df5 --- /dev/null +++ b/backend/migrations/1739650446621-add-library-item-created-at.ts @@ -0,0 +1,28 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class AddLibraryItemCreatedAt1739650446621 implements MigrationInterface { + name = 'AddLibraryItemCreatedAt1739650446621' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`CREATE TABLE "temporary_library_item" ("id" varchar NOT NULL, "tmdbId" varchar NOT NULL, "userId" varchar NOT NULL, "mediaType" varchar NOT NULL, "updatedAt" datetime NOT NULL DEFAULT (CURRENT_TIMESTAMP), "createdAt" datetime NOT NULL DEFAULT (CURRENT_TIMESTAMP), CONSTRAINT "UQ_d1794fd0082c98017895ea6afa4" UNIQUE ("tmdbId", "userId"), CONSTRAINT "UQ_d1794fd0082c98017895ea6afa4" UNIQUE ("tmdbId"), CONSTRAINT "FK_44e2a69f2788510e190dd3ac5ec" FOREIGN KEY ("userId") REFERENCES "user" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, PRIMARY KEY ("id", "userId"))`); + await queryRunner.query(`INSERT INTO "temporary_library_item"("id", "tmdbId", "userId", "mediaType") SELECT "id", "tmdbId", "userId", "mediaType" FROM "library_item"`); + await queryRunner.query(`DROP TABLE "library_item"`); + await queryRunner.query(`ALTER TABLE "temporary_library_item" RENAME TO "library_item"`); + await queryRunner.query(`CREATE TABLE "temporary_library_item" ("id" varchar NOT NULL, "tmdbId" varchar NOT NULL, "userId" varchar NOT NULL, "mediaType" varchar NOT NULL, "updatedAt" datetime NOT NULL DEFAULT (CURRENT_TIMESTAMP), "createdAt" datetime NOT NULL DEFAULT (CURRENT_TIMESTAMP), CONSTRAINT "UQ_d1794fd0082c98017895ea6afa4" UNIQUE ("tmdbId", "userId"), CONSTRAINT "UQ_d1794fd0082c98017895ea6afa4" UNIQUE ("tmdbId"), CONSTRAINT "UQ_97081ef9b13ccb55daec682da1a" UNIQUE ("tmdbId", "userId"), CONSTRAINT "FK_44e2a69f2788510e190dd3ac5ec" FOREIGN KEY ("userId") REFERENCES "user" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, PRIMARY KEY ("id", "userId"))`); + await queryRunner.query(`INSERT INTO "temporary_library_item"("id", "tmdbId", "userId", "mediaType", "updatedAt", "createdAt") SELECT "id", "tmdbId", "userId", "mediaType", "updatedAt", "createdAt" FROM "library_item"`); + await queryRunner.query(`DROP TABLE "library_item"`); + await queryRunner.query(`ALTER TABLE "temporary_library_item" RENAME TO "library_item"`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE "library_item" RENAME TO "temporary_library_item"`); + await queryRunner.query(`CREATE TABLE "library_item" ("id" varchar NOT NULL, "tmdbId" varchar NOT NULL, "userId" varchar NOT NULL, "mediaType" varchar NOT NULL, "updatedAt" datetime NOT NULL DEFAULT (CURRENT_TIMESTAMP), "createdAt" datetime NOT NULL DEFAULT (CURRENT_TIMESTAMP), CONSTRAINT "UQ_d1794fd0082c98017895ea6afa4" UNIQUE ("tmdbId", "userId"), CONSTRAINT "UQ_d1794fd0082c98017895ea6afa4" UNIQUE ("tmdbId"), CONSTRAINT "FK_44e2a69f2788510e190dd3ac5ec" FOREIGN KEY ("userId") REFERENCES "user" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, PRIMARY KEY ("id", "userId"))`); + await queryRunner.query(`INSERT INTO "library_item"("id", "tmdbId", "userId", "mediaType", "updatedAt", "createdAt") SELECT "id", "tmdbId", "userId", "mediaType", "updatedAt", "createdAt" FROM "temporary_library_item"`); + await queryRunner.query(`DROP TABLE "temporary_library_item"`); + await queryRunner.query(`ALTER TABLE "library_item" RENAME TO "temporary_library_item"`); + await queryRunner.query(`CREATE TABLE "library_item" ("id" varchar NOT NULL, "tmdbId" varchar NOT NULL, "userId" varchar NOT NULL, "mediaType" varchar NOT NULL, CONSTRAINT "UQ_d1794fd0082c98017895ea6afa4" UNIQUE ("tmdbId", "userId"), CONSTRAINT "UQ_d1794fd0082c98017895ea6afa4" UNIQUE ("tmdbId"), CONSTRAINT "FK_44e2a69f2788510e190dd3ac5ec" FOREIGN KEY ("userId") REFERENCES "user" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, PRIMARY KEY ("id", "userId"))`); + await queryRunner.query(`INSERT INTO "library_item"("id", "tmdbId", "userId", "mediaType") SELECT "id", "tmdbId", "userId", "mediaType" FROM "temporary_library_item"`); + await queryRunner.query(`DROP TABLE "temporary_library_item"`); + } + +} diff --git a/backend/package.json b/backend/package.json index b820dbf..cc05b2c 100644 --- a/backend/package.json +++ b/backend/package.json @@ -25,9 +25,9 @@ "openapi:generate-spec": "ts-node scripts/generate-openapi-spec.ts", "typeorm": "ts-node ./node_modules/typeorm/cli", "typeorm:run-migrations": "npm run typeorm migration:run -- -d ./dist/data-source.js", - "typeorm:generate-migration": "npm run typeorm -- -d ./dist/data-source.js migration:generate ./migrations/$npm_config_name", - "typeorm:create-migration": "npm run typeorm -- migration:create ./migrations/$npm_config_name", - "typeorm:revert-migration": "npm run typeorm -- -d ./dist/data-source.js migration:revert" + "typeorm:generate-migration": "ts-node ./node_modules/typeorm/cli -d ./dist/data-source.js migration:generate", + "typeorm:create-migration": "ts-node ./node_modules/typeorm/cli migration:create ./migrations/$npm_config_name", + "typeorm:revert-migration": "ts-node ./node_modules/typeorm/cli -d ./dist/data-source.js migration:revert" }, "dependencies": { "@aleksilassila/reiverr-plugin": "*", @@ -100,4 +100,4 @@ "packages/jellyfin.plugin", "packages/torrent-stream.plugin" ] -} \ No newline at end of file +}