mirror of
https://github.com/memohai/Memoh.git
synced 2026-04-27 07:16:19 +09:00
feat(access): add guest chat ACL (#235)
This commit is contained in:
@@ -0,0 +1,415 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: acl.sql
|
||||
|
||||
package sqlc
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const deleteBotACLGuestAllAllowRule = `-- name: DeleteBotACLGuestAllAllowRule :exec
|
||||
DELETE FROM bot_acl_rules
|
||||
WHERE bot_id = $1
|
||||
AND action = 'chat.trigger'
|
||||
AND effect = 'allow'
|
||||
AND subject_kind = 'guest_all'
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteBotACLGuestAllAllowRule(ctx context.Context, botID pgtype.UUID) error {
|
||||
_, err := q.db.Exec(ctx, deleteBotACLGuestAllAllowRule, botID)
|
||||
return err
|
||||
}
|
||||
|
||||
const deleteBotACLRuleByID = `-- name: DeleteBotACLRuleByID :exec
|
||||
DELETE FROM bot_acl_rules
|
||||
WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteBotACLRuleByID(ctx context.Context, id pgtype.UUID) error {
|
||||
_, err := q.db.Exec(ctx, deleteBotACLRuleByID, id)
|
||||
return err
|
||||
}
|
||||
|
||||
const hasBotACLChannelIdentityRule = `-- name: HasBotACLChannelIdentityRule :one
|
||||
SELECT EXISTS (
|
||||
SELECT 1
|
||||
FROM bot_acl_rules
|
||||
WHERE bot_id = $1
|
||||
AND action = 'chat.trigger'
|
||||
AND effect = $2
|
||||
AND subject_kind = 'channel_identity'
|
||||
AND channel_identity_id = $3
|
||||
AND (source_channel IS NULL OR source_channel = $4::text)
|
||||
AND (source_conversation_type IS NULL OR source_conversation_type = $5::text)
|
||||
AND (source_conversation_id IS NULL OR source_conversation_id = $6::text)
|
||||
AND (source_thread_id IS NULL OR source_thread_id = $7::text)
|
||||
) AS matched
|
||||
`
|
||||
|
||||
type HasBotACLChannelIdentityRuleParams struct {
|
||||
BotID pgtype.UUID `json:"bot_id"`
|
||||
Effect string `json:"effect"`
|
||||
ChannelIdentityID pgtype.UUID `json:"channel_identity_id"`
|
||||
SourceChannel pgtype.Text `json:"source_channel"`
|
||||
SourceConversationType pgtype.Text `json:"source_conversation_type"`
|
||||
SourceConversationID pgtype.Text `json:"source_conversation_id"`
|
||||
SourceThreadID pgtype.Text `json:"source_thread_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) HasBotACLChannelIdentityRule(ctx context.Context, arg HasBotACLChannelIdentityRuleParams) (bool, error) {
|
||||
row := q.db.QueryRow(ctx, hasBotACLChannelIdentityRule,
|
||||
arg.BotID,
|
||||
arg.Effect,
|
||||
arg.ChannelIdentityID,
|
||||
arg.SourceChannel,
|
||||
arg.SourceConversationType,
|
||||
arg.SourceConversationID,
|
||||
arg.SourceThreadID,
|
||||
)
|
||||
var matched bool
|
||||
err := row.Scan(&matched)
|
||||
return matched, err
|
||||
}
|
||||
|
||||
const hasBotACLGuestAllAllowRule = `-- name: HasBotACLGuestAllAllowRule :one
|
||||
SELECT EXISTS (
|
||||
SELECT 1
|
||||
FROM bot_acl_rules
|
||||
WHERE bot_id = $1
|
||||
AND action = 'chat.trigger'
|
||||
AND effect = 'allow'
|
||||
AND subject_kind = 'guest_all'
|
||||
) AS allowed
|
||||
`
|
||||
|
||||
func (q *Queries) HasBotACLGuestAllAllowRule(ctx context.Context, botID pgtype.UUID) (bool, error) {
|
||||
row := q.db.QueryRow(ctx, hasBotACLGuestAllAllowRule, botID)
|
||||
var allowed bool
|
||||
err := row.Scan(&allowed)
|
||||
return allowed, err
|
||||
}
|
||||
|
||||
const hasBotACLUserRule = `-- name: HasBotACLUserRule :one
|
||||
SELECT EXISTS (
|
||||
SELECT 1
|
||||
FROM bot_acl_rules
|
||||
WHERE bot_id = $1
|
||||
AND action = 'chat.trigger'
|
||||
AND effect = $2
|
||||
AND subject_kind = 'user'
|
||||
AND user_id = $3
|
||||
AND (source_channel IS NULL OR source_channel = $4::text)
|
||||
AND (source_conversation_type IS NULL OR source_conversation_type = $5::text)
|
||||
AND (source_conversation_id IS NULL OR source_conversation_id = $6::text)
|
||||
AND (source_thread_id IS NULL OR source_thread_id = $7::text)
|
||||
) AS matched
|
||||
`
|
||||
|
||||
type HasBotACLUserRuleParams struct {
|
||||
BotID pgtype.UUID `json:"bot_id"`
|
||||
Effect string `json:"effect"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
SourceChannel pgtype.Text `json:"source_channel"`
|
||||
SourceConversationType pgtype.Text `json:"source_conversation_type"`
|
||||
SourceConversationID pgtype.Text `json:"source_conversation_id"`
|
||||
SourceThreadID pgtype.Text `json:"source_thread_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) HasBotACLUserRule(ctx context.Context, arg HasBotACLUserRuleParams) (bool, error) {
|
||||
row := q.db.QueryRow(ctx, hasBotACLUserRule,
|
||||
arg.BotID,
|
||||
arg.Effect,
|
||||
arg.UserID,
|
||||
arg.SourceChannel,
|
||||
arg.SourceConversationType,
|
||||
arg.SourceConversationID,
|
||||
arg.SourceThreadID,
|
||||
)
|
||||
var matched bool
|
||||
err := row.Scan(&matched)
|
||||
return matched, err
|
||||
}
|
||||
|
||||
const listBotACLSubjectRulesByEffect = `-- name: ListBotACLSubjectRulesByEffect :many
|
||||
SELECT
|
||||
r.id,
|
||||
r.bot_id,
|
||||
r.action,
|
||||
r.effect,
|
||||
r.subject_kind,
|
||||
r.user_id,
|
||||
r.channel_identity_id,
|
||||
r.source_channel,
|
||||
r.source_conversation_type,
|
||||
r.source_conversation_id,
|
||||
r.source_thread_id,
|
||||
r.created_by_user_id,
|
||||
r.created_at,
|
||||
r.updated_at,
|
||||
u.username AS user_username,
|
||||
u.display_name AS user_display_name,
|
||||
u.avatar_url AS user_avatar_url,
|
||||
ci.channel_type,
|
||||
ci.channel_subject_id,
|
||||
ci.display_name AS channel_identity_display_name,
|
||||
ci.avatar_url AS channel_identity_avatar_url,
|
||||
linked.id AS linked_user_id,
|
||||
linked.username AS linked_user_username,
|
||||
linked.display_name AS linked_user_display_name,
|
||||
linked.avatar_url AS linked_user_avatar_url
|
||||
FROM bot_acl_rules r
|
||||
LEFT JOIN users u ON u.id = r.user_id
|
||||
LEFT JOIN channel_identities ci ON ci.id = r.channel_identity_id
|
||||
LEFT JOIN users linked ON linked.id = ci.user_id
|
||||
WHERE r.bot_id = $1
|
||||
AND r.action = 'chat.trigger'
|
||||
AND r.effect = $2
|
||||
AND r.subject_kind IN ('user', 'channel_identity')
|
||||
ORDER BY r.created_at DESC
|
||||
`
|
||||
|
||||
type ListBotACLSubjectRulesByEffectParams struct {
|
||||
BotID pgtype.UUID `json:"bot_id"`
|
||||
Effect string `json:"effect"`
|
||||
}
|
||||
|
||||
type ListBotACLSubjectRulesByEffectRow struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
BotID pgtype.UUID `json:"bot_id"`
|
||||
Action string `json:"action"`
|
||||
Effect string `json:"effect"`
|
||||
SubjectKind string `json:"subject_kind"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
ChannelIdentityID pgtype.UUID `json:"channel_identity_id"`
|
||||
SourceChannel pgtype.Text `json:"source_channel"`
|
||||
SourceConversationType pgtype.Text `json:"source_conversation_type"`
|
||||
SourceConversationID pgtype.Text `json:"source_conversation_id"`
|
||||
SourceThreadID pgtype.Text `json:"source_thread_id"`
|
||||
CreatedByUserID pgtype.UUID `json:"created_by_user_id"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
UserUsername pgtype.Text `json:"user_username"`
|
||||
UserDisplayName pgtype.Text `json:"user_display_name"`
|
||||
UserAvatarUrl pgtype.Text `json:"user_avatar_url"`
|
||||
ChannelType pgtype.Text `json:"channel_type"`
|
||||
ChannelSubjectID pgtype.Text `json:"channel_subject_id"`
|
||||
ChannelIdentityDisplayName pgtype.Text `json:"channel_identity_display_name"`
|
||||
ChannelIdentityAvatarUrl pgtype.Text `json:"channel_identity_avatar_url"`
|
||||
LinkedUserID pgtype.UUID `json:"linked_user_id"`
|
||||
LinkedUserUsername pgtype.Text `json:"linked_user_username"`
|
||||
LinkedUserDisplayName pgtype.Text `json:"linked_user_display_name"`
|
||||
LinkedUserAvatarUrl pgtype.Text `json:"linked_user_avatar_url"`
|
||||
}
|
||||
|
||||
func (q *Queries) ListBotACLSubjectRulesByEffect(ctx context.Context, arg ListBotACLSubjectRulesByEffectParams) ([]ListBotACLSubjectRulesByEffectRow, error) {
|
||||
rows, err := q.db.Query(ctx, listBotACLSubjectRulesByEffect, arg.BotID, arg.Effect)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []ListBotACLSubjectRulesByEffectRow
|
||||
for rows.Next() {
|
||||
var i ListBotACLSubjectRulesByEffectRow
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.BotID,
|
||||
&i.Action,
|
||||
&i.Effect,
|
||||
&i.SubjectKind,
|
||||
&i.UserID,
|
||||
&i.ChannelIdentityID,
|
||||
&i.SourceChannel,
|
||||
&i.SourceConversationType,
|
||||
&i.SourceConversationID,
|
||||
&i.SourceThreadID,
|
||||
&i.CreatedByUserID,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.UserUsername,
|
||||
&i.UserDisplayName,
|
||||
&i.UserAvatarUrl,
|
||||
&i.ChannelType,
|
||||
&i.ChannelSubjectID,
|
||||
&i.ChannelIdentityDisplayName,
|
||||
&i.ChannelIdentityAvatarUrl,
|
||||
&i.LinkedUserID,
|
||||
&i.LinkedUserUsername,
|
||||
&i.LinkedUserDisplayName,
|
||||
&i.LinkedUserAvatarUrl,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const upsertBotACLChannelIdentityRule = `-- name: UpsertBotACLChannelIdentityRule :one
|
||||
INSERT INTO bot_acl_rules (
|
||||
bot_id, action, effect, subject_kind, channel_identity_id,
|
||||
source_channel, source_conversation_type, source_conversation_id, source_thread_id,
|
||||
created_by_user_id
|
||||
)
|
||||
VALUES (
|
||||
$1, 'chat.trigger', $2, 'channel_identity', $3,
|
||||
$5::text,
|
||||
$6::text,
|
||||
$7::text,
|
||||
$8::text,
|
||||
$4
|
||||
)
|
||||
ON CONFLICT ON CONSTRAINT bot_acl_rules_unique_channel_identity
|
||||
DO UPDATE SET
|
||||
created_by_user_id = COALESCE(EXCLUDED.created_by_user_id, bot_acl_rules.created_by_user_id),
|
||||
updated_at = now()
|
||||
RETURNING id, bot_id, action, effect, subject_kind, user_id, channel_identity_id, source_channel, source_conversation_type, source_conversation_id, source_thread_id, created_by_user_id, created_at, updated_at
|
||||
`
|
||||
|
||||
type UpsertBotACLChannelIdentityRuleParams struct {
|
||||
BotID pgtype.UUID `json:"bot_id"`
|
||||
Effect string `json:"effect"`
|
||||
ChannelIdentityID pgtype.UUID `json:"channel_identity_id"`
|
||||
CreatedByUserID pgtype.UUID `json:"created_by_user_id"`
|
||||
SourceChannel pgtype.Text `json:"source_channel"`
|
||||
SourceConversationType pgtype.Text `json:"source_conversation_type"`
|
||||
SourceConversationID pgtype.Text `json:"source_conversation_id"`
|
||||
SourceThreadID pgtype.Text `json:"source_thread_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpsertBotACLChannelIdentityRule(ctx context.Context, arg UpsertBotACLChannelIdentityRuleParams) (BotAclRule, error) {
|
||||
row := q.db.QueryRow(ctx, upsertBotACLChannelIdentityRule,
|
||||
arg.BotID,
|
||||
arg.Effect,
|
||||
arg.ChannelIdentityID,
|
||||
arg.CreatedByUserID,
|
||||
arg.SourceChannel,
|
||||
arg.SourceConversationType,
|
||||
arg.SourceConversationID,
|
||||
arg.SourceThreadID,
|
||||
)
|
||||
var i BotAclRule
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.BotID,
|
||||
&i.Action,
|
||||
&i.Effect,
|
||||
&i.SubjectKind,
|
||||
&i.UserID,
|
||||
&i.ChannelIdentityID,
|
||||
&i.SourceChannel,
|
||||
&i.SourceConversationType,
|
||||
&i.SourceConversationID,
|
||||
&i.SourceThreadID,
|
||||
&i.CreatedByUserID,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const upsertBotACLGuestAllAllowRule = `-- name: UpsertBotACLGuestAllAllowRule :one
|
||||
INSERT INTO bot_acl_rules (bot_id, action, effect, subject_kind, created_by_user_id)
|
||||
VALUES ($1, 'chat.trigger', 'allow', 'guest_all', $2)
|
||||
ON CONFLICT ON CONSTRAINT bot_acl_rules_unique_user
|
||||
DO UPDATE SET
|
||||
created_by_user_id = COALESCE(EXCLUDED.created_by_user_id, bot_acl_rules.created_by_user_id),
|
||||
updated_at = now()
|
||||
RETURNING id, bot_id, action, effect, subject_kind, user_id, channel_identity_id, source_channel, source_conversation_type, source_conversation_id, source_thread_id, created_by_user_id, created_at, updated_at
|
||||
`
|
||||
|
||||
type UpsertBotACLGuestAllAllowRuleParams struct {
|
||||
BotID pgtype.UUID `json:"bot_id"`
|
||||
CreatedByUserID pgtype.UUID `json:"created_by_user_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpsertBotACLGuestAllAllowRule(ctx context.Context, arg UpsertBotACLGuestAllAllowRuleParams) (BotAclRule, error) {
|
||||
row := q.db.QueryRow(ctx, upsertBotACLGuestAllAllowRule, arg.BotID, arg.CreatedByUserID)
|
||||
var i BotAclRule
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.BotID,
|
||||
&i.Action,
|
||||
&i.Effect,
|
||||
&i.SubjectKind,
|
||||
&i.UserID,
|
||||
&i.ChannelIdentityID,
|
||||
&i.SourceChannel,
|
||||
&i.SourceConversationType,
|
||||
&i.SourceConversationID,
|
||||
&i.SourceThreadID,
|
||||
&i.CreatedByUserID,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const upsertBotACLUserRule = `-- name: UpsertBotACLUserRule :one
|
||||
INSERT INTO bot_acl_rules (
|
||||
bot_id, action, effect, subject_kind, user_id,
|
||||
source_channel, source_conversation_type, source_conversation_id, source_thread_id,
|
||||
created_by_user_id
|
||||
)
|
||||
VALUES (
|
||||
$1, 'chat.trigger', $2, 'user', $3,
|
||||
$5::text,
|
||||
$6::text,
|
||||
$7::text,
|
||||
$8::text,
|
||||
$4
|
||||
)
|
||||
ON CONFLICT ON CONSTRAINT bot_acl_rules_unique_user
|
||||
DO UPDATE SET
|
||||
created_by_user_id = COALESCE(EXCLUDED.created_by_user_id, bot_acl_rules.created_by_user_id),
|
||||
updated_at = now()
|
||||
RETURNING id, bot_id, action, effect, subject_kind, user_id, channel_identity_id, source_channel, source_conversation_type, source_conversation_id, source_thread_id, created_by_user_id, created_at, updated_at
|
||||
`
|
||||
|
||||
type UpsertBotACLUserRuleParams struct {
|
||||
BotID pgtype.UUID `json:"bot_id"`
|
||||
Effect string `json:"effect"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
CreatedByUserID pgtype.UUID `json:"created_by_user_id"`
|
||||
SourceChannel pgtype.Text `json:"source_channel"`
|
||||
SourceConversationType pgtype.Text `json:"source_conversation_type"`
|
||||
SourceConversationID pgtype.Text `json:"source_conversation_id"`
|
||||
SourceThreadID pgtype.Text `json:"source_thread_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpsertBotACLUserRule(ctx context.Context, arg UpsertBotACLUserRuleParams) (BotAclRule, error) {
|
||||
row := q.db.QueryRow(ctx, upsertBotACLUserRule,
|
||||
arg.BotID,
|
||||
arg.Effect,
|
||||
arg.UserID,
|
||||
arg.CreatedByUserID,
|
||||
arg.SourceChannel,
|
||||
arg.SourceConversationType,
|
||||
arg.SourceConversationID,
|
||||
arg.SourceThreadID,
|
||||
)
|
||||
var i BotAclRule
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.BotID,
|
||||
&i.Action,
|
||||
&i.Effect,
|
||||
&i.SubjectKind,
|
||||
&i.UserID,
|
||||
&i.ChannelIdentityID,
|
||||
&i.SourceChannel,
|
||||
&i.SourceConversationType,
|
||||
&i.SourceConversationID,
|
||||
&i.SourceThreadID,
|
||||
&i.CreatedByUserID,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
const createBot = `-- name: CreateBot :one
|
||||
INSERT INTO bots (owner_user_id, type, display_name, avatar_url, is_active, metadata, status)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
||||
RETURNING id, owner_user_id, type, display_name, avatar_url, is_active, status, max_context_load_time, max_context_tokens, max_inbox_items, language, allow_guest, reasoning_enabled, reasoning_effort, chat_model_id, search_provider_id, memory_provider_id, heartbeat_enabled, heartbeat_interval, heartbeat_prompt, metadata, created_at, updated_at
|
||||
RETURNING id, owner_user_id, type, display_name, avatar_url, is_active, status, max_context_load_time, max_context_tokens, max_inbox_items, language, reasoning_enabled, reasoning_effort, chat_model_id, search_provider_id, memory_provider_id, heartbeat_enabled, heartbeat_interval, heartbeat_prompt, metadata, created_at, updated_at
|
||||
`
|
||||
|
||||
type CreateBotParams struct {
|
||||
@@ -39,7 +39,6 @@ type CreateBotRow struct {
|
||||
MaxContextTokens int32 `json:"max_context_tokens"`
|
||||
MaxInboxItems int32 `json:"max_inbox_items"`
|
||||
Language string `json:"language"`
|
||||
AllowGuest bool `json:"allow_guest"`
|
||||
ReasoningEnabled bool `json:"reasoning_enabled"`
|
||||
ReasoningEffort string `json:"reasoning_effort"`
|
||||
ChatModelID pgtype.UUID `json:"chat_model_id"`
|
||||
@@ -76,7 +75,6 @@ func (q *Queries) CreateBot(ctx context.Context, arg CreateBotParams) (CreateBot
|
||||
&i.MaxContextTokens,
|
||||
&i.MaxInboxItems,
|
||||
&i.Language,
|
||||
&i.AllowGuest,
|
||||
&i.ReasoningEnabled,
|
||||
&i.ReasoningEffort,
|
||||
&i.ChatModelID,
|
||||
@@ -101,22 +99,8 @@ func (q *Queries) DeleteBotByID(ctx context.Context, id pgtype.UUID) error {
|
||||
return err
|
||||
}
|
||||
|
||||
const deleteBotMember = `-- name: DeleteBotMember :exec
|
||||
DELETE FROM bot_members WHERE bot_id = $1 AND user_id = $2
|
||||
`
|
||||
|
||||
type DeleteBotMemberParams struct {
|
||||
BotID pgtype.UUID `json:"bot_id"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) DeleteBotMember(ctx context.Context, arg DeleteBotMemberParams) error {
|
||||
_, err := q.db.Exec(ctx, deleteBotMember, arg.BotID, arg.UserID)
|
||||
return err
|
||||
}
|
||||
|
||||
const getBotByID = `-- name: GetBotByID :one
|
||||
SELECT id, owner_user_id, type, display_name, avatar_url, is_active, status, max_context_load_time, max_context_tokens, max_inbox_items, language, allow_guest, reasoning_enabled, reasoning_effort, chat_model_id, search_provider_id, memory_provider_id, heartbeat_enabled, heartbeat_interval, heartbeat_prompt, metadata, created_at, updated_at
|
||||
SELECT id, owner_user_id, type, display_name, avatar_url, is_active, status, max_context_load_time, max_context_tokens, max_inbox_items, language, reasoning_enabled, reasoning_effort, chat_model_id, search_provider_id, memory_provider_id, heartbeat_enabled, heartbeat_interval, heartbeat_prompt, metadata, created_at, updated_at
|
||||
FROM bots
|
||||
WHERE id = $1
|
||||
`
|
||||
@@ -133,7 +117,6 @@ type GetBotByIDRow struct {
|
||||
MaxContextTokens int32 `json:"max_context_tokens"`
|
||||
MaxInboxItems int32 `json:"max_inbox_items"`
|
||||
Language string `json:"language"`
|
||||
AllowGuest bool `json:"allow_guest"`
|
||||
ReasoningEnabled bool `json:"reasoning_enabled"`
|
||||
ReasoningEffort string `json:"reasoning_effort"`
|
||||
ChatModelID pgtype.UUID `json:"chat_model_id"`
|
||||
@@ -162,7 +145,6 @@ func (q *Queries) GetBotByID(ctx context.Context, id pgtype.UUID) (GetBotByIDRow
|
||||
&i.MaxContextTokens,
|
||||
&i.MaxInboxItems,
|
||||
&i.Language,
|
||||
&i.AllowGuest,
|
||||
&i.ReasoningEnabled,
|
||||
&i.ReasoningEffort,
|
||||
&i.ChatModelID,
|
||||
@@ -178,142 +160,8 @@ func (q *Queries) GetBotByID(ctx context.Context, id pgtype.UUID) (GetBotByIDRow
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getBotMember = `-- name: GetBotMember :one
|
||||
SELECT bot_id, user_id, role, created_at
|
||||
FROM bot_members
|
||||
WHERE bot_id = $1 AND user_id = $2
|
||||
LIMIT 1
|
||||
`
|
||||
|
||||
type GetBotMemberParams struct {
|
||||
BotID pgtype.UUID `json:"bot_id"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetBotMember(ctx context.Context, arg GetBotMemberParams) (BotMember, error) {
|
||||
row := q.db.QueryRow(ctx, getBotMember, arg.BotID, arg.UserID)
|
||||
var i BotMember
|
||||
err := row.Scan(
|
||||
&i.BotID,
|
||||
&i.UserID,
|
||||
&i.Role,
|
||||
&i.CreatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const listBotMembers = `-- name: ListBotMembers :many
|
||||
SELECT bot_id, user_id, role, created_at
|
||||
FROM bot_members
|
||||
WHERE bot_id = $1
|
||||
ORDER BY created_at DESC
|
||||
`
|
||||
|
||||
func (q *Queries) ListBotMembers(ctx context.Context, botID pgtype.UUID) ([]BotMember, error) {
|
||||
rows, err := q.db.Query(ctx, listBotMembers, botID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []BotMember
|
||||
for rows.Next() {
|
||||
var i BotMember
|
||||
if err := rows.Scan(
|
||||
&i.BotID,
|
||||
&i.UserID,
|
||||
&i.Role,
|
||||
&i.CreatedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listBotsByMember = `-- name: ListBotsByMember :many
|
||||
SELECT b.id, b.owner_user_id, b.type, b.display_name, b.avatar_url, b.is_active, b.status, b.max_context_load_time, b.max_context_tokens, b.max_inbox_items, b.language, b.allow_guest, b.reasoning_enabled, b.reasoning_effort, b.chat_model_id, b.search_provider_id, b.memory_provider_id, b.heartbeat_enabled, b.heartbeat_interval, b.heartbeat_prompt, b.metadata, b.created_at, b.updated_at
|
||||
FROM bots b
|
||||
JOIN bot_members m ON m.bot_id = b.id
|
||||
WHERE m.user_id = $1
|
||||
ORDER BY b.created_at DESC
|
||||
`
|
||||
|
||||
type ListBotsByMemberRow struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
OwnerUserID pgtype.UUID `json:"owner_user_id"`
|
||||
Type string `json:"type"`
|
||||
DisplayName pgtype.Text `json:"display_name"`
|
||||
AvatarUrl pgtype.Text `json:"avatar_url"`
|
||||
IsActive bool `json:"is_active"`
|
||||
Status string `json:"status"`
|
||||
MaxContextLoadTime int32 `json:"max_context_load_time"`
|
||||
MaxContextTokens int32 `json:"max_context_tokens"`
|
||||
MaxInboxItems int32 `json:"max_inbox_items"`
|
||||
Language string `json:"language"`
|
||||
AllowGuest bool `json:"allow_guest"`
|
||||
ReasoningEnabled bool `json:"reasoning_enabled"`
|
||||
ReasoningEffort string `json:"reasoning_effort"`
|
||||
ChatModelID pgtype.UUID `json:"chat_model_id"`
|
||||
SearchProviderID pgtype.UUID `json:"search_provider_id"`
|
||||
MemoryProviderID pgtype.UUID `json:"memory_provider_id"`
|
||||
HeartbeatEnabled bool `json:"heartbeat_enabled"`
|
||||
HeartbeatInterval int32 `json:"heartbeat_interval"`
|
||||
HeartbeatPrompt string `json:"heartbeat_prompt"`
|
||||
Metadata []byte `json:"metadata"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
}
|
||||
|
||||
func (q *Queries) ListBotsByMember(ctx context.Context, userID pgtype.UUID) ([]ListBotsByMemberRow, error) {
|
||||
rows, err := q.db.Query(ctx, listBotsByMember, userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []ListBotsByMemberRow
|
||||
for rows.Next() {
|
||||
var i ListBotsByMemberRow
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.OwnerUserID,
|
||||
&i.Type,
|
||||
&i.DisplayName,
|
||||
&i.AvatarUrl,
|
||||
&i.IsActive,
|
||||
&i.Status,
|
||||
&i.MaxContextLoadTime,
|
||||
&i.MaxContextTokens,
|
||||
&i.MaxInboxItems,
|
||||
&i.Language,
|
||||
&i.AllowGuest,
|
||||
&i.ReasoningEnabled,
|
||||
&i.ReasoningEffort,
|
||||
&i.ChatModelID,
|
||||
&i.SearchProviderID,
|
||||
&i.MemoryProviderID,
|
||||
&i.HeartbeatEnabled,
|
||||
&i.HeartbeatInterval,
|
||||
&i.HeartbeatPrompt,
|
||||
&i.Metadata,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listBotsByOwner = `-- name: ListBotsByOwner :many
|
||||
SELECT id, owner_user_id, type, display_name, avatar_url, is_active, status, max_context_load_time, max_context_tokens, max_inbox_items, language, allow_guest, reasoning_enabled, reasoning_effort, chat_model_id, search_provider_id, memory_provider_id, heartbeat_enabled, heartbeat_interval, heartbeat_prompt, metadata, created_at, updated_at
|
||||
SELECT id, owner_user_id, type, display_name, avatar_url, is_active, status, max_context_load_time, max_context_tokens, max_inbox_items, language, reasoning_enabled, reasoning_effort, chat_model_id, search_provider_id, memory_provider_id, heartbeat_enabled, heartbeat_interval, heartbeat_prompt, metadata, created_at, updated_at
|
||||
FROM bots
|
||||
WHERE owner_user_id = $1
|
||||
ORDER BY created_at DESC
|
||||
@@ -331,7 +179,6 @@ type ListBotsByOwnerRow struct {
|
||||
MaxContextTokens int32 `json:"max_context_tokens"`
|
||||
MaxInboxItems int32 `json:"max_inbox_items"`
|
||||
Language string `json:"language"`
|
||||
AllowGuest bool `json:"allow_guest"`
|
||||
ReasoningEnabled bool `json:"reasoning_enabled"`
|
||||
ReasoningEffort string `json:"reasoning_effort"`
|
||||
ChatModelID pgtype.UUID `json:"chat_model_id"`
|
||||
@@ -366,7 +213,6 @@ func (q *Queries) ListBotsByOwner(ctx context.Context, ownerUserID pgtype.UUID)
|
||||
&i.MaxContextTokens,
|
||||
&i.MaxInboxItems,
|
||||
&i.Language,
|
||||
&i.AllowGuest,
|
||||
&i.ReasoningEnabled,
|
||||
&i.ReasoningEffort,
|
||||
&i.ChatModelID,
|
||||
@@ -434,7 +280,7 @@ UPDATE bots
|
||||
SET owner_user_id = $2,
|
||||
updated_at = now()
|
||||
WHERE id = $1
|
||||
RETURNING id, owner_user_id, type, display_name, avatar_url, is_active, status, max_context_load_time, max_context_tokens, max_inbox_items, language, allow_guest, reasoning_enabled, reasoning_effort, chat_model_id, search_provider_id, memory_provider_id, heartbeat_enabled, heartbeat_interval, heartbeat_prompt, metadata, created_at, updated_at
|
||||
RETURNING id, owner_user_id, type, display_name, avatar_url, is_active, status, max_context_load_time, max_context_tokens, max_inbox_items, language, reasoning_enabled, reasoning_effort, chat_model_id, search_provider_id, memory_provider_id, heartbeat_enabled, heartbeat_interval, heartbeat_prompt, metadata, created_at, updated_at
|
||||
`
|
||||
|
||||
type UpdateBotOwnerParams struct {
|
||||
@@ -454,7 +300,6 @@ type UpdateBotOwnerRow struct {
|
||||
MaxContextTokens int32 `json:"max_context_tokens"`
|
||||
MaxInboxItems int32 `json:"max_inbox_items"`
|
||||
Language string `json:"language"`
|
||||
AllowGuest bool `json:"allow_guest"`
|
||||
ReasoningEnabled bool `json:"reasoning_enabled"`
|
||||
ReasoningEffort string `json:"reasoning_effort"`
|
||||
ChatModelID pgtype.UUID `json:"chat_model_id"`
|
||||
@@ -483,7 +328,6 @@ func (q *Queries) UpdateBotOwner(ctx context.Context, arg UpdateBotOwnerParams)
|
||||
&i.MaxContextTokens,
|
||||
&i.MaxInboxItems,
|
||||
&i.Language,
|
||||
&i.AllowGuest,
|
||||
&i.ReasoningEnabled,
|
||||
&i.ReasoningEffort,
|
||||
&i.ChatModelID,
|
||||
@@ -507,7 +351,7 @@ SET display_name = $2,
|
||||
metadata = $5,
|
||||
updated_at = now()
|
||||
WHERE id = $1
|
||||
RETURNING id, owner_user_id, type, display_name, avatar_url, is_active, status, max_context_load_time, max_context_tokens, max_inbox_items, language, allow_guest, reasoning_enabled, reasoning_effort, chat_model_id, search_provider_id, memory_provider_id, heartbeat_enabled, heartbeat_interval, heartbeat_prompt, metadata, created_at, updated_at
|
||||
RETURNING id, owner_user_id, type, display_name, avatar_url, is_active, status, max_context_load_time, max_context_tokens, max_inbox_items, language, reasoning_enabled, reasoning_effort, chat_model_id, search_provider_id, memory_provider_id, heartbeat_enabled, heartbeat_interval, heartbeat_prompt, metadata, created_at, updated_at
|
||||
`
|
||||
|
||||
type UpdateBotProfileParams struct {
|
||||
@@ -530,7 +374,6 @@ type UpdateBotProfileRow struct {
|
||||
MaxContextTokens int32 `json:"max_context_tokens"`
|
||||
MaxInboxItems int32 `json:"max_inbox_items"`
|
||||
Language string `json:"language"`
|
||||
AllowGuest bool `json:"allow_guest"`
|
||||
ReasoningEnabled bool `json:"reasoning_enabled"`
|
||||
ReasoningEffort string `json:"reasoning_effort"`
|
||||
ChatModelID pgtype.UUID `json:"chat_model_id"`
|
||||
@@ -565,7 +408,6 @@ func (q *Queries) UpdateBotProfile(ctx context.Context, arg UpdateBotProfilePara
|
||||
&i.MaxContextTokens,
|
||||
&i.MaxInboxItems,
|
||||
&i.Language,
|
||||
&i.AllowGuest,
|
||||
&i.ReasoningEnabled,
|
||||
&i.ReasoningEffort,
|
||||
&i.ChatModelID,
|
||||
@@ -597,29 +439,3 @@ func (q *Queries) UpdateBotStatus(ctx context.Context, arg UpdateBotStatusParams
|
||||
_, err := q.db.Exec(ctx, updateBotStatus, arg.ID, arg.Status)
|
||||
return err
|
||||
}
|
||||
|
||||
const upsertBotMember = `-- name: UpsertBotMember :one
|
||||
INSERT INTO bot_members (bot_id, user_id, role)
|
||||
VALUES ($1, $2, $3)
|
||||
ON CONFLICT (bot_id, user_id) DO UPDATE SET
|
||||
role = EXCLUDED.role
|
||||
RETURNING bot_id, user_id, role, created_at
|
||||
`
|
||||
|
||||
type UpsertBotMemberParams struct {
|
||||
BotID pgtype.UUID `json:"bot_id"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
Role string `json:"role"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpsertBotMember(ctx context.Context, arg UpsertBotMemberParams) (BotMember, error) {
|
||||
row := q.db.QueryRow(ctx, upsertBotMember, arg.BotID, arg.UserID, arg.Role)
|
||||
var i BotMember
|
||||
err := row.Scan(
|
||||
&i.BotID,
|
||||
&i.UserID,
|
||||
&i.Role,
|
||||
&i.CreatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
@@ -162,6 +162,86 @@ func (q *Queries) ListChannelIdentitiesByUserID(ctx context.Context, userID pgty
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const searchChannelIdentities = `-- name: SearchChannelIdentities :many
|
||||
SELECT
|
||||
ci.id,
|
||||
ci.user_id,
|
||||
ci.channel_type,
|
||||
ci.channel_subject_id,
|
||||
ci.display_name,
|
||||
ci.avatar_url,
|
||||
ci.metadata,
|
||||
ci.created_at,
|
||||
ci.updated_at,
|
||||
u.username AS linked_username,
|
||||
u.display_name AS linked_display_name,
|
||||
u.avatar_url AS linked_avatar_url
|
||||
FROM channel_identities ci
|
||||
LEFT JOIN users u ON u.id = ci.user_id
|
||||
WHERE
|
||||
$1::text = ''
|
||||
OR ci.channel_type ILIKE '%' || $1::text || '%'
|
||||
OR ci.channel_subject_id ILIKE '%' || $1::text || '%'
|
||||
OR COALESCE(ci.display_name, '') ILIKE '%' || $1::text || '%'
|
||||
OR COALESCE(u.username, '') ILIKE '%' || $1::text || '%'
|
||||
OR COALESCE(u.display_name, '') ILIKE '%' || $1::text || '%'
|
||||
ORDER BY ci.updated_at DESC
|
||||
LIMIT $2
|
||||
`
|
||||
|
||||
type SearchChannelIdentitiesParams struct {
|
||||
Query string `json:"query"`
|
||||
LimitCount int32 `json:"limit_count"`
|
||||
}
|
||||
|
||||
type SearchChannelIdentitiesRow struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
ChannelType string `json:"channel_type"`
|
||||
ChannelSubjectID string `json:"channel_subject_id"`
|
||||
DisplayName pgtype.Text `json:"display_name"`
|
||||
AvatarUrl pgtype.Text `json:"avatar_url"`
|
||||
Metadata []byte `json:"metadata"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
LinkedUsername pgtype.Text `json:"linked_username"`
|
||||
LinkedDisplayName pgtype.Text `json:"linked_display_name"`
|
||||
LinkedAvatarUrl pgtype.Text `json:"linked_avatar_url"`
|
||||
}
|
||||
|
||||
func (q *Queries) SearchChannelIdentities(ctx context.Context, arg SearchChannelIdentitiesParams) ([]SearchChannelIdentitiesRow, error) {
|
||||
rows, err := q.db.Query(ctx, searchChannelIdentities, arg.Query, arg.LimitCount)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []SearchChannelIdentitiesRow
|
||||
for rows.Next() {
|
||||
var i SearchChannelIdentitiesRow
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.UserID,
|
||||
&i.ChannelType,
|
||||
&i.ChannelSubjectID,
|
||||
&i.DisplayName,
|
||||
&i.AvatarUrl,
|
||||
&i.Metadata,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.LinkedUsername,
|
||||
&i.LinkedDisplayName,
|
||||
&i.LinkedAvatarUrl,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const setChannelIdentityLinkedUser = `-- name: SetChannelIdentityLinkedUser :one
|
||||
UPDATE channel_identities
|
||||
SET user_id = $2, updated_at = now()
|
||||
|
||||
@@ -11,58 +11,6 @@ import (
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const addChatParticipant = `-- name: AddChatParticipant :one
|
||||
|
||||
INSERT INTO bot_members (bot_id, user_id, role)
|
||||
VALUES ($1, $2, $3)
|
||||
ON CONFLICT (bot_id, user_id) DO UPDATE SET role = EXCLUDED.role
|
||||
RETURNING bot_id AS chat_id, user_id, role, created_at AS joined_at
|
||||
`
|
||||
|
||||
type AddChatParticipantParams struct {
|
||||
ChatID pgtype.UUID `json:"chat_id"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
Role string `json:"role"`
|
||||
}
|
||||
|
||||
type AddChatParticipantRow struct {
|
||||
ChatID pgtype.UUID `json:"chat_id"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
Role string `json:"role"`
|
||||
JoinedAt pgtype.Timestamptz `json:"joined_at"`
|
||||
}
|
||||
|
||||
// chat_participants
|
||||
func (q *Queries) AddChatParticipant(ctx context.Context, arg AddChatParticipantParams) (AddChatParticipantRow, error) {
|
||||
row := q.db.QueryRow(ctx, addChatParticipant, arg.ChatID, arg.UserID, arg.Role)
|
||||
var i AddChatParticipantRow
|
||||
err := row.Scan(
|
||||
&i.ChatID,
|
||||
&i.UserID,
|
||||
&i.Role,
|
||||
&i.JoinedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const copyParticipantsToChat = `-- name: CopyParticipantsToChat :exec
|
||||
INSERT INTO bot_members (bot_id, user_id, role)
|
||||
SELECT $1, bm.user_id, bm.role
|
||||
FROM bot_members bm
|
||||
WHERE bm.bot_id = $2
|
||||
ON CONFLICT (bot_id, user_id) DO NOTHING
|
||||
`
|
||||
|
||||
type CopyParticipantsToChatParams struct {
|
||||
ChatID2 pgtype.UUID `json:"chat_id_2"`
|
||||
ChatID pgtype.UUID `json:"chat_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) CopyParticipantsToChat(ctx context.Context, arg CopyParticipantsToChatParams) error {
|
||||
_, err := q.db.Exec(ctx, copyParticipantsToChat, arg.ChatID2, arg.ChatID)
|
||||
return err
|
||||
}
|
||||
|
||||
const createChat = `-- name: CreateChat :one
|
||||
SELECT
|
||||
b.id AS id,
|
||||
@@ -191,23 +139,9 @@ func (q *Queries) GetChatByID(ctx context.Context, id pgtype.UUID) (GetChatByIDR
|
||||
}
|
||||
|
||||
const getChatParticipant = `-- name: GetChatParticipant :one
|
||||
WITH owner_participant AS (
|
||||
SELECT b.id AS chat_id, b.owner_user_id AS user_id, 'owner'::text AS role, b.created_at AS joined_at
|
||||
FROM bots b
|
||||
WHERE b.id = $1 AND b.owner_user_id = $2
|
||||
),
|
||||
member_participant AS (
|
||||
SELECT bm.bot_id AS chat_id, bm.user_id, bm.role, bm.created_at AS joined_at
|
||||
FROM bot_members bm
|
||||
WHERE bm.bot_id = $1 AND bm.user_id = $2
|
||||
)
|
||||
SELECT chat_id, user_id, role, joined_at
|
||||
FROM (
|
||||
SELECT chat_id, user_id, role, joined_at FROM owner_participant
|
||||
UNION ALL
|
||||
SELECT chat_id, user_id, role, joined_at FROM member_participant
|
||||
) p
|
||||
ORDER BY CASE WHEN role = 'owner' THEN 0 ELSE 1 END
|
||||
SELECT b.id AS chat_id, b.owner_user_id AS user_id, 'owner'::text AS role, b.created_at AS joined_at
|
||||
FROM bots b
|
||||
WHERE b.id = $1 AND b.owner_user_id = $2
|
||||
LIMIT 1
|
||||
`
|
||||
|
||||
@@ -238,21 +172,17 @@ func (q *Queries) GetChatParticipant(ctx context.Context, arg GetChatParticipant
|
||||
const getChatReadAccessByUser = `-- name: GetChatReadAccessByUser :one
|
||||
SELECT
|
||||
'participant'::text AS access_mode,
|
||||
(CASE
|
||||
WHEN b.owner_user_id = $1 THEN 'owner'
|
||||
ELSE COALESCE(bm.role, ''::text)
|
||||
END)::text AS participant_role,
|
||||
'owner'::text AS participant_role,
|
||||
NULL::timestamptz AS last_observed_at
|
||||
FROM bots b
|
||||
LEFT JOIN bot_members bm ON bm.bot_id = b.id AND bm.user_id = $1
|
||||
WHERE b.id = $2
|
||||
AND (b.owner_user_id = $1 OR bm.user_id IS NOT NULL)
|
||||
WHERE b.id = $1
|
||||
AND b.owner_user_id = $2
|
||||
LIMIT 1
|
||||
`
|
||||
|
||||
type GetChatReadAccessByUserParams struct {
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
ChatID pgtype.UUID `json:"chat_id"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
}
|
||||
|
||||
type GetChatReadAccessByUserRow struct {
|
||||
@@ -262,7 +192,7 @@ type GetChatReadAccessByUserRow struct {
|
||||
}
|
||||
|
||||
func (q *Queries) GetChatReadAccessByUser(ctx context.Context, arg GetChatReadAccessByUserParams) (GetChatReadAccessByUserRow, error) {
|
||||
row := q.db.QueryRow(ctx, getChatReadAccessByUser, arg.UserID, arg.ChatID)
|
||||
row := q.db.QueryRow(ctx, getChatReadAccessByUser, arg.ChatID, arg.UserID)
|
||||
var i GetChatReadAccessByUserRow
|
||||
err := row.Scan(&i.AccessMode, &i.ParticipantRole, &i.LastObservedAt)
|
||||
return i, err
|
||||
@@ -292,23 +222,9 @@ func (q *Queries) GetChatSettings(ctx context.Context, id pgtype.UUID) (GetChatS
|
||||
}
|
||||
|
||||
const listChatParticipants = `-- name: ListChatParticipants :many
|
||||
WITH owner_participant AS (
|
||||
SELECT b.id AS chat_id, b.owner_user_id AS user_id, 'owner'::text AS role, b.created_at AS joined_at
|
||||
FROM bots b
|
||||
WHERE b.id = $1
|
||||
),
|
||||
member_participant AS (
|
||||
SELECT bm.bot_id AS chat_id, bm.user_id, bm.role, bm.created_at AS joined_at
|
||||
FROM bot_members bm
|
||||
WHERE bm.bot_id = $1
|
||||
AND bm.user_id <> (SELECT owner_user_id FROM bots WHERE id = $1)
|
||||
)
|
||||
SELECT chat_id, user_id, role, joined_at
|
||||
FROM (
|
||||
SELECT chat_id, user_id, role, joined_at FROM owner_participant
|
||||
UNION ALL
|
||||
SELECT chat_id, user_id, role, joined_at FROM member_participant
|
||||
) p
|
||||
SELECT b.id AS chat_id, b.owner_user_id AS user_id, 'owner'::text AS role, b.created_at AS joined_at
|
||||
FROM bots b
|
||||
WHERE b.id = $1
|
||||
ORDER BY joined_at ASC
|
||||
`
|
||||
|
||||
@@ -357,16 +273,15 @@ SELECT
|
||||
b.created_at,
|
||||
b.updated_at
|
||||
FROM bots b
|
||||
LEFT JOIN bot_members bm ON bm.bot_id = b.id AND bm.user_id = $1
|
||||
LEFT JOIN models chat_models ON chat_models.id = b.chat_model_id
|
||||
WHERE b.id = $2
|
||||
AND (b.owner_user_id = $1 OR bm.user_id IS NOT NULL)
|
||||
WHERE b.id = $1
|
||||
AND b.owner_user_id = $2
|
||||
ORDER BY b.updated_at DESC
|
||||
`
|
||||
|
||||
type ListChatsByBotAndUserParams struct {
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
BotID pgtype.UUID `json:"bot_id"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
}
|
||||
|
||||
type ListChatsByBotAndUserRow struct {
|
||||
@@ -383,7 +298,7 @@ type ListChatsByBotAndUserRow struct {
|
||||
}
|
||||
|
||||
func (q *Queries) ListChatsByBotAndUser(ctx context.Context, arg ListChatsByBotAndUserParams) ([]ListChatsByBotAndUserRow, error) {
|
||||
rows, err := q.db.Query(ctx, listChatsByBotAndUser, arg.UserID, arg.BotID)
|
||||
rows, err := q.db.Query(ctx, listChatsByBotAndUser, arg.BotID, arg.UserID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -494,10 +409,9 @@ SELECT
|
||||
END)::text AS participant_role,
|
||||
NULL::timestamptz AS last_observed_at
|
||||
FROM bots b
|
||||
LEFT JOIN bot_members bm ON bm.bot_id = b.id AND bm.user_id = $1
|
||||
LEFT JOIN models chat_models ON chat_models.id = b.chat_model_id
|
||||
WHERE b.id = $2
|
||||
AND (b.owner_user_id = $1 OR bm.user_id IS NOT NULL)
|
||||
AND b.owner_user_id = $1
|
||||
ORDER BY b.updated_at DESC
|
||||
`
|
||||
|
||||
@@ -557,10 +471,13 @@ func (q *Queries) ListVisibleChatsByBotAndUser(ctx context.Context, arg ListVisi
|
||||
}
|
||||
|
||||
const removeChatParticipant = `-- name: RemoveChatParticipant :exec
|
||||
DELETE FROM bot_members
|
||||
WHERE bot_id = $1
|
||||
AND user_id = $2
|
||||
AND user_id <> (SELECT owner_user_id FROM bots WHERE id = $1)
|
||||
SELECT 1
|
||||
WHERE EXISTS (
|
||||
SELECT 1
|
||||
FROM bots b
|
||||
WHERE b.id = $1
|
||||
AND b.owner_user_id = $2
|
||||
)
|
||||
`
|
||||
|
||||
type RemoveChatParticipantParams struct {
|
||||
@@ -590,7 +507,7 @@ WITH updated AS (
|
||||
SET display_name = $1,
|
||||
updated_at = now()
|
||||
WHERE bots.id = $2
|
||||
RETURNING id, owner_user_id, type, display_name, avatar_url, is_active, status, max_context_load_time, max_context_tokens, language, allow_guest, reasoning_enabled, reasoning_effort, max_inbox_items, chat_model_id, search_provider_id, memory_provider_id, heartbeat_enabled, heartbeat_interval, heartbeat_prompt, heartbeat_model_id, tts_model_id, browser_context_id, metadata, created_at, updated_at
|
||||
RETURNING id, owner_user_id, type, display_name, avatar_url, is_active, status, max_context_load_time, max_context_tokens, language, reasoning_enabled, reasoning_effort, max_inbox_items, chat_model_id, search_provider_id, memory_provider_id, heartbeat_enabled, heartbeat_interval, heartbeat_prompt, heartbeat_model_id, tts_model_id, browser_context_id, metadata, created_at, updated_at
|
||||
)
|
||||
SELECT
|
||||
updated.id AS id,
|
||||
|
||||
@@ -543,3 +543,69 @@ func (q *Queries) ListMessagesSince(ctx context.Context, arg ListMessagesSincePa
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listObservedConversationsByChannelIdentity = `-- name: ListObservedConversationsByChannelIdentity :many
|
||||
SELECT
|
||||
r.id AS route_id,
|
||||
r.channel_type AS channel,
|
||||
COALESCE(r.conversation_type, '') AS conversation_type,
|
||||
r.external_conversation_id AS conversation_id,
|
||||
COALESCE(r.external_thread_id, '') AS thread_id,
|
||||
COALESCE(r.metadata->>'conversation_name', '')::text AS conversation_name,
|
||||
MAX(m.created_at)::timestamptz AS last_observed_at
|
||||
FROM bot_history_messages m
|
||||
JOIN bot_channel_routes r ON r.id = m.route_id
|
||||
WHERE m.bot_id = $1
|
||||
AND m.sender_channel_identity_id = $2
|
||||
GROUP BY
|
||||
r.id,
|
||||
r.channel_type,
|
||||
r.conversation_type,
|
||||
r.external_conversation_id,
|
||||
r.external_thread_id,
|
||||
r.metadata
|
||||
ORDER BY MAX(m.created_at) DESC
|
||||
`
|
||||
|
||||
type ListObservedConversationsByChannelIdentityParams struct {
|
||||
BotID pgtype.UUID `json:"bot_id"`
|
||||
ChannelIdentityID pgtype.UUID `json:"channel_identity_id"`
|
||||
}
|
||||
|
||||
type ListObservedConversationsByChannelIdentityRow struct {
|
||||
RouteID pgtype.UUID `json:"route_id"`
|
||||
Channel string `json:"channel"`
|
||||
ConversationType string `json:"conversation_type"`
|
||||
ConversationID string `json:"conversation_id"`
|
||||
ThreadID string `json:"thread_id"`
|
||||
ConversationName string `json:"conversation_name"`
|
||||
LastObservedAt pgtype.Timestamptz `json:"last_observed_at"`
|
||||
}
|
||||
|
||||
func (q *Queries) ListObservedConversationsByChannelIdentity(ctx context.Context, arg ListObservedConversationsByChannelIdentityParams) ([]ListObservedConversationsByChannelIdentityRow, error) {
|
||||
rows, err := q.db.Query(ctx, listObservedConversationsByChannelIdentity, arg.BotID, arg.ChannelIdentityID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []ListObservedConversationsByChannelIdentityRow
|
||||
for rows.Next() {
|
||||
var i ListObservedConversationsByChannelIdentityRow
|
||||
if err := rows.Scan(
|
||||
&i.RouteID,
|
||||
&i.Channel,
|
||||
&i.ConversationType,
|
||||
&i.ConversationID,
|
||||
&i.ThreadID,
|
||||
&i.ConversationName,
|
||||
&i.LastObservedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
+17
-18
@@ -19,7 +19,6 @@ type Bot struct {
|
||||
MaxContextLoadTime int32 `json:"max_context_load_time"`
|
||||
MaxContextTokens int32 `json:"max_context_tokens"`
|
||||
Language string `json:"language"`
|
||||
AllowGuest bool `json:"allow_guest"`
|
||||
ReasoningEnabled bool `json:"reasoning_enabled"`
|
||||
ReasoningEffort string `json:"reasoning_effort"`
|
||||
MaxInboxItems int32 `json:"max_inbox_items"`
|
||||
@@ -37,6 +36,23 @@ type Bot struct {
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
}
|
||||
|
||||
type BotAclRule struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
BotID pgtype.UUID `json:"bot_id"`
|
||||
Action string `json:"action"`
|
||||
Effect string `json:"effect"`
|
||||
SubjectKind string `json:"subject_kind"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
ChannelIdentityID pgtype.UUID `json:"channel_identity_id"`
|
||||
SourceChannel pgtype.Text `json:"source_channel"`
|
||||
SourceConversationType pgtype.Text `json:"source_conversation_type"`
|
||||
SourceConversationID pgtype.Text `json:"source_conversation_id"`
|
||||
SourceThreadID pgtype.Text `json:"source_thread_id"`
|
||||
CreatedByUserID pgtype.UUID `json:"created_by_user_id"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
}
|
||||
|
||||
type BotChannelConfig struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
BotID pgtype.UUID `json:"bot_id"`
|
||||
@@ -129,23 +145,6 @@ type BotInbox struct {
|
||||
ReadAt pgtype.Timestamptz `json:"read_at"`
|
||||
}
|
||||
|
||||
type BotMember struct {
|
||||
BotID pgtype.UUID `json:"bot_id"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
Role string `json:"role"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
}
|
||||
|
||||
type BotPreauthKey struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
BotID pgtype.UUID `json:"bot_id"`
|
||||
Token string `json:"token"`
|
||||
IssuedByUserID pgtype.UUID `json:"issued_by_user_id"`
|
||||
ExpiresAt pgtype.Timestamptz `json:"expires_at"`
|
||||
UsedAt pgtype.Timestamptz `json:"used_at"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
}
|
||||
|
||||
type BotStorageBinding struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
BotID pgtype.UUID `json:"bot_id"`
|
||||
|
||||
@@ -1,91 +0,0 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: preauth.sql
|
||||
|
||||
package sqlc
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const createBotPreauthKey = `-- name: CreateBotPreauthKey :one
|
||||
INSERT INTO bot_preauth_keys (bot_id, token, issued_by_user_id, expires_at)
|
||||
VALUES ($1, $2, $3, $4)
|
||||
RETURNING id, bot_id, token, issued_by_user_id, expires_at, used_at, created_at
|
||||
`
|
||||
|
||||
type CreateBotPreauthKeyParams struct {
|
||||
BotID pgtype.UUID `json:"bot_id"`
|
||||
Token string `json:"token"`
|
||||
IssuedByUserID pgtype.UUID `json:"issued_by_user_id"`
|
||||
ExpiresAt pgtype.Timestamptz `json:"expires_at"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateBotPreauthKey(ctx context.Context, arg CreateBotPreauthKeyParams) (BotPreauthKey, error) {
|
||||
row := q.db.QueryRow(ctx, createBotPreauthKey,
|
||||
arg.BotID,
|
||||
arg.Token,
|
||||
arg.IssuedByUserID,
|
||||
arg.ExpiresAt,
|
||||
)
|
||||
var i BotPreauthKey
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.BotID,
|
||||
&i.Token,
|
||||
&i.IssuedByUserID,
|
||||
&i.ExpiresAt,
|
||||
&i.UsedAt,
|
||||
&i.CreatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getBotPreauthKey = `-- name: GetBotPreauthKey :one
|
||||
SELECT id, bot_id, token, issued_by_user_id, expires_at, used_at, created_at
|
||||
FROM bot_preauth_keys
|
||||
WHERE token = $1
|
||||
AND used_at IS NULL
|
||||
AND (expires_at IS NULL OR expires_at > now())
|
||||
LIMIT 1
|
||||
`
|
||||
|
||||
func (q *Queries) GetBotPreauthKey(ctx context.Context, token string) (BotPreauthKey, error) {
|
||||
row := q.db.QueryRow(ctx, getBotPreauthKey, token)
|
||||
var i BotPreauthKey
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.BotID,
|
||||
&i.Token,
|
||||
&i.IssuedByUserID,
|
||||
&i.ExpiresAt,
|
||||
&i.UsedAt,
|
||||
&i.CreatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const markBotPreauthKeyUsed = `-- name: MarkBotPreauthKeyUsed :one
|
||||
UPDATE bot_preauth_keys
|
||||
SET used_at = now()
|
||||
WHERE id = $1
|
||||
RETURNING id, bot_id, token, issued_by_user_id, expires_at, used_at, created_at
|
||||
`
|
||||
|
||||
func (q *Queries) MarkBotPreauthKeyUsed(ctx context.Context, id pgtype.UUID) (BotPreauthKey, error) {
|
||||
row := q.db.QueryRow(ctx, markBotPreauthKeyUsed, id)
|
||||
var i BotPreauthKey
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.BotID,
|
||||
&i.Token,
|
||||
&i.IssuedByUserID,
|
||||
&i.ExpiresAt,
|
||||
&i.UsedAt,
|
||||
&i.CreatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@@ -17,7 +17,6 @@ SET max_context_load_time = 1440,
|
||||
max_context_tokens = 0,
|
||||
max_inbox_items = 50,
|
||||
language = 'auto',
|
||||
allow_guest = false,
|
||||
reasoning_enabled = false,
|
||||
reasoning_effort = 'medium',
|
||||
heartbeat_enabled = false,
|
||||
@@ -45,7 +44,6 @@ SELECT
|
||||
bots.max_context_tokens,
|
||||
bots.max_inbox_items,
|
||||
bots.language,
|
||||
bots.allow_guest,
|
||||
bots.reasoning_enabled,
|
||||
bots.reasoning_effort,
|
||||
bots.heartbeat_enabled,
|
||||
@@ -73,7 +71,6 @@ type GetSettingsByBotIDRow struct {
|
||||
MaxContextTokens int32 `json:"max_context_tokens"`
|
||||
MaxInboxItems int32 `json:"max_inbox_items"`
|
||||
Language string `json:"language"`
|
||||
AllowGuest bool `json:"allow_guest"`
|
||||
ReasoningEnabled bool `json:"reasoning_enabled"`
|
||||
ReasoningEffort string `json:"reasoning_effort"`
|
||||
HeartbeatEnabled bool `json:"heartbeat_enabled"`
|
||||
@@ -96,7 +93,6 @@ func (q *Queries) GetSettingsByBotID(ctx context.Context, id pgtype.UUID) (GetSe
|
||||
&i.MaxContextTokens,
|
||||
&i.MaxInboxItems,
|
||||
&i.Language,
|
||||
&i.AllowGuest,
|
||||
&i.ReasoningEnabled,
|
||||
&i.ReasoningEffort,
|
||||
&i.HeartbeatEnabled,
|
||||
@@ -119,21 +115,20 @@ WITH updated AS (
|
||||
max_context_tokens = $2,
|
||||
max_inbox_items = $3,
|
||||
language = $4,
|
||||
allow_guest = $5,
|
||||
reasoning_enabled = $6,
|
||||
reasoning_effort = $7,
|
||||
heartbeat_enabled = $8,
|
||||
heartbeat_interval = $9,
|
||||
heartbeat_prompt = $10,
|
||||
chat_model_id = COALESCE($11::uuid, bots.chat_model_id),
|
||||
heartbeat_model_id = COALESCE($12::uuid, bots.heartbeat_model_id),
|
||||
search_provider_id = COALESCE($13::uuid, bots.search_provider_id),
|
||||
memory_provider_id = COALESCE($14::uuid, bots.memory_provider_id),
|
||||
tts_model_id = COALESCE($15::uuid, bots.tts_model_id),
|
||||
browser_context_id = COALESCE($16::uuid, bots.browser_context_id),
|
||||
reasoning_enabled = $5,
|
||||
reasoning_effort = $6,
|
||||
heartbeat_enabled = $7,
|
||||
heartbeat_interval = $8,
|
||||
heartbeat_prompt = $9,
|
||||
chat_model_id = COALESCE($10::uuid, bots.chat_model_id),
|
||||
heartbeat_model_id = COALESCE($11::uuid, bots.heartbeat_model_id),
|
||||
search_provider_id = COALESCE($12::uuid, bots.search_provider_id),
|
||||
memory_provider_id = COALESCE($13::uuid, bots.memory_provider_id),
|
||||
tts_model_id = COALESCE($14::uuid, bots.tts_model_id),
|
||||
browser_context_id = COALESCE($15::uuid, bots.browser_context_id),
|
||||
updated_at = now()
|
||||
WHERE bots.id = $17
|
||||
RETURNING bots.id, bots.max_context_load_time, bots.max_context_tokens, bots.max_inbox_items, bots.language, bots.allow_guest, bots.reasoning_enabled, bots.reasoning_effort, bots.heartbeat_enabled, bots.heartbeat_interval, bots.heartbeat_prompt, bots.chat_model_id, bots.heartbeat_model_id, bots.search_provider_id, bots.memory_provider_id, bots.tts_model_id, bots.browser_context_id
|
||||
WHERE bots.id = $16
|
||||
RETURNING bots.id, bots.max_context_load_time, bots.max_context_tokens, bots.max_inbox_items, bots.language, bots.reasoning_enabled, bots.reasoning_effort, bots.heartbeat_enabled, bots.heartbeat_interval, bots.heartbeat_prompt, bots.chat_model_id, bots.heartbeat_model_id, bots.search_provider_id, bots.memory_provider_id, bots.tts_model_id, bots.browser_context_id
|
||||
)
|
||||
SELECT
|
||||
updated.id AS bot_id,
|
||||
@@ -141,7 +136,6 @@ SELECT
|
||||
updated.max_context_tokens,
|
||||
updated.max_inbox_items,
|
||||
updated.language,
|
||||
updated.allow_guest,
|
||||
updated.reasoning_enabled,
|
||||
updated.reasoning_effort,
|
||||
updated.heartbeat_enabled,
|
||||
@@ -167,7 +161,6 @@ type UpsertBotSettingsParams struct {
|
||||
MaxContextTokens int32 `json:"max_context_tokens"`
|
||||
MaxInboxItems int32 `json:"max_inbox_items"`
|
||||
Language string `json:"language"`
|
||||
AllowGuest bool `json:"allow_guest"`
|
||||
ReasoningEnabled bool `json:"reasoning_enabled"`
|
||||
ReasoningEffort string `json:"reasoning_effort"`
|
||||
HeartbeatEnabled bool `json:"heartbeat_enabled"`
|
||||
@@ -188,7 +181,6 @@ type UpsertBotSettingsRow struct {
|
||||
MaxContextTokens int32 `json:"max_context_tokens"`
|
||||
MaxInboxItems int32 `json:"max_inbox_items"`
|
||||
Language string `json:"language"`
|
||||
AllowGuest bool `json:"allow_guest"`
|
||||
ReasoningEnabled bool `json:"reasoning_enabled"`
|
||||
ReasoningEffort string `json:"reasoning_effort"`
|
||||
HeartbeatEnabled bool `json:"heartbeat_enabled"`
|
||||
@@ -208,7 +200,6 @@ func (q *Queries) UpsertBotSettings(ctx context.Context, arg UpsertBotSettingsPa
|
||||
arg.MaxContextTokens,
|
||||
arg.MaxInboxItems,
|
||||
arg.Language,
|
||||
arg.AllowGuest,
|
||||
arg.ReasoningEnabled,
|
||||
arg.ReasoningEffort,
|
||||
arg.HeartbeatEnabled,
|
||||
@@ -229,7 +220,6 @@ func (q *Queries) UpsertBotSettings(ctx context.Context, arg UpsertBotSettingsPa
|
||||
&i.MaxContextTokens,
|
||||
&i.MaxInboxItems,
|
||||
&i.Language,
|
||||
&i.AllowGuest,
|
||||
&i.ReasoningEnabled,
|
||||
&i.ReasoningEffort,
|
||||
&i.HeartbeatEnabled,
|
||||
|
||||
@@ -232,6 +232,59 @@ func (q *Queries) ListAccounts(ctx context.Context) ([]User, error) {
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const searchAccounts = `-- name: SearchAccounts :many
|
||||
SELECT id, username, email, password_hash, role, display_name, avatar_url, data_root, last_login_at, is_active, metadata, created_at, updated_at
|
||||
FROM users
|
||||
WHERE username IS NOT NULL
|
||||
AND (
|
||||
$1::text = ''
|
||||
OR username ILIKE '%' || $1::text || '%'
|
||||
OR COALESCE(display_name, '') ILIKE '%' || $1::text || '%'
|
||||
OR COALESCE(email, '') ILIKE '%' || $1::text || '%'
|
||||
)
|
||||
ORDER BY last_login_at DESC NULLS LAST, created_at DESC
|
||||
LIMIT $2
|
||||
`
|
||||
|
||||
type SearchAccountsParams struct {
|
||||
Query string `json:"query"`
|
||||
LimitCount int32 `json:"limit_count"`
|
||||
}
|
||||
|
||||
func (q *Queries) SearchAccounts(ctx context.Context, arg SearchAccountsParams) ([]User, error) {
|
||||
rows, err := q.db.Query(ctx, searchAccounts, arg.Query, arg.LimitCount)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []User
|
||||
for rows.Next() {
|
||||
var i User
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.Username,
|
||||
&i.Email,
|
||||
&i.PasswordHash,
|
||||
&i.Role,
|
||||
&i.DisplayName,
|
||||
&i.AvatarUrl,
|
||||
&i.DataRoot,
|
||||
&i.LastLoginAt,
|
||||
&i.IsActive,
|
||||
&i.Metadata,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const updateAccountAdmin = `-- name: UpdateAccountAdmin :one
|
||||
UPDATE users
|
||||
SET role = $1::user_role,
|
||||
|
||||
Reference in New Issue
Block a user