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"))`); + } +} +