Skip to content

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

Add inbox table

天舟f9d8246d16c4
diff --git a/store/migration/10001__init_schema.sql b/store/migration/10001__init_schema.sql
index 12a786b257..23a8b56a66 100644
--- a/store/migration/10001__init_schema.sql
+++ b/store/migration/10001__init_schema.sql
@@ -814,6 +814,25 @@ WHERE
END;
+-- inbox table stores the inbox entry for the corresponding activity.
+-- Unlike other tables, it doesn't have row_status/creator_id/created_ts/updater_id/updated_ts.
+-- We design in this way because:
+-- 1. The table may potentially contain a lot of rows (an issue activity will generate one inbox record per issue subscriber)
+-- 2. Does not provide much value besides what's contained in the related activity record.
+CREATE TABLE inbox (
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
+ receiver_id INTEGER NOT NULL REFERENCES principal (id),
+ activity_id INTEGER NOT NULL REFERENCES activity (id),
+ `status` TEXT NOT NULL CHECK (`status` IN ('UNREAD', 'READ', 'PINNED'))
+);
+
+CREATE INDEX idx_inbox_receiver_id_activity_id_status ON inbox(receiver_id, activity_id, `status`);
+
+INSERT INTO
+ sqlite_sequence (name, seq)
+VALUES
+ ('inbox', 100);
+
-- bookmark table stores the bookmark for the user
CREATE TABLE bookmark (
id INTEGER PRIMARY KEY AUTOINCREMENT,
diff --git a/store/seed/test/10000__reset.sql b/store/seed/test/10000__reset.sql
index 4e3957f0ae..c6fe694364 100644
--- a/store/seed/test/10000__reset.sql
+++ b/store/seed/test/10000__reset.sql
@@ -14,6 +14,9 @@ DELETE FROM
DELETE FROM
bookmark;
+DELETE FROM
+ inbox;
+
DELETE FROM
activity;
diff --git a/store/seed/test/10140__activity.sql b/store/seed/test/10140__activity.sql
index baea07c62c..072b423710 100644
--- a/store/seed/test/10140__activity.sql
+++ b/store/seed/test/10140__activity.sql
@@ -18,6 +18,7 @@ VALUES
INSERT INTO
activity (
+ id,
creator_id,
updater_id,
container_id,
@@ -26,6 +27,7 @@ INSERT INTO
)
VALUES
(
+ 14002,
101,
101,
13001,
@@ -35,6 +37,7 @@ VALUES
INSERT INTO
activity (
+ id,
creator_id,
updater_id,
container_id,
@@ -43,6 +46,7 @@ INSERT INTO
)
VALUES
(
+ 14003,
102,
102,
13001,
@@ -52,6 +56,7 @@ VALUES
INSERT INTO
activity (
+ id,
creator_id,
updater_id,
container_id,
@@ -60,6 +65,7 @@ INSERT INTO
)
VALUES
(
+ 14004,
103,
103,
13001,
@@ -70,6 +76,7 @@ VALUES
-- Activity for issue 13002
INSERT INTO
activity (
+ id,
creator_id,
created_ts,
updater_id,
@@ -79,6 +86,7 @@ INSERT INTO
)
VALUES
(
+ 14005,
1,
1624873710,
1,
@@ -89,6 +97,7 @@ VALUES
INSERT INTO
activity (
+ id,
creator_id,
created_ts,
updater_id,
@@ -100,6 +109,7 @@ INSERT INTO
)
VALUES
(
+ 14006,
1,
1624873710,
1,
@@ -112,6 +122,7 @@ VALUES
INSERT INTO
activity (
+ id,
creator_id,
created_ts,
updater_id,
@@ -123,6 +134,7 @@ INSERT INTO
)
VALUES
(
+ 14007,
1,
1624873710,
1,
@@ -135,6 +147,7 @@ VALUES
INSERT INTO
activity (
+ id,
creator_id,
created_ts,
updater_id,
@@ -146,6 +159,7 @@ INSERT INTO
)
VALUES
(
+ 14008,
1,
1624873710,
1,
@@ -158,6 +172,7 @@ VALUES
INSERT INTO
activity (
+ id,
creator_id,
created_ts,
updater_id,
@@ -169,6 +184,7 @@ INSERT INTO
)
VALUES
(
+ 14009,
1,
1624873710,
1,
@@ -182,6 +198,7 @@ VALUES
-- Activity for issue 13003
INSERT INTO
activity (
+ id,
creator_id,
created_ts,
updater_id,
@@ -191,6 +208,7 @@ INSERT INTO
)
VALUES
(
+ 14010,
103,
1624873710,
103,
@@ -202,6 +220,7 @@ VALUES
-- Activity for failed task_run 12001
INSERT INTO
activity (
+ id,
creator_id,
updater_id,
container_id,
@@ -211,6 +230,7 @@ INSERT INTO
)
VALUES
(
+ 14011,
1,
1,
13003,
@@ -221,6 +241,7 @@ VALUES
INSERT INTO
activity (
+ id,
creator_id,
updater_id,
container_id,
@@ -229,6 +250,7 @@ INSERT INTO
)
VALUES
(
+ 14012,
102,
102,
13003,
diff --git a/store/seed/test/10150__inbox.sql b/store/seed/test/10150__inbox.sql
new file mode 100644
index 0000000000..c94e626323
--- /dev/null
+++ b/store/seed/test/10150__inbox.sql
@@ -0,0 +1,170 @@
+-- Inbox for receiver 101
+INSERT INTO
+ inbox (
+ id,
+ receiver_id,
+ activity_id,
+ `status`
+ )
+VALUES
+ (
+ 15001,
+ 101,
+ 14001,
+ 'READ'
+ );
+
+INSERT INTO
+ inbox (
+ receiver_id,
+ activity_id,
+ `status`
+ )
+VALUES
+ (101, 14003, 'UNREAD');
+
+INSERT INTO
+ inbox (
+ receiver_id,
+ activity_id,
+ `status`
+ )
+VALUES
+ (101, 14004, 'UNREAD');
+
+INSERT INTO
+ inbox (
+ receiver_id,
+ activity_id,
+ `status`
+ )
+VALUES
+ (101, 14005, 'UNREAD');
+
+INSERT INTO
+ inbox (
+ receiver_id,
+ activity_id,
+ `status`
+ )
+VALUES
+ (101, 14006, 'UNREAD');
+
+INSERT INTO
+ inbox (
+ receiver_id,
+ activity_id,
+ `status`
+ )
+VALUES
+ (101, 14012, 'UNREAD');
+
+-- Inbox for receiver 102
+INSERT INTO
+ inbox (
+ receiver_id,
+ activity_id,
+ `status`
+ )
+VALUES
+ (102, 14001, 'READ');
+
+INSERT INTO
+ inbox (
+ receiver_id,
+ activity_id,
+ `status`
+ )
+VALUES
+ (102, 14002, 'READ');
+
+INSERT INTO
+ inbox (
+ receiver_id,
+ activity_id,
+ `status`
+ )
+VALUES
+ (102, 14004, 'READ');
+
+INSERT INTO
+ inbox (
+ receiver_id,
+ activity_id,
+ `status`
+ )
+VALUES
+ (102, 14005, 'UNREAD');
+
+INSERT INTO
+ inbox (
+ receiver_id,
+ activity_id,
+ `status`
+ )
+VALUES
+ (102, 14006, 'UNREAD');
+
+INSERT INTO
+ inbox (
+ receiver_id,
+ activity_id,
+ `status`
+ )
+VALUES
+ (102, 14012, 'UNREAD');
+
+-- Inbox for receiver 103
+INSERT INTO
+ inbox (
+ receiver_id,
+ activity_id,
+ `status`
+ )
+VALUES
+ (103, 14001, 'READ');
+
+INSERT INTO
+ inbox (
+ receiver_id,
+ activity_id,
+ `status`
+ )
+VALUES
+ (103, 14002, 'READ');
+
+INSERT INTO
+ inbox (
+ receiver_id,
+ activity_id,
+ `status`
+ )
+VALUES
+ (103, 14003, 'READ');
+
+INSERT INTO
+ inbox (
+ receiver_id,
+ activity_id,
+ `status`
+ )
+VALUES
+ (103, 14005, 'READ');
+
+INSERT INTO
+ inbox (
+ receiver_id,
+ activity_id,
+ `status`
+ )
+VALUES
+ (103, 14006, 'UNREAD');
+
+INSERT INTO
+ inbox (
+ receiver_id,
+ activity_id,
+ `status`
+ )
+VALUES
+ (103, 14012, 'UNREAD');
\ No newline at end of file
diff --git a/store/seed/test/10150__bookmark.sql b/store/seed/test/10160__bookmark.sql
similarity index 92%
rename from store/seed/test/10150__bookmark.sql
rename to store/seed/test/10160__bookmark.sql
index 882ffd449a..383d9c306a 100644
--- a/store/seed/test/10150__bookmark.sql
+++ b/store/seed/test/10160__bookmark.sql
@@ -9,7 +9,7 @@ INSERT INTO
)
VALUES
(
- 15001,
+ 16001,
101,
101,
'Hello world!',
diff --git a/store/seed/test/10160__vcs.sql b/store/seed/test/10170__vcs.sql
similarity index 96%
rename from store/seed/test/10160__vcs.sql
rename to store/seed/test/10170__vcs.sql
index cfeba8a4bf..a2b5321947 100644
--- a/store/seed/test/10160__vcs.sql
+++ b/store/seed/test/10170__vcs.sql
@@ -13,7 +13,7 @@ INSERT INTO
)
VALUES
(
- 16001,
+ 17001,
101,
101,
'bytebase.gitlab.com',
diff --git a/store/seed/test/10170__repo.sql b/store/seed/test/10180__repo.sql
similarity index 97%
rename from store/seed/test/10170__repo.sql
rename to store/seed/test/10180__repo.sql
index 07e9df5eb1..1ef5b0c7fc 100644
--- a/store/seed/test/10170__repo.sql
+++ b/store/seed/test/10180__repo.sql
@@ -22,10 +22,10 @@ INSERT INTO
)
VALUES
(
- 17001,
+ 18001,
101,
101,
- 16001,
+ 17001,
3003,
"Blog",
"bytebase-demo/blog",
@@ -67,10 +67,10 @@ INSERT INTO
)
VALUES
(
- 17002,
+ 18002,
101,
101,
- 16001,
+ 17001,
3002,
"Shop",
"bytebase-demo/shop",