-
Notifications
You must be signed in to change notification settings - Fork 249
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chrore(migration)_: remove the migration totally since it is not right
- Loading branch information
1 parent
75c96dd
commit 8c73295
Showing
1 changed file
with
8 additions
and
31 deletions.
There are no files selected for viewing
39 changes: 8 additions & 31 deletions
39
protocol/migrations/sqlite/1733428521_pinned_messages_add_on_delete_clause.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |