Skip to content

Commit

Permalink
chore: squash migrations when possible
Browse files Browse the repository at this point in the history
  • Loading branch information
typfel committed Oct 13, 2023
1 parent 6d73cb0 commit 9a3ef70
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 260 deletions.
26 changes: 26 additions & 0 deletions persistence/src/commonMain/db_user/migrations/60.sqm
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
ALTER TABLE User ADD COLUMN supported_protocols TEXT AS Set<SupportedProtocolEntity> DEFAULT 'PROTEUS';
ALTER TABLE User ADD COLUMN active_one_on_one_conversation_id TEXT AS QualifiedIDEntity;

-- Re-create ConversationDetails view

DROP VIEW IF EXISTS ConversationDetails;

Expand Down Expand Up @@ -58,10 +61,18 @@ CASE (Conversation.type)
WHEN 'ONE_ON_ONE' THEN User.qualified_id
WHEN 'CONNECTION_PENDING' THEN connection_user.qualified_id
END AS otherUserId,
CASE (Conversation.type)
WHEN 'ONE_ON_ONE' THEN User.active_one_on_one_conversation_id
WHEN 'CONNECTION_PENDING' THEN connection_user.active_one_on_one_conversation_id
END AS otherUserActiveConversationId,
CASE
WHEN ((SELECT id FROM SelfUser LIMIT 1) LIKE (Conversation.creator_id || '@%')) THEN 1
ELSE 0
END AS isCreator,
CASE (Conversation.type)
WHEN 'ONE_ON_ONE' THEN coalesce(User.active_one_on_one_conversation_id = Conversation.qualified_id, 0)
ELSE 1
END AS isActive,
Conversation.last_notified_date AS lastNotifiedMessageDate,
memberRole. role AS selfRole,
Conversation.protocol,
Expand Down Expand Up @@ -99,6 +110,8 @@ LEFT JOIN Connection ON Connection.qualified_conversation = Conversation.qualifi
LEFT JOIN User AS connection_user ON Connection.qualified_to = connection_user.qualified_id
LEFT JOIN Call ON Call.id IS (SELECT id FROM Call WHERE Call.conversation_id = Conversation.qualified_id AND Call.status IS 'STILL_ONGOING' ORDER BY created_at DESC LIMIT 1);

-- Re-create UserDetails view

DROP VIEW IF EXISTS UserDetails;

CREATE VIEW IF NOT EXISTS UserDetails AS
Expand All @@ -121,10 +134,23 @@ User.incomplete_metadata,
User.expires_at,
User.defederated,
User.supported_protocols,
User.active_one_on_one_conversation_id,
CASE
WHEN SUM(Client.is_verified) = COUNT(*) THEN 1
ELSE 0
END AS is_proteus_verified
FROM User
LEFT JOIN Client ON User.qualified_id = Client.user_id
GROUP BY User.qualified_id;

-- Populate active_one_on_one_conversation_id for users with existing one-on-one conversations

UPDATE User
SET active_one_on_one_conversation_id = (
SELECT Member.conversation FROM Member
JOIN Conversation ON Conversation.qualified_id = Member.conversation
WHERE Conversation.type = 'ONE_ON_ONE' AND Conversation.protocol = 'PROTEUS' AND Member.user = User.qualified_id
LIMIT 1
)
WHERE qualified_id != (SELECT id FROM SelfUser);

152 changes: 0 additions & 152 deletions persistence/src/commonMain/db_user/migrations/63.sqm

This file was deleted.

108 changes: 0 additions & 108 deletions persistence/src/commonMain/db_user/migrations/64.sqm

This file was deleted.

0 comments on commit 9a3ef70

Please sign in to comment.