From bf2d837f998bcbe8f59bb43bc7e7c206499a47d1 Mon Sep 17 00:00:00 2001 From: dr-carrot Date: Sun, 15 Dec 2024 15:33:24 -0500 Subject: [PATCH] feat: add postgres migration for streaming region --- ...71530757-AddUserSettingsStreamingRegion.ts | 89 +++++++++++++++++++ ...07530757-AddUserSettingsStreamingRegion.ts | 0 2 files changed, 89 insertions(+) create mode 100644 server/migration/postgres/1730771530757-AddUserSettingsStreamingRegion.ts rename server/migration/{ => sqlite}/1727907530757-AddUserSettingsStreamingRegion.ts (100%) diff --git a/server/migration/postgres/1730771530757-AddUserSettingsStreamingRegion.ts b/server/migration/postgres/1730771530757-AddUserSettingsStreamingRegion.ts new file mode 100644 index 000000000..9a98228b3 --- /dev/null +++ b/server/migration/postgres/1730771530757-AddUserSettingsStreamingRegion.ts @@ -0,0 +1,89 @@ +import type { MigrationInterface, QueryRunner } from 'typeorm'; + +export class AddUserSettingsStreamingRegion1727907530757 + implements MigrationInterface +{ + name = 'AddUserSettingsStreamingRegion1727907530757'; + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query( + `CREATE TABLE "temporary_user_settings" ( + "id" SERIAL PRIMARY KEY, + "notificationTypes" text, + "discordId" varchar, + "userId" integer, + "originalLanguage" varchar, + "telegramChatId" varchar, + "telegramSendSilently" boolean, + "pgpKey" varchar, + "locale" varchar NOT NULL DEFAULT '', + "pushbulletAccessToken" varchar, + "pushoverApplicationToken" varchar, + "pushoverUserKey" varchar, + "watchlistSyncMovies" boolean, + "watchlistSyncTv" boolean, + "pushoverSound" varchar, + CONSTRAINT "UQ_986a2b6d3c05eb4091bb8066f78" UNIQUE ("userId"), + CONSTRAINT "FK_986a2b6d3c05eb4091bb8066f78" FOREIGN KEY ("userId") REFERENCES "user" ("id") ON DELETE CASCADE ON UPDATE NO ACTION + )` + ); + await queryRunner.query( + `INSERT INTO "temporary_user_settings"( + "id", "notificationTypes", "discordId", "userId", "originalLanguage", "telegramChatId", "telegramSendSilently", "pgpKey", "locale", "pushbulletAccessToken", "pushoverApplicationToken", "pushoverUserKey", "watchlistSyncMovies", "watchlistSyncTv", "pushoverSound" + ) SELECT + "id", "notificationTypes", "discordId", "userId", "originalLanguage", "telegramChatId", "telegramSendSilently", "pgpKey", "locale", "pushbulletAccessToken", "pushoverApplicationToken", "pushoverUserKey", "watchlistSyncMovies", "watchlistSyncTv", "pushoverSound" + FROM "user_settings"` + ); + await queryRunner.query(`DROP TABLE "user_settings"`); + await queryRunner.query( + `ALTER TABLE "temporary_user_settings" RENAME TO "user_settings"` + ); + await queryRunner.query( + `ALTER TABLE "user_settings" ADD COLUMN "discoverRegion" varchar` + ); + await queryRunner.query( + `ALTER TABLE "user_settings" ADD COLUMN "streamingRegion" varchar` + ); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query( + `ALTER TABLE "user_settings" DROP COLUMN "streamingRegion"` + ); + await queryRunner.query( + `ALTER TABLE "user_settings" DROP COLUMN "discoverRegion"` + ); + await queryRunner.query( + `ALTER TABLE "user_settings" RENAME TO "temporary_user_settings"` + ); + await queryRunner.query( + `CREATE TABLE "user_settings" ( + "id" SERIAL PRIMARY KEY, + "notificationTypes" text, + "discordId" varchar, + "userId" integer, + "originalLanguage" varchar, + "telegramChatId" varchar, + "telegramSendSilently" boolean, + "pgpKey" varchar, + "locale" varchar NOT NULL DEFAULT '', + "pushbulletAccessToken" varchar, + "pushoverApplicationToken" varchar, + "pushoverUserKey" varchar, + "watchlistSyncMovies" boolean, + "watchlistSyncTv" boolean, + "pushoverSound" varchar, + CONSTRAINT "UQ_986a2b6d3c05eb4091bb8066f78" UNIQUE ("userId"), + CONSTRAINT "FK_986a2b6d3c05eb4091bb8066f78" FOREIGN KEY ("userId") REFERENCES "user" ("id") ON DELETE CASCADE ON UPDATE NO ACTION + )` + ); + await queryRunner.query( + `INSERT INTO "user_settings"( + "id", "notificationTypes", "discordId", "userId", "originalLanguage", "telegramChatId", "telegramSendSilently", "pgpKey", "locale", "pushbulletAccessToken", "pushoverApplicationToken", "pushoverUserKey", "watchlistSyncMovies", "watchlistSyncTv", "pushoverSound" + ) SELECT + "id", "notificationTypes", "discordId", "userId", "originalLanguage", "telegramChatId", "telegramSendSilently", "pgpKey", "locale", "pushbulletAccessToken", "pushoverApplicationToken", "pushoverUserKey", "watchlistSyncMovies", "watchlistSyncTv", "pushoverSound" + FROM "temporary_user_settings"` + ); + await queryRunner.query(`DROP TABLE "temporary_user_settings"`); + } +} diff --git a/server/migration/1727907530757-AddUserSettingsStreamingRegion.ts b/server/migration/sqlite/1727907530757-AddUserSettingsStreamingRegion.ts similarity index 100% rename from server/migration/1727907530757-AddUserSettingsStreamingRegion.ts rename to server/migration/sqlite/1727907530757-AddUserSettingsStreamingRegion.ts