Skip to content

Commit

Permalink
chrore(migration)_: remove the migration totally since it is not right
Browse files Browse the repository at this point in the history
  • Loading branch information
jrainville committed Jan 7, 2025
1 parent 75c96dd commit 8c73295
Showing 1 changed file with 8 additions and 31 deletions.
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

0 comments on commit 8c73295

Please sign in to comment.