feat: user settings & history

This commit is contained in:
Acbox
2026-01-28 15:57:39 +08:00
parent 39215309da
commit 11551b72ab
19 changed files with 1920 additions and 10 deletions
+3
View File
@@ -1,6 +1,9 @@
DROP TABLE IF EXISTS user_settings;
DROP TABLE IF EXISTS history;
DROP TABLE IF EXISTS lifecycle_events;
DROP TABLE IF EXISTS container_versions;
DROP TABLE IF EXISTS models;
DROP TABLE IF EXISTS llm_providers;
DROP TABLE IF EXISTS snapshots;
DROP TABLE IF EXISTS containers;
DROP TABLE IF EXISTS users;
+6
View File
@@ -140,3 +140,9 @@ CREATE TABLE IF NOT EXISTS history (
CREATE INDEX IF NOT EXISTS idx_history_user ON history("user");
CREATE INDEX IF NOT EXISTS idx_history_timestamp ON history(timestamp);
CREATE TABLE IF NOT EXISTS user_settings (
user_id UUID PRIMARY KEY REFERENCES users(id) ON DELETE CASCADE,
max_context_load_time INTEGER NOT NULL DEFAULT 1440,
language TEXT NOT NULL DEFAULT 'Same as user input'
);
+20
View File
@@ -9,3 +9,23 @@ FROM history
WHERE "user" = $1 AND timestamp >= $2
ORDER BY timestamp ASC;
-- name: GetHistoryByID :one
SELECT id, messages, timestamp, "user"
FROM history
WHERE id = $1;
-- name: ListHistoryByUser :many
SELECT id, messages, timestamp, "user"
FROM history
WHERE "user" = $1
ORDER BY timestamp DESC
LIMIT $2;
-- name: DeleteHistoryByID :exec
DELETE FROM history
WHERE id = $1;
-- name: DeleteHistoryByUser :exec
DELETE FROM history
WHERE "user" = $1;
+17
View File
@@ -0,0 +1,17 @@
-- name: GetSettingsByUserID :one
SELECT user_id, max_context_load_time, language
FROM user_settings
WHERE user_id = $1;
-- name: UpsertSettings :one
INSERT INTO user_settings (user_id, max_context_load_time, language)
VALUES ($1, $2, $3)
ON CONFLICT (user_id) DO UPDATE SET
max_context_load_time = EXCLUDED.max_context_load_time,
language = EXCLUDED.language
RETURNING user_id, max_context_load_time, language;
-- name: DeleteSettingsByUserID :exec
DELETE FROM user_settings
WHERE user_id = $1;