Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

Add member schema

天舟8c539bb2b86c
diff --git a/backend/store/migration/0001_init_schema.down.sql b/backend/store/migration/0001_init_schema.down.sql
index af74080369..9089eb1603 100644
--- a/backend/store/migration/0001_init_schema.down.sql
+++ b/backend/store/migration/0001_init_schema.down.sql
@@ -1,4 +1,5 @@
-DROP TABLE workspace;
+DROP TABLE member;
-DROP TABLE principal;
+DROP TABLE workspace;
+DROP TABLE principal;
\ No newline at end of file
diff --git a/backend/store/migration/0001_init_schema.up.sql b/backend/store/migration/0001_init_schema.up.sql
index ee201b60de..a61759c65c 100644
--- a/backend/store/migration/0001_init_schema.up.sql
+++ b/backend/store/migration/0001_init_schema.up.sql
@@ -90,4 +90,36 @@ INSERT INTO
name
)
VALUES
- (1, 1, 1, 'NORMAL', '', 'Default workspace');
\ No newline at end of file
+ (1, 1, 1, 'NORMAL', '', 'Default workspace');
+
+-- Member table stores the workspace membership
+CREATE TABLE member (
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
+ workspace_id INTEGER NOT NULL REFERENCES workspace (id),
+ creator_id INTEGER NOT NULL REFERENCES principal (id),
+ created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
+ updater_id INTEGER NOT NULL REFERENCES principal (id),
+ updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
+ `role` TEXT NOT NULL CHECK (
+ `role` IN ('OWNER', 'DBA', 'DEVELOPER', "GUEST")
+ ),
+ principal_id INTEGER NOT NULL REFERENCES principal (id)
+);
+
+INSERT INTO
+ sqlite_sequence (name, seq)
+VALUES
+ ('member', 1000);
+
+CREATE TRIGGER IF NOT EXISTS `trigger_update_member_modification_time`
+AFTER
+UPDATE
+ ON `member` FOR EACH ROW BEGIN
+UPDATE
+ `member`
+SET
+ updated_ts = (strftime('%s', 'now'))
+WHERE
+ rowid = old.rowid;
+
+END;
\ No newline at end of file
diff --git a/backend/store/seed/0020_member.sql b/backend/store/seed/0020_member.sql
new file mode 100644
index 0000000000..10aed7b7be
--- /dev/null
+++ b/backend/store/seed/0020_member.sql
@@ -0,0 +1,65 @@
+INSERT INTO
+ member (
+ workspace_id,
+ creator_id,
+ updater_id,
+ role,
+ principal_id
+ )
+VALUES
+ (1, 1001, 1001, 'OWNER', 1001);
+
+INSERT INTO
+ member (
+ workspace_id,
+ creator_id,
+ updater_id,
+ role,
+ principal_id
+ )
+VALUES
+ (1001, 1001, 1001, 'OWNER', 1001);
+
+INSERT INTO
+ member (
+ workspace_id,
+ creator_id,
+ updater_id,
+ role,
+ principal_id
+ )
+VALUES
+ (1, 1001, 1001, 'DBA', 1002);
+
+INSERT INTO
+ member (
+ workspace_id,
+ creator_id,
+ updater_id,
+ role,
+ principal_id
+ )
+VALUES
+ (1, 1001, 1001, 'DEVELOPER', 1003);
+
+INSERT INTO
+ member (
+ workspace_id,
+ creator_id,
+ updater_id,
+ role,
+ principal_id
+ )
+VALUES
+ (1001, 1001, 1001, 'DBA', 1004);
+
+INSERT INTO
+ member (
+ workspace_id,
+ creator_id,
+ updater_id,
+ role,
+ principal_id
+ )
+VALUES
+ (1, 1001, 1001, 'DEVELOPER', 1005);
\ No newline at end of file