schema.plantuml 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. @startuml
  2. left to right direction
  3. entity "af_roles" as roles {
  4. id : SERIAL (PK)
  5. name : TEXT
  6. }
  7. entity "af_permissions" as permissions {
  8. id : SERIAL (PK)
  9. name : VARCHAR(255)
  10. access_level : INTEGER
  11. description : TEXT
  12. }
  13. entity "af_role_permissions" as role_permissions {
  14. role_id : INT (FK af_roles.id)
  15. permission_id : INT (FK af_permissions.id)
  16. --
  17. (role_id, permission_id) : PK
  18. }
  19. entity "af_user" as user {
  20. uuid : UUID (PK)
  21. email : TEXT
  22. uid : BIGSERIAL
  23. name : TEXT
  24. created_at : TIMESTAMP WITH TIME ZONE
  25. }
  26. entity "af_workspace" as workspace {
  27. workspace_id : UUID (PK)
  28. database_storage_id : UUID
  29. owner_uid : BIGINT (FK af_user.uid)
  30. created_at : TIMESTAMP WITH TIME ZONE
  31. workspace_type : INTEGER
  32. workspace_name : TEXT
  33. }
  34. entity "af_workspace_member" as workspace_member {
  35. uid : BIGINT
  36. role_id : INT (FK af_roles.id)
  37. workspace_id : UUID (FK af_workspace.workspace_id)
  38. created_at : TIMESTAMP WITH TIME ZONE
  39. updated_at : TIMESTAMP WITH TIME ZONE
  40. --
  41. (uid, workspace_id) : PK
  42. }
  43. entity "af_collab" as collab {
  44. oid : TEXT (PK)
  45. owner_uid : BIGINT
  46. workspace_id : UUID (FK af_workspace.workspace_id)
  47. access_level : INTEGER
  48. created_at : TIMESTAMP WITH TIME ZONE
  49. }
  50. entity "af_collab_update" as collab_update {
  51. oid : TEXT (FK af_collab.oid)
  52. key : BIGSERIAL
  53. value : BYTEA
  54. value_size : INTEGER
  55. partition_key : INTEGER
  56. uid : BIGINT
  57. md5 : TEXT
  58. created_at : TIMESTAMP WITH TIME ZONE
  59. workspace_id : UUID (FK af_workspace.workspace_id)
  60. --
  61. (oid, key, partition_key) : PK
  62. }
  63. entity "af_collab_update_document" as af_collab_update_document {
  64. Inherits af_collab_update (partition_key = 0)
  65. }
  66. entity "af_collab_update_database" as af_collab_update_database {
  67. Inherits af_collab_update (partition_key = 1)
  68. }
  69. entity "af_collab_update_w_database" as af_collab_update_w_database {
  70. Inherits af_collab_update (partition_key = 2)
  71. }
  72. entity "af_collab_update_folder" as af_collab_update_folder {
  73. Inherits af_collab_update (partition_key = 3)
  74. }
  75. af_collab_update_document -u-|> collab_update
  76. af_collab_update_database -u-|> collab_update
  77. af_collab_update_w_database -u-|> collab_update
  78. af_collab_update_folder -u-|> collab_update
  79. entity "af_database_row_update" as database_row_update {
  80. oid : TEXT
  81. key : BIGSERIAL
  82. value : BYTEA
  83. value_size : INTEGER
  84. partition_key : INTEGER
  85. uid : BIGINT
  86. md5 : TEXT
  87. workspace_id : UUID (FK af_workspace.workspace_id)
  88. --
  89. (oid, key) : PK
  90. }
  91. entity "af_collab_member" as collab_member {
  92. uid : BIGINT (FK af_user.uid)
  93. oid : TEXT (FK af_collab.oid)
  94. role_id : INTEGER (FK af_roles.id)
  95. --
  96. (uid, oid) : PK
  97. }
  98. entity "af_collab_statistics" as collab_statistics {
  99. oid : TEXT (PK)
  100. edit_count : BIGINT
  101. }
  102. entity "af_collab_snapshot" as collab_snapshot {
  103. sid : BIGSERIAL (PK)
  104. oid : TEXT (FK af_collab.oid)
  105. name : TEXT
  106. blob : BYTEA
  107. blob_size : INTEGER
  108. edit_count : BIGINT
  109. created_at : TIMESTAMP WITH TIME ZONE
  110. }
  111. roles <-- role_permissions : FK
  112. permissions <-u- role_permissions : FK
  113. user <-- collab : FK
  114. user <-- workspace : FK
  115. user <-- collab_member : FK
  116. roles <-- workspace_member : FK
  117. workspace <-- workspace_member : FK
  118. workspace <-- collab : FK
  119. workspace <-- database_row_update : FK
  120. collab <-- collab_update : FK
  121. collab <-- collab_snapshot: FK
  122. collab <-u- collab_member : FK
  123. collab <-- collab_statistics : PK
  124. roles <-- collab_member : FK
  125. @enduml
  126. @startuml
  127. title Triggers in Database Schema
  128. participant "af_user" as A
  129. participant "af_workspace" as B
  130. participant "af_workspace_member" as C
  131. participant "af_collab" as D
  132. participant "af_collab_update" as E
  133. participant "af_collab_member" as F
  134. participant "af_collab_statistics" as G
  135. participant "af_collab_snapshot" as H
  136. A -> B: create_af_workspace_trigger
  137. note right
  138. This trigger fires after an insert on af_user. It automatically creates a workspace
  139. with the uid of the new user as the owner_uid.
  140. end note
  141. B -> C: manage_af_workspace_member_role_trigger
  142. note right
  143. This trigger fires after an insert on af_workspace. It automatically
  144. creates a workspace member in the af_workspace_member table with the
  145. role 'Owner'.
  146. end note
  147. E -> D: insert_into_af_collab_trigger
  148. note right
  149. This trigger fires before an insert on af_collab_update.
  150. It checks if a corresponding collab exists in the af_collab table.
  151. If not, it creates one with the oid, uid, and current timestamp.
  152. end note
  153. D -> F: insert_into_af_collab_member_trigger
  154. note right
  155. This trigger fires after an insert on af_collab.
  156. It automatically adds the collab's owner to the af_collab_member
  157. table with the role 'Owner'.
  158. end note
  159. E -> G: af_collab_update_edit_count_trigger
  160. note right
  161. This trigger fires after an insert on af_collab_update.
  162. It increments the edit_count of the corresponding collab in
  163. the af_collab_statistics table.
  164. end note
  165. H -> G: af_collab_snapshot_update_edit_count_trigger
  166. note right
  167. This trigger fires after an insert on af_collab_snapshot.
  168. It sets the edit_count of the new snapshot to the current
  169. edit_count of the collab in the af_collab_statistics table.
  170. end note
  171. @enduml