-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: save workspace member info to disk (#5536)
* chore: save workspace member info to disk * chore: fix clippy
- Loading branch information
Showing
18 changed files
with
207 additions
and
24 deletions.
There are no files selected for viewing
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
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
1 change: 1 addition & 0 deletions
1
frontend/rust-lib/flowy-sqlite/migrations/2024-06-14-020242_workspace_member/down.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 |
---|---|---|
@@ -0,0 +1 @@ | ||
-- This file should undo anything in `up.sql` |
11 changes: 11 additions & 0 deletions
11
frontend/rust-lib/flowy-sqlite/migrations/2024-06-14-020242_workspace_member/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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
-- Your SQL goes here | ||
CREATE TABLE workspace_members_table ( | ||
email TEXT KEY NOT NULL, | ||
role INTEGER NOT NULL, | ||
name TEXT NOT NULL, | ||
avatar_url TEXT, | ||
uid BIGINT NOT NULL, | ||
workspace_id TEXT NOT NULL, | ||
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
PRIMARY KEY (email, workspace_id) | ||
); |
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
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
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
52 changes: 52 additions & 0 deletions
52
frontend/rust-lib/flowy-user/src/services/sqlite_sql/member_sql.rs
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use diesel::{insert_into, RunQueryDsl}; | ||
use flowy_error::FlowyResult; | ||
|
||
use flowy_sqlite::schema::workspace_members_table; | ||
|
||
use flowy_sqlite::schema::workspace_members_table::dsl; | ||
use flowy_sqlite::{query_dsl::*, DBConnection, ExpressionMethods}; | ||
|
||
#[derive(Queryable, Insertable, AsChangeset, Debug)] | ||
#[diesel(table_name = workspace_members_table)] | ||
#[diesel(primary_key(email, workspace_id))] | ||
pub struct WorkspaceMemberTable { | ||
pub email: String, | ||
pub role: i32, | ||
pub name: String, | ||
pub avatar_url: Option<String>, | ||
pub uid: i64, | ||
pub workspace_id: String, | ||
pub updated_at: chrono::NaiveDateTime, | ||
} | ||
|
||
pub fn upsert_workspace_member<T: Into<WorkspaceMemberTable>>( | ||
mut conn: DBConnection, | ||
member: T, | ||
) -> FlowyResult<()> { | ||
let member = member.into(); | ||
|
||
insert_into(workspace_members_table::table) | ||
.values(&member) | ||
.on_conflict(( | ||
workspace_members_table::email, | ||
workspace_members_table::workspace_id, | ||
)) | ||
.do_update() | ||
.set(&member) | ||
.execute(&mut conn)?; | ||
|
||
Ok(()) | ||
} | ||
|
||
pub fn select_workspace_member( | ||
mut conn: DBConnection, | ||
workspace_id: &str, | ||
uid: i64, | ||
) -> FlowyResult<WorkspaceMemberTable> { | ||
let member = dsl::workspace_members_table | ||
.filter(workspace_members_table::workspace_id.eq(workspace_id)) | ||
.filter(workspace_members_table::uid.eq(uid)) | ||
.first::<WorkspaceMemberTable>(&mut conn)?; | ||
|
||
Ok(member) | ||
} |
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,2 +1,3 @@ | ||
pub(crate) mod member_sql; | ||
pub(crate) mod user_sql; | ||
pub(crate) mod workspace_sql; |
Oops, something went wrong.