diff --git a/protocol/migrations/sqlite/1733428521_pinned_messages_add_on_delete_clause.up.sql b/protocol/migrations/sqlite/1733428521_pinned_messages_add_on_delete_clause.up.sql index f876e0b038..5fe44c7176 100644 --- a/protocol/migrations/sqlite/1733428521_pinned_messages_add_on_delete_clause.up.sql +++ b/protocol/migrations/sqlite/1733428521_pinned_messages_add_on_delete_clause.up.sql @@ -1,31 +1,8 @@ --- Delete pinned messages that are not associated with any user message --- This makes sure the migration below works even if a message is deleted -DELETE FROM pin_messages -WHERE NOT EXISTS ( - SELECT 1 - FROM user_messages - WHERE user_messages.id = pin_messages.message_id -); - --- Add the ON DELETE CASCADE clause to the foreign key constraint -CREATE TABLE pin_messages_new ( - id VARCHAR PRIMARY KEY NOT NULL, - message_id VARCHAR NOT NULL, - whisper_timestamp INTEGER NOT NULL, - chat_id VARCHAR NOT NULL, - local_chat_id VARCHAR NOT NULL, - clock_value INT NOT NULL, - pinned BOOLEAN NOT NULL, - pinned_by TEXT, - FOREIGN KEY (message_id) REFERENCES user_messages(id) ON DELETE CASCADE -); - --- Copy the data from the old table to the new table -INSERT INTO pin_messages_new (id, message_id, whisper_timestamp, chat_id, local_chat_id, clock_value, pinned, pinned_by) -SELECT id, message_id, whisper_timestamp, chat_id, local_chat_id, clock_value, pinned, pinned_by -FROM pin_messages; - --- Drop the old table and rename the new table -DROP TABLE pin_messages; - -ALTER TABLE pin_messages_new RENAME TO pin_messages; +-- Leave this migration empty +-- This used to be a migration to add ON DELETE CASCADE to the pinned_messages table +-- However, we found that it had the side effect of preventing pinned messages to arrive before the messages they are pinned to +-- Leaving this migration here to prevent the migration from being run again +-- People that ran the migraiton already will have the wrong behavior on edge cases, but we can't fix that easily +-- People that didn't run this migration will have the correct behavior +-- This was never run on a release +-- See more info here: https://github.com/status-im/status-go/pull/6231#discussion_r1904038990 \ No newline at end of file