diff --git a/docs/downgrade.sql b/docs/downgrade.sql index 192800257b..149e82fafe 100644 --- a/docs/downgrade.sql +++ b/docs/downgrade.sql @@ -1,6 +1,7 @@ BEGIN; DELETE FROM "migrations" WHERE name IN ( + 'RemoveMentionedUsersColumn1710688552234', 'NoteFile1710304584214', 'RenameMetaColumns1705944717480', 'SeparateHardMuteWordsAndPatterns1706413792769', @@ -17,6 +18,19 @@ DELETE FROM "migrations" WHERE name IN ( 'RemoveNativeUtilsMigration1705877093218' ); +-- remove-mentioned-users-column +ALTER TABLE "note" ADD "mentionedRemoteUsers" text NOT NULL DEFAULT '[]'::text; +CREATE TABLE "temp_mentions_1710688552234" AS + SELECT "id", "url", "uri", "username", "host" + FROM "user" + JOIN "user_profile" ON "user"."id" = "user_profile". "userId" WHERE "user"."host" IS NOT NULL; +CREATE UNIQUE INDEX "temp_mentions_id" ON "temp_mentions_1710688552234" ("id"); +UPDATE "note" SET "mentionedRemoteUsers" = ( + SELECT COALESCE(json_agg(row_to_json("data")::jsonb - 'id')::text, '[]') FROM "temp_mentions_1710688552234" AS "data" + WHERE "data"."id" = ANY("note"."mentions") +); +DROP TABLE "temp_mentions_1710688552234"; + -- note-file DROP TABLE "note_file"; diff --git a/packages/backend-rs/src/model/entity/note.rs b/packages/backend-rs/src/model/entity/note.rs index c851c776e2..f713e2e47e 100644 --- a/packages/backend-rs/src/model/entity/note.rs +++ b/packages/backend-rs/src/model/entity/note.rs @@ -38,8 +38,6 @@ pub struct Model { #[sea_orm(column_name = "visibleUserIds")] pub visible_user_ids: Vec, pub mentions: Vec, - #[sea_orm(column_name = "mentionedRemoteUsers", column_type = "Text")] - pub mentioned_remote_users: String, pub emojis: Vec, pub tags: Vec, #[sea_orm(column_name = "hasPoll")]