Skip to content

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

chore(store): use ARRAY TEXT for activity list (#699)

Danny Xu15cfc2060be1
diff --git a/store/migration/10001__init_schema.sql b/store/migration/10001__init_schema.sql
index 22852aa7a3..30e342c1aa 100644
--- a/store/migration/10001__init_schema.sql
+++ b/store/migration/10001__init_schema.sql
@@ -261,7 +261,7 @@ CREATE TABLE project_webhook (
name TEXT NOT NULL,
url TEXT NOT NULL,
-- Comma separated list of activity triggers.
- activity_list TEXT NOT NULL
+ activity_list TEXT ARRAY NOT NULL
);
CREATE INDEX idx_project_webhook_project_id ON project_webhook(project_id);
diff --git a/store/project_webhook.go b/store/project_webhook.go
index edd84c2a38..422091c0bd 100644
--- a/store/project_webhook.go
+++ b/store/project_webhook.go
@@ -146,7 +146,7 @@ func createProjectWebhook(ctx context.Context, tx *sql.Tx, create *api.ProjectWe
create.Type,
create.Name,
create.URL,
- strings.Join(create.ActivityList, ","),
+ create.ActivityList,
)
if err != nil {
@@ -211,7 +211,6 @@ func findProjectWebhookList(ctx context.Context, tx *sql.Tx, find *api.ProjectWe
list := make([]*api.ProjectWebhook, 0)
for rows.Next() {
var projectWebhook api.ProjectWebhook
- var activityList string
if err := rows.Scan(
&projectWebhook.ID,
&projectWebhook.CreatorID,
@@ -222,11 +221,10 @@ func findProjectWebhookList(ctx context.Context, tx *sql.Tx, find *api.ProjectWe
&projectWebhook.Type,
&projectWebhook.Name,
&projectWebhook.URL,
- &activityList,
+ &projectWebhook.ActivityList,
); err != nil {
return nil, FormatError(err)
}
- projectWebhook.ActivityList = strings.Split(activityList, ",")
if v := find.ActivityType; v != nil {
for _, activity := range projectWebhook.ActivityList {
@@ -257,7 +255,8 @@ func patchProjectWebhook(ctx context.Context, tx *sql.Tx, patch *api.ProjectWebh
set, args = append(set, fmt.Sprintf("url = $%d", len(args)+1)), append(args, *v)
}
if v := patch.ActivityList; v != nil {
- set, args = append(set, fmt.Sprintf("activity_list = $%d", len(args)+1)), append(args, *v)
+ activities := strings.Split(*v, ",")
+ set, args = append(set, fmt.Sprintf("activity_list = $%d", len(args)+1)), append(args, activities)
}
args = append(args, patch.ID)
diff --git a/store/seed/test/10041__project_webhook.sql b/store/seed/test/10041__project_webhook.sql
index f5fabeca90..a679f3c7da 100644
--- a/store/seed/test/10041__project_webhook.sql
+++ b/store/seed/test/10041__project_webhook.sql
@@ -19,7 +19,7 @@ VALUES
'bb.plugin.webhook.wecom',
'WeCom',
'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=12345',
- 'bb.issue.create,bb.issue.status.update,bb.pipeline.task.status.update,bb.issue.field.update,bb.issue.comment.create'
+ '{"bb.issue.create", "bb.issue.status.update", "bb.pipeline.task.status.update", "bb.issue.field.update", "bb.issue.comment.create"}'
);
INSERT INTO
@@ -42,7 +42,7 @@ VALUES
'bb.plugin.webhook.dingtalk',
'DingTalk',
'https://oapi.dingtalk.com/robot/send?access_token=12345',
- 'bb.issue.create,bb.issue.status.update,bb.pipeline.task.status.update,bb.issue.field.update,bb.issue.comment.create'
+ '{"bb.issue.create", "bb.issue.status.update", "bb.pipeline.task.status.update", "bb.issue.field.update", "bb.issue.comment.create"}'
);
-- Project 3002 hook
@@ -66,7 +66,7 @@ VALUES
'bb.plugin.webhook.feishu',
'Feishu',
'https://open.feishu.cn/open-apis/bot/v2/hook/12345',
- 'bb.issue.create,bb.issue.status.update,bb.pipeline.task.status.update,bb.issue.field.update,bb.issue.comment.create'
+ '{"bb.issue.create", "bb.issue.status.update", "bb.pipeline.task.status.update", "bb.issue.field.update", "bb.issue.comment.create"}'
);
INSERT INTO
@@ -89,7 +89,7 @@ VALUES
'bb.plugin.webhook.slack',
'Slack',
'https://hooks.slack.com/services/12345',
- 'bb.issue.create,bb.issue.status.update,bb.pipeline.task.status.update,bb.issue.field.update,bb.issue.comment.create'
+ '{"bb.issue.create", "bb.issue.status.update", "bb.pipeline.task.status.update", "bb.issue.field.update", "bb.issue.comment.create"}'
);
-- Project 3003 hook
@@ -113,7 +113,7 @@ VALUES
'bb.plugin.webhook.discord',
'Discord',
'https://discord.com/api/webhooks/12345',
- 'bb.issue.create,bb.issue.status.update,bb.pipeline.task.status.update,bb.issue.field.update,bb.issue.comment.create'
+ '{"bb.issue.create", "bb.issue.status.update", "bb.pipeline.task.status.update", "bb.issue.field.update", "bb.issue.comment.create"}'
);
INSERT INTO
@@ -136,7 +136,7 @@ VALUES
'bb.plugin.webhook.teams',
'Teams',
'https://foo.webhook.office.com/webhookb2/12345',
- 'bb.issue.create,bb.issue.status.update,bb.pipeline.task.status.update,bb.issue.field.update,bb.issue.comment.create'
+ '{"bb.issue.create", "bb.issue.status.update", "bb.pipeline.task.status.update", "bb.issue.field.update", "bb.issue.comment.create"}'
);
ALTER SEQUENCE project_webhook_id_seq RESTART WITH 4107;