feat: add timezone support for schedule and user runtime (#282)

This commit is contained in:
Yiming Qi
2026-03-26 01:32:02 +08:00
committed by GitHub
parent 3a7f5200ed
commit 03ba13e7e5
51 changed files with 793 additions and 100 deletions
+24 -9
View File
@@ -12,15 +12,16 @@ import (
)
const createBot = `-- name: CreateBot :one
INSERT INTO bots (owner_user_id, display_name, avatar_url, is_active, metadata, status)
VALUES ($1, $2, $3, $4, $5, $6)
RETURNING id, owner_user_id, display_name, avatar_url, is_active, status, max_context_load_time, max_context_tokens, 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
INSERT INTO bots (owner_user_id, display_name, avatar_url, timezone, is_active, metadata, status)
VALUES ($1, $2, $3, $4, $5, $6, $7)
RETURNING id, owner_user_id, display_name, avatar_url, timezone, is_active, status, max_context_load_time, max_context_tokens, 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 {
OwnerUserID pgtype.UUID `json:"owner_user_id"`
DisplayName pgtype.Text `json:"display_name"`
AvatarUrl pgtype.Text `json:"avatar_url"`
Timezone pgtype.Text `json:"timezone"`
IsActive bool `json:"is_active"`
Metadata []byte `json:"metadata"`
Status string `json:"status"`
@@ -31,6 +32,7 @@ type CreateBotRow struct {
OwnerUserID pgtype.UUID `json:"owner_user_id"`
DisplayName pgtype.Text `json:"display_name"`
AvatarUrl pgtype.Text `json:"avatar_url"`
Timezone pgtype.Text `json:"timezone"`
IsActive bool `json:"is_active"`
Status string `json:"status"`
MaxContextLoadTime int32 `json:"max_context_load_time"`
@@ -54,6 +56,7 @@ func (q *Queries) CreateBot(ctx context.Context, arg CreateBotParams) (CreateBot
arg.OwnerUserID,
arg.DisplayName,
arg.AvatarUrl,
arg.Timezone,
arg.IsActive,
arg.Metadata,
arg.Status,
@@ -64,6 +67,7 @@ func (q *Queries) CreateBot(ctx context.Context, arg CreateBotParams) (CreateBot
&i.OwnerUserID,
&i.DisplayName,
&i.AvatarUrl,
&i.Timezone,
&i.IsActive,
&i.Status,
&i.MaxContextLoadTime,
@@ -94,7 +98,7 @@ func (q *Queries) DeleteBotByID(ctx context.Context, id pgtype.UUID) error {
}
const getBotByID = `-- name: GetBotByID :one
SELECT id, owner_user_id, display_name, avatar_url, is_active, status, max_context_load_time, max_context_tokens, language, reasoning_enabled, reasoning_effort, chat_model_id, search_provider_id, memory_provider_id, heartbeat_enabled, heartbeat_interval, heartbeat_prompt, compaction_enabled, compaction_threshold, compaction_model_id, metadata, created_at, updated_at
SELECT id, owner_user_id, display_name, avatar_url, timezone, is_active, status, max_context_load_time, max_context_tokens, language, reasoning_enabled, reasoning_effort, chat_model_id, search_provider_id, memory_provider_id, heartbeat_enabled, heartbeat_interval, heartbeat_prompt, compaction_enabled, compaction_threshold, compaction_model_id, metadata, created_at, updated_at
FROM bots
WHERE id = $1
`
@@ -104,6 +108,7 @@ type GetBotByIDRow struct {
OwnerUserID pgtype.UUID `json:"owner_user_id"`
DisplayName pgtype.Text `json:"display_name"`
AvatarUrl pgtype.Text `json:"avatar_url"`
Timezone pgtype.Text `json:"timezone"`
IsActive bool `json:"is_active"`
Status string `json:"status"`
MaxContextLoadTime int32 `json:"max_context_load_time"`
@@ -133,6 +138,7 @@ func (q *Queries) GetBotByID(ctx context.Context, id pgtype.UUID) (GetBotByIDRow
&i.OwnerUserID,
&i.DisplayName,
&i.AvatarUrl,
&i.Timezone,
&i.IsActive,
&i.Status,
&i.MaxContextLoadTime,
@@ -157,7 +163,7 @@ func (q *Queries) GetBotByID(ctx context.Context, id pgtype.UUID) (GetBotByIDRow
}
const listBotsByOwner = `-- name: ListBotsByOwner :many
SELECT id, owner_user_id, display_name, avatar_url, is_active, status, max_context_load_time, max_context_tokens, 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
SELECT id, owner_user_id, display_name, avatar_url, timezone, is_active, status, max_context_load_time, max_context_tokens, 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
@@ -168,6 +174,7 @@ type ListBotsByOwnerRow struct {
OwnerUserID pgtype.UUID `json:"owner_user_id"`
DisplayName pgtype.Text `json:"display_name"`
AvatarUrl pgtype.Text `json:"avatar_url"`
Timezone pgtype.Text `json:"timezone"`
IsActive bool `json:"is_active"`
Status string `json:"status"`
MaxContextLoadTime int32 `json:"max_context_load_time"`
@@ -200,6 +207,7 @@ func (q *Queries) ListBotsByOwner(ctx context.Context, ownerUserID pgtype.UUID)
&i.OwnerUserID,
&i.DisplayName,
&i.AvatarUrl,
&i.Timezone,
&i.IsActive,
&i.Status,
&i.MaxContextLoadTime,
@@ -272,7 +280,7 @@ UPDATE bots
SET owner_user_id = $2,
updated_at = now()
WHERE id = $1
RETURNING id, owner_user_id, display_name, avatar_url, is_active, status, max_context_load_time, max_context_tokens, 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
RETURNING id, owner_user_id, display_name, avatar_url, timezone, is_active, status, max_context_load_time, max_context_tokens, 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 {
@@ -285,6 +293,7 @@ type UpdateBotOwnerRow struct {
OwnerUserID pgtype.UUID `json:"owner_user_id"`
DisplayName pgtype.Text `json:"display_name"`
AvatarUrl pgtype.Text `json:"avatar_url"`
Timezone pgtype.Text `json:"timezone"`
IsActive bool `json:"is_active"`
Status string `json:"status"`
MaxContextLoadTime int32 `json:"max_context_load_time"`
@@ -311,6 +320,7 @@ func (q *Queries) UpdateBotOwner(ctx context.Context, arg UpdateBotOwnerParams)
&i.OwnerUserID,
&i.DisplayName,
&i.AvatarUrl,
&i.Timezone,
&i.IsActive,
&i.Status,
&i.MaxContextLoadTime,
@@ -335,17 +345,19 @@ const updateBotProfile = `-- name: UpdateBotProfile :one
UPDATE bots
SET display_name = $2,
avatar_url = $3,
is_active = $4,
metadata = $5,
timezone = $4,
is_active = $5,
metadata = $6,
updated_at = now()
WHERE id = $1
RETURNING id, owner_user_id, display_name, avatar_url, is_active, status, max_context_load_time, max_context_tokens, 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
RETURNING id, owner_user_id, display_name, avatar_url, timezone, is_active, status, max_context_load_time, max_context_tokens, 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 {
ID pgtype.UUID `json:"id"`
DisplayName pgtype.Text `json:"display_name"`
AvatarUrl pgtype.Text `json:"avatar_url"`
Timezone pgtype.Text `json:"timezone"`
IsActive bool `json:"is_active"`
Metadata []byte `json:"metadata"`
}
@@ -355,6 +367,7 @@ type UpdateBotProfileRow struct {
OwnerUserID pgtype.UUID `json:"owner_user_id"`
DisplayName pgtype.Text `json:"display_name"`
AvatarUrl pgtype.Text `json:"avatar_url"`
Timezone pgtype.Text `json:"timezone"`
IsActive bool `json:"is_active"`
Status string `json:"status"`
MaxContextLoadTime int32 `json:"max_context_load_time"`
@@ -378,6 +391,7 @@ func (q *Queries) UpdateBotProfile(ctx context.Context, arg UpdateBotProfilePara
arg.ID,
arg.DisplayName,
arg.AvatarUrl,
arg.Timezone,
arg.IsActive,
arg.Metadata,
)
@@ -387,6 +401,7 @@ func (q *Queries) UpdateBotProfile(ctx context.Context, arg UpdateBotProfilePara
&i.OwnerUserID,
&i.DisplayName,
&i.AvatarUrl,
&i.Timezone,
&i.IsActive,
&i.Status,
&i.MaxContextLoadTime,
+1 -1
View File
@@ -511,7 +511,7 @@ WITH updated AS (
SET display_name = $1,
updated_at = now()
WHERE bots.id = $2
RETURNING id, owner_user_id, display_name, avatar_url, is_active, status, max_context_load_time, max_context_tokens, language, reasoning_enabled, reasoning_effort, chat_model_id, search_provider_id, memory_provider_id, heartbeat_enabled, heartbeat_interval, heartbeat_prompt, heartbeat_model_id, compaction_enabled, compaction_threshold, compaction_model_id, title_model_id, tts_model_id, browser_context_id, metadata, created_at, updated_at
RETURNING id, owner_user_id, display_name, avatar_url, timezone, is_active, status, max_context_load_time, max_context_tokens, language, reasoning_enabled, reasoning_effort, chat_model_id, search_provider_id, memory_provider_id, heartbeat_enabled, heartbeat_interval, heartbeat_prompt, heartbeat_model_id, compaction_enabled, compaction_threshold, compaction_model_id, title_model_id, tts_model_id, browser_context_id, metadata, created_at, updated_at
)
SELECT
updated.id AS id,
+2
View File
@@ -13,6 +13,7 @@ type Bot struct {
OwnerUserID pgtype.UUID `json:"owner_user_id"`
DisplayName pgtype.Text `json:"display_name"`
AvatarUrl pgtype.Text `json:"avatar_url"`
Timezone pgtype.Text `json:"timezone"`
IsActive bool `json:"is_active"`
Status string `json:"status"`
MaxContextLoadTime int32 `json:"max_context_load_time"`
@@ -463,6 +464,7 @@ type User struct {
Role string `json:"role"`
DisplayName pgtype.Text `json:"display_name"`
AvatarUrl pgtype.Text `json:"avatar_url"`
Timezone string `json:"timezone"`
DataRoot pgtype.Text `json:"data_root"`
LastLoginAt pgtype.Timestamptz `json:"last_login_at"`
IsActive bool `json:"is_active"`
+28 -13
View File
@@ -37,7 +37,7 @@ SET username = $1,
data_root = $8,
updated_at = now()
WHERE id = $9
RETURNING id, username, email, password_hash, role, display_name, avatar_url, data_root, last_login_at, is_active, metadata, created_at, updated_at
RETURNING id, username, email, password_hash, role, display_name, avatar_url, timezone, data_root, last_login_at, is_active, metadata, created_at, updated_at
`
type CreateAccountParams struct {
@@ -73,6 +73,7 @@ func (q *Queries) CreateAccount(ctx context.Context, arg CreateAccountParams) (U
&i.Role,
&i.DisplayName,
&i.AvatarUrl,
&i.Timezone,
&i.DataRoot,
&i.LastLoginAt,
&i.IsActive,
@@ -86,7 +87,7 @@ func (q *Queries) CreateAccount(ctx context.Context, arg CreateAccountParams) (U
const createUser = `-- name: CreateUser :one
INSERT INTO users (is_active, metadata)
VALUES ($1, $2)
RETURNING id, username, email, password_hash, role, display_name, avatar_url, data_root, last_login_at, is_active, metadata, created_at, updated_at
RETURNING id, username, email, password_hash, role, display_name, avatar_url, timezone, data_root, last_login_at, is_active, metadata, created_at, updated_at
`
type CreateUserParams struct {
@@ -105,6 +106,7 @@ func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (User, e
&i.Role,
&i.DisplayName,
&i.AvatarUrl,
&i.Timezone,
&i.DataRoot,
&i.LastLoginAt,
&i.IsActive,
@@ -116,7 +118,7 @@ func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (User, e
}
const getAccountByIdentity = `-- name: GetAccountByIdentity :one
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 = $1 OR email = $1
SELECT id, username, email, password_hash, role, display_name, avatar_url, timezone, data_root, last_login_at, is_active, metadata, created_at, updated_at FROM users WHERE username = $1 OR email = $1
`
func (q *Queries) GetAccountByIdentity(ctx context.Context, identity pgtype.Text) (User, error) {
@@ -130,6 +132,7 @@ func (q *Queries) GetAccountByIdentity(ctx context.Context, identity pgtype.Text
&i.Role,
&i.DisplayName,
&i.AvatarUrl,
&i.Timezone,
&i.DataRoot,
&i.LastLoginAt,
&i.IsActive,
@@ -141,7 +144,7 @@ func (q *Queries) GetAccountByIdentity(ctx context.Context, identity pgtype.Text
}
const getAccountByUserID = `-- name: GetAccountByUserID :one
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 id = $1
SELECT id, username, email, password_hash, role, display_name, avatar_url, timezone, data_root, last_login_at, is_active, metadata, created_at, updated_at FROM users WHERE id = $1
`
func (q *Queries) GetAccountByUserID(ctx context.Context, userID pgtype.UUID) (User, error) {
@@ -155,6 +158,7 @@ func (q *Queries) GetAccountByUserID(ctx context.Context, userID pgtype.UUID) (U
&i.Role,
&i.DisplayName,
&i.AvatarUrl,
&i.Timezone,
&i.DataRoot,
&i.LastLoginAt,
&i.IsActive,
@@ -166,7 +170,7 @@ func (q *Queries) GetAccountByUserID(ctx context.Context, userID pgtype.UUID) (U
}
const getUserByID = `-- name: GetUserByID :one
SELECT id, username, email, password_hash, role, display_name, avatar_url, data_root, last_login_at, is_active, metadata, created_at, updated_at
SELECT id, username, email, password_hash, role, display_name, avatar_url, timezone, data_root, last_login_at, is_active, metadata, created_at, updated_at
FROM users
WHERE id = $1
`
@@ -182,6 +186,7 @@ func (q *Queries) GetUserByID(ctx context.Context, id pgtype.UUID) (User, error)
&i.Role,
&i.DisplayName,
&i.AvatarUrl,
&i.Timezone,
&i.DataRoot,
&i.LastLoginAt,
&i.IsActive,
@@ -193,7 +198,7 @@ func (q *Queries) GetUserByID(ctx context.Context, id pgtype.UUID) (User, error)
}
const listAccounts = `-- name: ListAccounts :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
SELECT id, username, email, password_hash, role, display_name, avatar_url, timezone, data_root, last_login_at, is_active, metadata, created_at, updated_at FROM users
WHERE username IS NOT NULL
ORDER BY created_at DESC
`
@@ -215,6 +220,7 @@ func (q *Queries) ListAccounts(ctx context.Context) ([]User, error) {
&i.Role,
&i.DisplayName,
&i.AvatarUrl,
&i.Timezone,
&i.DataRoot,
&i.LastLoginAt,
&i.IsActive,
@@ -233,7 +239,7 @@ func (q *Queries) ListAccounts(ctx context.Context) ([]User, error) {
}
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
SELECT id, username, email, password_hash, role, display_name, avatar_url, timezone, data_root, last_login_at, is_active, metadata, created_at, updated_at
FROM users
WHERE username IS NOT NULL
AND (
@@ -268,6 +274,7 @@ func (q *Queries) SearchAccounts(ctx context.Context, arg SearchAccountsParams)
&i.Role,
&i.DisplayName,
&i.AvatarUrl,
&i.Timezone,
&i.DataRoot,
&i.LastLoginAt,
&i.IsActive,
@@ -293,7 +300,7 @@ SET role = $1::user_role,
is_active = $4,
updated_at = now()
WHERE id = $5
RETURNING id, username, email, password_hash, role, display_name, avatar_url, data_root, last_login_at, is_active, metadata, created_at, updated_at
RETURNING id, username, email, password_hash, role, display_name, avatar_url, timezone, data_root, last_login_at, is_active, metadata, created_at, updated_at
`
type UpdateAccountAdminParams struct {
@@ -321,6 +328,7 @@ func (q *Queries) UpdateAccountAdmin(ctx context.Context, arg UpdateAccountAdmin
&i.Role,
&i.DisplayName,
&i.AvatarUrl,
&i.Timezone,
&i.DataRoot,
&i.LastLoginAt,
&i.IsActive,
@@ -336,7 +344,7 @@ UPDATE users
SET last_login_at = now(),
updated_at = now()
WHERE id = $1
RETURNING id, username, email, password_hash, role, display_name, avatar_url, data_root, last_login_at, is_active, metadata, created_at, updated_at
RETURNING id, username, email, password_hash, role, display_name, avatar_url, timezone, data_root, last_login_at, is_active, metadata, created_at, updated_at
`
func (q *Queries) UpdateAccountLastLogin(ctx context.Context, id pgtype.UUID) (User, error) {
@@ -350,6 +358,7 @@ func (q *Queries) UpdateAccountLastLogin(ctx context.Context, id pgtype.UUID) (U
&i.Role,
&i.DisplayName,
&i.AvatarUrl,
&i.Timezone,
&i.DataRoot,
&i.LastLoginAt,
&i.IsActive,
@@ -365,7 +374,7 @@ UPDATE users
SET password_hash = $2,
updated_at = now()
WHERE id = $1
RETURNING id, username, email, password_hash, role, display_name, avatar_url, data_root, last_login_at, is_active, metadata, created_at, updated_at
RETURNING id, username, email, password_hash, role, display_name, avatar_url, timezone, data_root, last_login_at, is_active, metadata, created_at, updated_at
`
type UpdateAccountPasswordParams struct {
@@ -384,6 +393,7 @@ func (q *Queries) UpdateAccountPassword(ctx context.Context, arg UpdateAccountPa
&i.Role,
&i.DisplayName,
&i.AvatarUrl,
&i.Timezone,
&i.DataRoot,
&i.LastLoginAt,
&i.IsActive,
@@ -398,16 +408,18 @@ const updateAccountProfile = `-- name: UpdateAccountProfile :one
UPDATE users
SET display_name = $2,
avatar_url = $3,
is_active = $4,
timezone = $4,
is_active = $5,
updated_at = now()
WHERE id = $1
RETURNING id, username, email, password_hash, role, display_name, avatar_url, data_root, last_login_at, is_active, metadata, created_at, updated_at
RETURNING id, username, email, password_hash, role, display_name, avatar_url, timezone, data_root, last_login_at, is_active, metadata, created_at, updated_at
`
type UpdateAccountProfileParams struct {
ID pgtype.UUID `json:"id"`
DisplayName pgtype.Text `json:"display_name"`
AvatarUrl pgtype.Text `json:"avatar_url"`
Timezone string `json:"timezone"`
IsActive bool `json:"is_active"`
}
@@ -416,6 +428,7 @@ func (q *Queries) UpdateAccountProfile(ctx context.Context, arg UpdateAccountPro
arg.ID,
arg.DisplayName,
arg.AvatarUrl,
arg.Timezone,
arg.IsActive,
)
var i User
@@ -427,6 +440,7 @@ func (q *Queries) UpdateAccountProfile(ctx context.Context, arg UpdateAccountPro
&i.Role,
&i.DisplayName,
&i.AvatarUrl,
&i.Timezone,
&i.DataRoot,
&i.LastLoginAt,
&i.IsActive,
@@ -460,7 +474,7 @@ ON CONFLICT (username) DO UPDATE SET
is_active = EXCLUDED.is_active,
data_root = EXCLUDED.data_root,
updated_at = now()
RETURNING id, username, email, password_hash, role, display_name, avatar_url, data_root, last_login_at, is_active, metadata, created_at, updated_at
RETURNING id, username, email, password_hash, role, display_name, avatar_url, timezone, data_root, last_login_at, is_active, metadata, created_at, updated_at
`
type UpsertAccountByUsernameParams struct {
@@ -496,6 +510,7 @@ func (q *Queries) UpsertAccountByUsername(ctx context.Context, arg UpsertAccount
&i.Role,
&i.DisplayName,
&i.AvatarUrl,
&i.Timezone,
&i.DataRoot,
&i.LastLoginAt,
&i.IsActive,