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 FoundKeyGang/FoundKey#374

Changelog: Removed
This commit is contained in:
Johann150 2023-05-26 21:13:42 +02:00
parent aa7171e116
commit 9859537b02
Signed by untrusted user: Johann150
GPG key ID: 9EE6577A2A06F8F1

View file

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