diff --git a/schema.sql b/schema.sql index 672d8bc..f2a613e 100644 --- a/schema.sql +++ b/schema.sql @@ -1,4 +1,4 @@ --- Óû§±í +-- 用户表 CREATE TABLE IF NOT EXISTS users ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), email VARCHAR(255) UNIQUE NOT NULL, @@ -10,7 +10,7 @@ CREATE TABLE IF NOT EXISTS users ( created_at TIMESTAMPTZ DEFAULT now() ); --- Ìû×Ó±í +-- 帖å­�表 CREATE TABLE IF NOT EXISTS posts ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE, @@ -21,7 +21,7 @@ CREATE TABLE IF NOT EXISTS posts ( updated_at TIMESTAMPTZ DEFAULT now() ); --- »Ø¸´±í +-- 回å¤�表 CREATE TABLE IF NOT EXISTS replies ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), post_id UUID NOT NULL REFERENCES posts(id) ON DELETE CASCADE, @@ -30,7 +30,7 @@ CREATE TABLE IF NOT EXISTS replies ( created_at TIMESTAMPTZ DEFAULT now() ); --- ÓÑÇéÁ´½Ó±í +-- å�‹æƒ…链接表 CREATE TABLE IF NOT EXISTS friendly_links ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), title VARCHAR(100) NOT NULL, @@ -38,7 +38,7 @@ CREATE TABLE IF NOT EXISTS friendly_links ( sort_order INT DEFAULT 0 ); --- ¾Ù±¨±í +-- 举报表 CREATE TABLE IF NOT EXISTS reports ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), post_id UUID NOT NULL REFERENCES posts(id) ON DELETE CASCADE, @@ -51,7 +51,7 @@ CREATE TABLE IF NOT EXISTS reports ( handler_note TEXT ); --- ʼþÈÕÖ¾±í +-- 事件日志表 CREATE TABLE IF NOT EXISTS event_logs ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), user_id UUID REFERENCES users(id) ON DELETE SET NULL, @@ -60,7 +60,22 @@ CREATE TABLE IF NOT EXISTS event_logs ( created_at TIMESTAMPTZ DEFAULT now() ); --- ×Ô¶¯¸üРupdated_at µÄ´¥·¢Æ÷ +-- ============================================================ +-- 论å�›è®¾ç½®è¡¨ï¼ˆæ–°å¢žï¼‰ +-- ============================================================ +CREATE TABLE IF NOT EXISTS settings ( + key VARCHAR(50) PRIMARY KEY, + value TEXT NOT NULL, + updated_at TIMESTAMPTZ DEFAULT now() +); + +-- æ�’入默认论å�›å��ç§° +INSERT INTO settings (key, value) VALUES ('forum_name', 'Forumlify') +ON CONFLICT (key) DO NOTHING; + +-- ============================================================ +-- 自动更新 updated_at 的触å�‘器 +-- ============================================================ CREATE OR REPLACE FUNCTION update_updated_at() RETURNS TRIGGER AS $$ BEGIN @@ -72,4 +87,4 @@ $$ LANGUAGE plpgsql; DROP TRIGGER IF EXISTS update_posts_updated_at ON posts; CREATE TRIGGER update_posts_updated_at BEFORE UPDATE ON posts - FOR EACH ROW EXECUTE FUNCTION update_updated_at(); \ No newline at end of file + FOR EACH ROW EXECUTE FUNCTION update_updated_at();