AppFlowy/frontend/rust-lib/flowy-server/docs/schema.plantuml
Nathan.fooo 2cd88594e8
feat: migrate user data to cloud (#3078)
* refactor: weak passed-in params in handler

* refactor: rename struct

* chore: update tables

* chore: update schema

* chore: add permission

* chore: update tables

* chore: support transaction mode

* chore: workspace database id

* chore: add user workspace

* feat: return list of workspaces

* chore: add user to workspace

* feat: separate database row table

* refactor: update schema

* chore: partition table

* chore: use transaction

* refactor: dir

* refactor: collab db ref

* fix: collab db lock

* chore: rename files

* chore: add tables descriptions

* chore: update readme

* docs: update documentation

* chore: rename crate

* chore: update ref

* chore: update tests

* chore: update tests

* refactor: crate deps

* chore: update crate ref

* chore: remove unused deps

* chore: remove unused deps

* chore: update collab crate refs

* chore: replace client with transaction in pooler

* refactor: return error type

* refactor: use anyhow error in deps

* feat: supabase postgrest user signin (wip)

* fix: Cargo.toml source git deps, changed Error to anyhow::Error

* fix: uuid serialization

* chore: fix conflict

* chore: extend the response

* feat: add implementation place holders

* feat: impl get_user_workspaces

* feat: impl get_user_profile

* test: create workspace

* fix: postgrest: field names and alias

* chore: implement folder restful api

* chore: implement collab storate with restful api

* feat: added placeholders for impl: update_user_profile, check_user

* feat: impl: update_user_profile

* feat: impl: check_user

* fix: use UidResponse, add more debug info for serde serialization error

* fix: get_user_profile: use Optional<UserProfileResponse>

* chore: imple init sync

* chore: support soft delete

* feat: postgresql: add migration test

* feat: postgresql migration test: added UID display and colored output

* feat: postgresql migration test: workspace role

* feat: postgresql migration test: create shared common utils

* feat: postgresql migration test: fixed shebang

* chore: add flush_collab_update pg function

* chore: implement datbaase and document restful api

* chore: migrate to use restful api

* chore: update table schema

* chore: fix tests

* chore: remove unused code

* chore: format code

* chore: remove unused env

* fix: tauri build

* fix: tauri build

---------

Co-authored-by: Fu Zi Xiang <speed2exe@live.com.sg>
2023-07-29 09:46:24 +08:00

204 lines
4.9 KiB
Plaintext

@startuml
left to right direction
entity "af_roles" as roles {
id : SERIAL (PK)
name : TEXT
}
entity "af_permissions" as permissions {
id : SERIAL (PK)
name : VARCHAR(255)
access_level : INTEGER
description : TEXT
}
entity "af_role_permissions" as role_permissions {
role_id : INT (FK af_roles.id)
permission_id : INT (FK af_permissions.id)
--
(role_id, permission_id) : PK
}
entity "af_user" as user {
uuid : UUID (PK)
email : TEXT
uid : BIGSERIAL
name : TEXT
created_at : TIMESTAMP WITH TIME ZONE
}
entity "af_workspace" as workspace {
workspace_id : UUID (PK)
database_storage_id : UUID
owner_uid : BIGINT (FK af_user.uid)
created_at : TIMESTAMP WITH TIME ZONE
workspace_type : INTEGER
workspace_name : TEXT
}
entity "af_workspace_member" as workspace_member {
uid : BIGINT
role_id : INT (FK af_roles.id)
workspace_id : UUID (FK af_workspace.workspace_id)
created_at : TIMESTAMP WITH TIME ZONE
updated_at : TIMESTAMP WITH TIME ZONE
--
(uid, workspace_id) : PK
}
entity "af_collab" as collab {
oid : TEXT (PK)
owner_uid : BIGINT
workspace_id : UUID (FK af_workspace.workspace_id)
access_level : INTEGER
created_at : TIMESTAMP WITH TIME ZONE
}
entity "af_collab_update" as collab_update {
oid : TEXT (FK af_collab.oid)
key : BIGSERIAL
value : BYTEA
value_size : INTEGER
partition_key : INTEGER
uid : BIGINT
md5 : TEXT
created_at : TIMESTAMP WITH TIME ZONE
workspace_id : UUID (FK af_workspace.workspace_id)
--
(oid, key, partition_key) : PK
}
entity "af_collab_update_document" as af_collab_update_document {
Inherits af_collab_update (partition_key = 0)
}
entity "af_collab_update_database" as af_collab_update_database {
Inherits af_collab_update (partition_key = 1)
}
entity "af_collab_update_w_database" as af_collab_update_w_database {
Inherits af_collab_update (partition_key = 2)
}
entity "af_collab_update_folder" as af_collab_update_folder {
Inherits af_collab_update (partition_key = 3)
}
af_collab_update_document -u-|> collab_update
af_collab_update_database -u-|> collab_update
af_collab_update_w_database -u-|> collab_update
af_collab_update_folder -u-|> collab_update
entity "af_database_row_update" as database_row_update {
oid : TEXT
key : BIGSERIAL
value : BYTEA
value_size : INTEGER
partition_key : INTEGER
uid : BIGINT
md5 : TEXT
workspace_id : UUID (FK af_workspace.workspace_id)
--
(oid, key) : PK
}
entity "af_collab_member" as collab_member {
uid : BIGINT (FK af_user.uid)
oid : TEXT (FK af_collab.oid)
role_id : INTEGER (FK af_roles.id)
--
(uid, oid) : PK
}
entity "af_collab_statistics" as collab_statistics {
oid : TEXT (PK)
edit_count : BIGINT
}
entity "af_collab_snapshot" as collab_snapshot {
sid : BIGSERIAL (PK)
oid : TEXT (FK af_collab.oid)
name : TEXT
blob : BYTEA
blob_size : INTEGER
edit_count : BIGINT
created_at : TIMESTAMP WITH TIME ZONE
}
roles <-- role_permissions : FK
permissions <-u- role_permissions : FK
user <-- collab : FK
user <-- workspace : FK
user <-- collab_member : FK
roles <-- workspace_member : FK
workspace <-- workspace_member : FK
workspace <-- collab : FK
workspace <-- database_row_update : FK
collab <-- collab_update : FK
collab <-- collab_snapshot: FK
collab <-u- collab_member : FK
collab <-- collab_statistics : PK
roles <-- collab_member : FK
@enduml
@startuml
title Triggers in Database Schema
participant "af_user" as A
participant "af_workspace" as B
participant "af_workspace_member" as C
participant "af_collab" as D
participant "af_collab_update" as E
participant "af_collab_member" as F
participant "af_collab_statistics" as G
participant "af_collab_snapshot" as H
A -> B: create_af_workspace_trigger
note right
This trigger fires after an insert on af_user. It automatically creates a workspace
with the uid of the new user as the owner_uid.
end note
B -> C: manage_af_workspace_member_role_trigger
note right
This trigger fires after an insert on af_workspace. It automatically
creates a workspace member in the af_workspace_member table with the
role 'Owner'.
end note
E -> D: insert_into_af_collab_trigger
note right
This trigger fires before an insert on af_collab_update.
It checks if a corresponding collab exists in the af_collab table.
If not, it creates one with the oid, uid, and current timestamp.
end note
D -> F: insert_into_af_collab_member_trigger
note right
This trigger fires after an insert on af_collab.
It automatically adds the collab's owner to the af_collab_member
table with the role 'Owner'.
end note
E -> G: af_collab_update_edit_count_trigger
note right
This trigger fires after an insert on af_collab_update.
It increments the edit_count of the corresponding collab in
the af_collab_statistics table.
end note
H -> G: af_collab_snapshot_update_edit_count_trigger
note right
This trigger fires after an insert on af_collab_snapshot.
It sets the edit_count of the new snapshot to the current
edit_count of the collab in the af_collab_statistics table.
end note
@enduml