From 9859537b024898bbddee11811dde22b55b2305be Mon Sep 17 00:00:00 2001 From: Johann150 Date: Fri, 26 May 2023 21:13:42 +0200 Subject: [PATCH] BREAKING migrate note favorites to clips The following endpoints are removed: - `api/i/favorites` - `api/notes/favorites/create` - `api/notes/favorites/delete` The following endpoints are changed: - `api/notes/state` - `api/users/stats` closes https://akkoma.dev/FoundKeyGang/FoundKey/issues/374 Changelog: Removed --- .../1685126322423-remove-favourites.js | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 packages/backend/migration/1685126322423-remove-favourites.js diff --git a/packages/backend/migration/1685126322423-remove-favourites.js b/packages/backend/migration/1685126322423-remove-favourites.js new file mode 100644 index 000000000..fab024744 --- /dev/null +++ b/packages/backend/migration/1685126322423-remove-favourites.js @@ -0,0 +1,33 @@ +export class removeFavourites1685126322423 { + name = 'removeFavourites1685126322423'; + + async up(queryRunner) { + await queryRunner.query(` + WITH "new_clips" AS ( + INSERT INTO "clip" ("id", "createdAt", "userId", "name") + SELECT + RIGHT(GEN_RANDOM_UUID()::text, 10), + NOW(), + "userId", + '⭐' + FROM "note_favorite" + GROUP BY "userId" + RETURNING "id", "userId" + ) + INSERT INTO "clip_note" ("id", "noteId", "clipId") + SELECT + "note_favorite"."id", + "noteId", + "new_clips"."id" + FROM "note_favorite" + JOIN "new_clips" ON "note_favorite"."userId" = "new_clips"."userId" + `); + await queryRunner.query(`DROP TABLE "note_favorite"`); + } + + async down(queryRunner) { + // can't revert the migration to clips, can only recreate the database table + await queryRunner.query(`CREATE TABLE "note_favorite" ("id" character varying(32) NOT NULL, "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL, "userId" character varying(32) NOT NULL, "noteId" character varying(32) NOT NULL, CONSTRAINT "PK_af0da35a60b9fa4463a62082b36" PRIMARY KEY ("id"))`); + } +} +