mirror of
https://github.com/memohai/Memoh.git
synced 2026-04-27 07:16:19 +09:00
feat: user settings & history
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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'
|
||||
);
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user