mirror of
https://github.com/memohai/Memoh.git
synced 2026-04-27 07:16:19 +09:00
refactor(core): codebase quality cleanup
- Remove user-level model settings (chat_model_id, memory_model_id, embedding_model_id, max_context_load_time, language) from users table - Merge migration 0002 into 0001, remove compatibility migrations - Delete dead conversation/resolver.go (1177 lines, only flow/resolver.go used) - Remove type aliases (Chat=Conversation, types_alias.go) - Fix SQL: remove AND false stub, fix UpdateChatTitle model_id, reset model IDs in DeleteSettings, add preauth expiry filter, add ListMessages limit, remove 10 dead queries - Extract shared handler helpers (RequireChannelIdentityID, AuthorizeBotAccess) - Rename internal/router to internal/channel/inbound - Fix identity confusion: remove UserID->ChannelIdentityID fallbacks - Fix all _ = var patterns with proper error logging - Fix error propagation: storeMessages, rescheduleJob, botContainerID - Fix naming: ModelId->ModelID, active->is_active, Duration semantic fix - Remove dead code: mcpService, ReplyTarget, callMCPServer, sshShellQuote, buildSessionMetadata, ChatRequest.Language, TriggerPayload.ChatID - Fix code quality: errors.Is(), remove goto, CreateHuman deprecated - Remove Enable model endpoint and user-level settings CLI commands - Regenerate sqlc, swagger, SDK
This commit is contained in:
+11
-135
@@ -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, chat_model_id, memory_model_id, embedding_model_id, max_context_load_time, language, is_active, metadata, created_at, updated_at
|
||||
RETURNING id, username, email, password_hash, role, display_name, avatar_url, data_root, last_login_at, is_active, metadata, created_at, updated_at
|
||||
`
|
||||
|
||||
type CreateAccountParams struct {
|
||||
@@ -75,11 +75,6 @@ func (q *Queries) CreateAccount(ctx context.Context, arg CreateAccountParams) (U
|
||||
&i.AvatarUrl,
|
||||
&i.DataRoot,
|
||||
&i.LastLoginAt,
|
||||
&i.ChatModelID,
|
||||
&i.MemoryModelID,
|
||||
&i.EmbeddingModelID,
|
||||
&i.MaxContextLoadTime,
|
||||
&i.Language,
|
||||
&i.IsActive,
|
||||
&i.Metadata,
|
||||
&i.CreatedAt,
|
||||
@@ -91,7 +86,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, chat_model_id, memory_model_id, embedding_model_id, max_context_load_time, language, is_active, metadata, created_at, updated_at
|
||||
RETURNING id, username, email, password_hash, role, display_name, avatar_url, data_root, last_login_at, is_active, metadata, created_at, updated_at
|
||||
`
|
||||
|
||||
type CreateUserParams struct {
|
||||
@@ -112,11 +107,6 @@ func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (User, e
|
||||
&i.AvatarUrl,
|
||||
&i.DataRoot,
|
||||
&i.LastLoginAt,
|
||||
&i.ChatModelID,
|
||||
&i.MemoryModelID,
|
||||
&i.EmbeddingModelID,
|
||||
&i.MaxContextLoadTime,
|
||||
&i.Language,
|
||||
&i.IsActive,
|
||||
&i.Metadata,
|
||||
&i.CreatedAt,
|
||||
@@ -126,7 +116,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, chat_model_id, memory_model_id, embedding_model_id, max_context_load_time, language, 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, 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) {
|
||||
@@ -142,11 +132,6 @@ func (q *Queries) GetAccountByIdentity(ctx context.Context, identity pgtype.Text
|
||||
&i.AvatarUrl,
|
||||
&i.DataRoot,
|
||||
&i.LastLoginAt,
|
||||
&i.ChatModelID,
|
||||
&i.MemoryModelID,
|
||||
&i.EmbeddingModelID,
|
||||
&i.MaxContextLoadTime,
|
||||
&i.Language,
|
||||
&i.IsActive,
|
||||
&i.Metadata,
|
||||
&i.CreatedAt,
|
||||
@@ -156,7 +141,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, chat_model_id, memory_model_id, embedding_model_id, max_context_load_time, language, is_active, metadata, created_at, updated_at FROM users WHERE id = $1
|
||||
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
|
||||
`
|
||||
|
||||
func (q *Queries) GetAccountByUserID(ctx context.Context, userID pgtype.UUID) (User, error) {
|
||||
@@ -172,41 +157,6 @@ func (q *Queries) GetAccountByUserID(ctx context.Context, userID pgtype.UUID) (U
|
||||
&i.AvatarUrl,
|
||||
&i.DataRoot,
|
||||
&i.LastLoginAt,
|
||||
&i.ChatModelID,
|
||||
&i.MemoryModelID,
|
||||
&i.EmbeddingModelID,
|
||||
&i.MaxContextLoadTime,
|
||||
&i.Language,
|
||||
&i.IsActive,
|
||||
&i.Metadata,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getAccountByUsername = `-- name: GetAccountByUsername :one
|
||||
SELECT id, username, email, password_hash, role, display_name, avatar_url, data_root, last_login_at, chat_model_id, memory_model_id, embedding_model_id, max_context_load_time, language, is_active, metadata, created_at, updated_at FROM users WHERE username = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetAccountByUsername(ctx context.Context, username pgtype.Text) (User, error) {
|
||||
row := q.db.QueryRow(ctx, getAccountByUsername, username)
|
||||
var i User
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Username,
|
||||
&i.Email,
|
||||
&i.PasswordHash,
|
||||
&i.Role,
|
||||
&i.DisplayName,
|
||||
&i.AvatarUrl,
|
||||
&i.DataRoot,
|
||||
&i.LastLoginAt,
|
||||
&i.ChatModelID,
|
||||
&i.MemoryModelID,
|
||||
&i.EmbeddingModelID,
|
||||
&i.MaxContextLoadTime,
|
||||
&i.Language,
|
||||
&i.IsActive,
|
||||
&i.Metadata,
|
||||
&i.CreatedAt,
|
||||
@@ -216,7 +166,7 @@ func (q *Queries) GetAccountByUsername(ctx context.Context, username pgtype.Text
|
||||
}
|
||||
|
||||
const getUserByID = `-- name: GetUserByID :one
|
||||
SELECT id, username, email, password_hash, role, display_name, avatar_url, data_root, last_login_at, chat_model_id, memory_model_id, embedding_model_id, max_context_load_time, language, is_active, metadata, created_at, updated_at
|
||||
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
|
||||
`
|
||||
@@ -234,11 +184,6 @@ func (q *Queries) GetUserByID(ctx context.Context, id pgtype.UUID) (User, error)
|
||||
&i.AvatarUrl,
|
||||
&i.DataRoot,
|
||||
&i.LastLoginAt,
|
||||
&i.ChatModelID,
|
||||
&i.MemoryModelID,
|
||||
&i.EmbeddingModelID,
|
||||
&i.MaxContextLoadTime,
|
||||
&i.Language,
|
||||
&i.IsActive,
|
||||
&i.Metadata,
|
||||
&i.CreatedAt,
|
||||
@@ -248,7 +193,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, chat_model_id, memory_model_id, embedding_model_id, max_context_load_time, language, is_active, metadata, created_at, updated_at FROM users
|
||||
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
|
||||
ORDER BY created_at DESC
|
||||
`
|
||||
@@ -272,11 +217,6 @@ func (q *Queries) ListAccounts(ctx context.Context) ([]User, error) {
|
||||
&i.AvatarUrl,
|
||||
&i.DataRoot,
|
||||
&i.LastLoginAt,
|
||||
&i.ChatModelID,
|
||||
&i.MemoryModelID,
|
||||
&i.EmbeddingModelID,
|
||||
&i.MaxContextLoadTime,
|
||||
&i.Language,
|
||||
&i.IsActive,
|
||||
&i.Metadata,
|
||||
&i.CreatedAt,
|
||||
@@ -300,7 +240,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, chat_model_id, memory_model_id, embedding_model_id, max_context_load_time, language, is_active, metadata, created_at, updated_at
|
||||
RETURNING id, username, email, password_hash, role, display_name, avatar_url, data_root, last_login_at, is_active, metadata, created_at, updated_at
|
||||
`
|
||||
|
||||
type UpdateAccountAdminParams struct {
|
||||
@@ -330,11 +270,6 @@ func (q *Queries) UpdateAccountAdmin(ctx context.Context, arg UpdateAccountAdmin
|
||||
&i.AvatarUrl,
|
||||
&i.DataRoot,
|
||||
&i.LastLoginAt,
|
||||
&i.ChatModelID,
|
||||
&i.MemoryModelID,
|
||||
&i.EmbeddingModelID,
|
||||
&i.MaxContextLoadTime,
|
||||
&i.Language,
|
||||
&i.IsActive,
|
||||
&i.Metadata,
|
||||
&i.CreatedAt,
|
||||
@@ -348,7 +283,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, chat_model_id, memory_model_id, embedding_model_id, max_context_load_time, language, is_active, metadata, created_at, updated_at
|
||||
RETURNING id, username, email, password_hash, role, display_name, avatar_url, data_root, last_login_at, is_active, metadata, created_at, updated_at
|
||||
`
|
||||
|
||||
func (q *Queries) UpdateAccountLastLogin(ctx context.Context, id pgtype.UUID) (User, error) {
|
||||
@@ -364,11 +299,6 @@ func (q *Queries) UpdateAccountLastLogin(ctx context.Context, id pgtype.UUID) (U
|
||||
&i.AvatarUrl,
|
||||
&i.DataRoot,
|
||||
&i.LastLoginAt,
|
||||
&i.ChatModelID,
|
||||
&i.MemoryModelID,
|
||||
&i.EmbeddingModelID,
|
||||
&i.MaxContextLoadTime,
|
||||
&i.Language,
|
||||
&i.IsActive,
|
||||
&i.Metadata,
|
||||
&i.CreatedAt,
|
||||
@@ -382,7 +312,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, chat_model_id, memory_model_id, embedding_model_id, max_context_load_time, language, is_active, metadata, created_at, updated_at
|
||||
RETURNING id, username, email, password_hash, role, display_name, avatar_url, data_root, last_login_at, is_active, metadata, created_at, updated_at
|
||||
`
|
||||
|
||||
type UpdateAccountPasswordParams struct {
|
||||
@@ -403,11 +333,6 @@ func (q *Queries) UpdateAccountPassword(ctx context.Context, arg UpdateAccountPa
|
||||
&i.AvatarUrl,
|
||||
&i.DataRoot,
|
||||
&i.LastLoginAt,
|
||||
&i.ChatModelID,
|
||||
&i.MemoryModelID,
|
||||
&i.EmbeddingModelID,
|
||||
&i.MaxContextLoadTime,
|
||||
&i.Language,
|
||||
&i.IsActive,
|
||||
&i.Metadata,
|
||||
&i.CreatedAt,
|
||||
@@ -423,7 +348,7 @@ SET display_name = $2,
|
||||
is_active = $4,
|
||||
updated_at = now()
|
||||
WHERE id = $1
|
||||
RETURNING id, username, email, password_hash, role, display_name, avatar_url, data_root, last_login_at, chat_model_id, memory_model_id, embedding_model_id, max_context_load_time, language, is_active, metadata, created_at, updated_at
|
||||
RETURNING id, username, email, password_hash, role, display_name, avatar_url, data_root, last_login_at, is_active, metadata, created_at, updated_at
|
||||
`
|
||||
|
||||
type UpdateAccountProfileParams struct {
|
||||
@@ -451,50 +376,6 @@ func (q *Queries) UpdateAccountProfile(ctx context.Context, arg UpdateAccountPro
|
||||
&i.AvatarUrl,
|
||||
&i.DataRoot,
|
||||
&i.LastLoginAt,
|
||||
&i.ChatModelID,
|
||||
&i.MemoryModelID,
|
||||
&i.EmbeddingModelID,
|
||||
&i.MaxContextLoadTime,
|
||||
&i.Language,
|
||||
&i.IsActive,
|
||||
&i.Metadata,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const updateUserStatus = `-- name: UpdateUserStatus :one
|
||||
UPDATE users
|
||||
SET is_active = $2,
|
||||
updated_at = now()
|
||||
WHERE id = $1
|
||||
RETURNING id, username, email, password_hash, role, display_name, avatar_url, data_root, last_login_at, chat_model_id, memory_model_id, embedding_model_id, max_context_load_time, language, is_active, metadata, created_at, updated_at
|
||||
`
|
||||
|
||||
type UpdateUserStatusParams struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
IsActive bool `json:"is_active"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateUserStatus(ctx context.Context, arg UpdateUserStatusParams) (User, error) {
|
||||
row := q.db.QueryRow(ctx, updateUserStatus, arg.ID, arg.IsActive)
|
||||
var i User
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Username,
|
||||
&i.Email,
|
||||
&i.PasswordHash,
|
||||
&i.Role,
|
||||
&i.DisplayName,
|
||||
&i.AvatarUrl,
|
||||
&i.DataRoot,
|
||||
&i.LastLoginAt,
|
||||
&i.ChatModelID,
|
||||
&i.MemoryModelID,
|
||||
&i.EmbeddingModelID,
|
||||
&i.MaxContextLoadTime,
|
||||
&i.Language,
|
||||
&i.IsActive,
|
||||
&i.Metadata,
|
||||
&i.CreatedAt,
|
||||
@@ -526,7 +407,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, chat_model_id, memory_model_id, embedding_model_id, max_context_load_time, language, is_active, metadata, created_at, updated_at
|
||||
RETURNING id, username, email, password_hash, role, display_name, avatar_url, data_root, last_login_at, is_active, metadata, created_at, updated_at
|
||||
`
|
||||
|
||||
type UpsertAccountByUsernameParams struct {
|
||||
@@ -564,11 +445,6 @@ func (q *Queries) UpsertAccountByUsername(ctx context.Context, arg UpsertAccount
|
||||
&i.AvatarUrl,
|
||||
&i.DataRoot,
|
||||
&i.LastLoginAt,
|
||||
&i.ChatModelID,
|
||||
&i.MemoryModelID,
|
||||
&i.EmbeddingModelID,
|
||||
&i.MaxContextLoadTime,
|
||||
&i.Language,
|
||||
&i.IsActive,
|
||||
&i.Metadata,
|
||||
&i.CreatedAt,
|
||||
|
||||
Reference in New Issue
Block a user