Skip to content

Commit

Permalink
Update schema to use added_by_address
Browse files Browse the repository at this point in the history
  • Loading branch information
zombieobject committed Apr 8, 2024
1 parent df83a89 commit 0a1eb1a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- As SQLite does not support ALTER, we play this game of move, repopulate, drop. Here we recreate without the 'added_by_address' column.
BEGIN TRANSACTION;
CREATE TEMPORARY TABLE backup_group(id BLOB PRIMARY KEY NOT NULL, created_at_ns BIGINT NOT NULL, membership_state INT NOT NULL, installations_last_checked BIGINT NOT NULL, purpose INT NOT NULL DEFAULT 1);
INSERT INTO backup_group SELECT id, created_at_ns, membership_state, installations_last_checked, pupose FROM groups;
DROP TABLE groups;
CREATE TABLE groups(id BLOB PRIMARY KEY NOT NULL, created_at_ns BIGINT NOT NULL, membership_state INT NOT NULL, installations_last_checked BIGINT NOT NULL, purpose INT NOT NULL DEFAULT 1);
INSERT INTO groups SELECT id, created_at_ns, membership_state, installations_last_checked, purpose FROM backup_group;
DROP TABLE backup_group;
COMMIT;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE groups
ADD COLUMN added_by_address TEXT
4 changes: 4 additions & 0 deletions xmtp_mls/src/storage/encrypted_store/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ pub struct StoredGroup {
pub installations_last_checked: i64,
/// Enum, [`Purpose`] signifies the group purpose which extends to who can access it.
pub purpose: Purpose,
/// String representing the wallet address of the who added the user to a group.
pub added_by_address: Option<String>,
}

impl_fetch!(StoredGroup, groups, Vec<u8>);
Expand All @@ -48,6 +50,7 @@ impl StoredGroup {
membership_state,
installations_last_checked: 0,
purpose: Purpose::Conversation,
added_by_address: None,
}
}

Expand All @@ -63,6 +66,7 @@ impl StoredGroup {
membership_state,
installations_last_checked: 0,
purpose: Purpose::Sync,
added_by_address: None,
}
}
}
Expand Down
1 change: 1 addition & 0 deletions xmtp_mls/src/storage/encrypted_store/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ diesel::table! {
membership_state -> Integer,
installations_last_checked -> BigInt,
purpose -> Integer,
added_by_address -> Nullable<Text>,
}
}

Expand Down

0 comments on commit 0a1eb1a

Please sign in to comment.