Skip to content

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

Add level column to inbox table. Level can be INFO, WARNING, ERROR

天舟84cf7344bc08
diff --git a/api/inbox.go b/api/inbox.go
index 1d2dcb2791..43019fdb82 100644
--- a/api/inbox.go
+++ b/api/inbox.go
@@ -25,6 +25,26 @@ func (e InboxStatus) String() string {
return "UNKNOWN"
}
+type InboxLevel string
+
+const (
+ INBOX_INFO InboxLevel = "INFO"
+ INBOX_WARNING InboxLevel = "WARNING"
+ INBOX_ERROR InboxLevel = "ERROR"
+)
+
+func (e InboxLevel) String() string {
+ switch e {
+ case INBOX_INFO:
+ return "INFO"
+ case INBOX_WARNING:
+ return "WARNING"
+ case INBOX_ERROR:
+ return "ERROR"
+ }
+ return "UNKNOWN"
+}
+
type Inbox struct {
ID int `jsonapi:"primary,inbox"`
@@ -32,12 +52,14 @@ type Inbox struct {
ReceiverId int `jsonapi:"attr,receiverId"`
Activity *Activity `jsonapi:"relation,activity"`
Status InboxStatus `jsonapi:"attr,status"`
+ Level InboxLevel `jsonapi:"attr,level"`
}
type InboxCreate struct {
// Domain specific fields
ReceiverId int
ActivityId int
+ Level InboxLevel
}
type InboxFind struct {
diff --git a/frontend/src/components/InboxList.vue b/frontend/src/components/InboxList.vue
index 438e69a819..62a31bd490 100644
--- a/frontend/src/components/InboxList.vue
+++ b/frontend/src/components/InboxList.vue
@@ -21,6 +21,7 @@
font-base
text-control-light
flex flex-row
+ items-center
whitespace-nowrap
"
>
@@ -32,6 +33,39 @@
>
</template>
<span> {{ actionSentence(inbox.activity) }}</span>
+ <template v-if="inbox.level == 'WARNING'">
+ <svg
+ class="ml-1 h-6 w-6 text-warning"
+ xmlns="http://www.w3.org/2000/svg"
+ fill="none"
+ viewBox="0 0 24 24"
+ stroke="currentColor"
+ aria-hidden="true"
+ >
+ <path
+ stroke-linecap="round"
+ stroke-linejoin="round"
+ stroke-width="2"
+ d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"
+ ></path>
+ </svg>
+ </template>
+ <template v-else-if="inbox.level == 'ERROR'">
+ <svg
+ class="ml-1 w-6 h-6 text-error"
+ fill="none"
+ stroke="currentColor"
+ viewBox="0 0 24 24"
+ xmlns="http://www.w3.org/2000/svg"
+ >
+ <path
+ stroke-linecap="round"
+ stroke-linejoin="round"
+ stroke-width="2"
+ d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"
+ ></path>
+ </svg>
+ </template>
</h3>
<p class="text-sm text-control whitespace-nowrap">
{{ humanizeTs(inbox.activity.createdTs) }}
diff --git a/frontend/src/types/inbox.ts b/frontend/src/types/inbox.ts
index 39e5eb1ab0..3f9ee72a7e 100644
--- a/frontend/src/types/inbox.ts
+++ b/frontend/src/types/inbox.ts
@@ -3,6 +3,8 @@ import { InboxId, PrincipalId } from "./id";
export type InboxStatus = "UNREAD" | "READ" | "PINNED";
+export type InboxLevel = "INFO" | "WARNING" | "ERROR";
+
export type Inbox = {
id: InboxId;
@@ -10,6 +12,7 @@ export type Inbox = {
receiver_id: PrincipalId;
activity: Activity;
status: InboxStatus;
+ level: InboxLevel;
};
export type InboxPatch = {
diff --git a/store/inbox.go b/store/inbox.go
index 7eb4f5d2a9..c0033564a4 100644
--- a/store/inbox.go
+++ b/store/inbox.go
@@ -112,13 +112,15 @@ func (s *InboxService) createInbox(ctx context.Context, tx *Tx, create *api.Inbo
INSERT INTO inbox (
receiver_id,
activity_id,
- `+"`status`"+`
+ `+"`status`,"+`
+ `+"`level`"+`
)
- VALUES (?, ?, 'UNREAD')
- RETURNING id, receiver_id, activity_id, `+"`status`"+`
+ VALUES (?, ?, 'UNREAD', ?)
+ RETURNING id, receiver_id, activity_id, `+"`status`, `level`"+`
`,
create.ReceiverId,
create.ActivityId,
+ create.Level,
)
if err != nil {
@@ -134,6 +136,7 @@ func (s *InboxService) createInbox(ctx context.Context, tx *Tx, create *api.Inbo
&inbox.ReceiverId,
&activityId,
&inbox.Status,
+ &inbox.Level,
); err != nil {
return nil, FormatError(err)
}
@@ -165,6 +168,7 @@ func findInboxList(ctx context.Context, tx *Tx, find *api.InboxFind) (_ []*api.I
inbox.id,
receiver_id,
`+"`status`,"+`
+ `+"`level`,"+`
activity.id,
activity.creator_id,
activity.created_ts,
@@ -192,6 +196,7 @@ func findInboxList(ctx context.Context, tx *Tx, find *api.InboxFind) (_ []*api.I
&inbox.ID,
&inbox.ReceiverId,
&inbox.Status,
+ &inbox.Level,
&inbox.Activity.ID,
&inbox.Activity.CreatorId,
&inbox.Activity.CreatedTs,
@@ -225,7 +230,7 @@ func (s *InboxService) patchInbox(ctx context.Context, tx *Tx, patch *api.InboxP
UPDATE inbox
SET `+strings.Join(set, ", ")+`
WHERE id = ?
- RETURNING id, receiver_id, activity_id, `+"`status`"+`
+ RETURNING id, receiver_id, activity_id, `+"`status`, `level`"+`
`,
args...,
)
@@ -242,6 +247,7 @@ func (s *InboxService) patchInbox(ctx context.Context, tx *Tx, patch *api.InboxP
&inbox.ReceiverId,
&activityId,
&inbox.Status,
+ &inbox.Level,
); err != nil {
return nil, FormatError(err)
}
diff --git a/store/migration/10001__init_schema.sql b/store/migration/10001__init_schema.sql
index 23a8b56a66..f9d1f23c9c 100644
--- a/store/migration/10001__init_schema.sql
+++ b/store/migration/10001__init_schema.sql
@@ -823,7 +823,8 @@ 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'))
+ `status` TEXT NOT NULL CHECK (`status` IN ('UNREAD', 'READ', 'PINNED')),
+ `level` TEXT NOT NULL CHECK (`level` IN ('INFO', 'WARNING', 'ERROR'))
);
CREATE INDEX idx_inbox_receiver_id_activity_id_status ON inbox(receiver_id, activity_id, `status`);
diff --git a/store/seed/test/10150__inbox.sql b/store/seed/test/10150__inbox.sql
index 28f2d29c47..3e94d95e94 100644
--- a/store/seed/test/10150__inbox.sql
+++ b/store/seed/test/10150__inbox.sql
@@ -4,176 +4,196 @@ INSERT INTO
id,
receiver_id,
activity_id,
- `status`
+ `status`,
+ `level`
)
VALUES
(
15001,
101,
14001,
- 'READ'
+ 'READ',
+ 'INFO'
);
INSERT INTO
inbox (
receiver_id,
activity_id,
- `status`
+ `status`,
+ `level`
)
VALUES
- (101, 14003, 'UNREAD');
+ (101, 14003, 'UNREAD', 'INFO');
INSERT INTO
inbox (
receiver_id,
activity_id,
- `status`
+ `status`,
+ `level`
)
VALUES
- (101, 14004, 'UNREAD');
+ (101, 14004, 'UNREAD', 'INFO');
INSERT INTO
inbox (
receiver_id,
activity_id,
- `status`
+ `status`,
+ `level`
)
VALUES
- (101, 14005, 'UNREAD');
+ (101, 14005, 'UNREAD', 'INFO');
INSERT INTO
inbox (
receiver_id,
activity_id,
- `status`
+ `status`,
+ `level`
)
VALUES
- (101, 14010, 'UNREAD');
+ (101, 14010, 'UNREAD', 'INFO');
INSERT INTO
inbox (
receiver_id,
activity_id,
- `status`
+ `status`,
+ `level`
)
VALUES
- (101, 14012, 'UNREAD');
+ (101, 14012, 'UNREAD', 'ERROR');
INSERT INTO
inbox (
receiver_id,
activity_id,
- `status`
+ `status`,
+ `level`
)
VALUES
- (101, 14013, 'UNREAD');
+ (101, 14013, 'UNREAD', 'INFO');
-- Inbox for receiver 102
INSERT INTO
inbox (
receiver_id,
activity_id,
- `status`
+ `status`,
+ `level`
)
VALUES
- (102, 14001, 'READ');
+ (102, 14001, 'READ', 'INFO');
INSERT INTO
inbox (
receiver_id,
activity_id,
- `status`
+ `status`,
+ `level`
)
VALUES
- (102, 14002, 'READ');
+ (102, 14002, 'READ', 'INFO');
INSERT INTO
inbox (
receiver_id,
activity_id,
- `status`
+ `status`,
+ `level`
)
VALUES
- (102, 14004, 'READ');
+ (102, 14004, 'READ', 'INFO');
INSERT INTO
inbox (
receiver_id,
activity_id,
- `status`
+ `status`,
+ `level`
)
VALUES
- (102, 14005, 'UNREAD');
+ (102, 14005, 'UNREAD', 'INFO');
INSERT INTO
inbox (
receiver_id,
activity_id,
- `status`
+ `status`,
+ `level`
)
VALUES
- (102, 14006, 'UNREAD');
+ (102, 14006, 'UNREAD', 'INFO');
INSERT INTO
inbox (
receiver_id,
activity_id,
- `status`
+ `status`,
+ `level`
)
VALUES
- (102, 14013, 'UNREAD');
+ (102, 14013, 'UNREAD', 'INFO');
-- Inbox for receiver 103
INSERT INTO
inbox (
receiver_id,
activity_id,
- `status`
+ `status`,
+ `level`
)
VALUES
- (103, 14001, 'READ');
+ (103, 14001, 'READ', 'INFO');
INSERT INTO
inbox (
receiver_id,
activity_id,
- `status`
+ `status`,
+ `level`
)
VALUES
- (103, 14002, 'READ');
+ (103, 14002, 'READ', 'INFO');
INSERT INTO
inbox (
receiver_id,
activity_id,
- `status`
+ `status`,
+ `level`
)
VALUES
- (103, 14003, 'READ');
+ (103, 14003, 'READ', 'INFO');
INSERT INTO
inbox (
receiver_id,
activity_id,
- `status`
+ `status`,
+ `level`
)
VALUES
- (103, 14005, 'READ');
+ (103, 14005, 'READ', 'INFO');
INSERT INTO
inbox (
receiver_id,
activity_id,
- `status`
+ `status`,
+ `level`
)
VALUES
- (103, 14006, 'UNREAD');
+ (103, 14006, 'UNREAD', 'INFO');
INSERT INTO
inbox (
receiver_id,
activity_id,
- `status`
+ `status`,
+ `level`
)
VALUES
- (103, 14013, 'UNREAD');
\ No newline at end of file
+ (103, 14013, 'UNREAD', 'INFO');
\ No newline at end of file