Update schema.sql
This commit is contained in:
1 parent
30014cc936
commit
6deb72beda
1 file changed
+22
-7
+22
-7
@@ -1,4 +1,4 @@
|
|||||||
-- 用户表
|
-- 用户表
|
||||||
CREATE TABLE IF NOT EXISTS users (
|
CREATE TABLE IF NOT EXISTS users (
|
||||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||||
email VARCHAR(255) UNIQUE NOT NULL,
|
email VARCHAR(255) UNIQUE NOT NULL,
|
||||||
@@ -10,7 +10,7 @@ CREATE TABLE IF NOT EXISTS users (
|
|||||||
created_at TIMESTAMPTZ DEFAULT now()
|
created_at TIMESTAMPTZ DEFAULT now()
|
||||||
);
|
);
|
||||||
|
|
||||||
-- 帖子表
|
-- 帖子表
|
||||||
CREATE TABLE IF NOT EXISTS posts (
|
CREATE TABLE IF NOT EXISTS posts (
|
||||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||||
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
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()
|
updated_at TIMESTAMPTZ DEFAULT now()
|
||||||
);
|
);
|
||||||
|
|
||||||
-- 回复表
|
-- 回复表
|
||||||
CREATE TABLE IF NOT EXISTS replies (
|
CREATE TABLE IF NOT EXISTS replies (
|
||||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||||
post_id UUID NOT NULL REFERENCES posts(id) ON DELETE CASCADE,
|
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()
|
created_at TIMESTAMPTZ DEFAULT now()
|
||||||
);
|
);
|
||||||
|
|
||||||
-- 友情链接表
|
-- 友情链接表
|
||||||
CREATE TABLE IF NOT EXISTS friendly_links (
|
CREATE TABLE IF NOT EXISTS friendly_links (
|
||||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||||
title VARCHAR(100) NOT NULL,
|
title VARCHAR(100) NOT NULL,
|
||||||
@@ -38,7 +38,7 @@ CREATE TABLE IF NOT EXISTS friendly_links (
|
|||||||
sort_order INT DEFAULT 0
|
sort_order INT DEFAULT 0
|
||||||
);
|
);
|
||||||
|
|
||||||
-- 举报表
|
-- 举报表
|
||||||
CREATE TABLE IF NOT EXISTS reports (
|
CREATE TABLE IF NOT EXISTS reports (
|
||||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||||
post_id UUID NOT NULL REFERENCES posts(id) ON DELETE CASCADE,
|
post_id UUID NOT NULL REFERENCES posts(id) ON DELETE CASCADE,
|
||||||
@@ -51,7 +51,7 @@ CREATE TABLE IF NOT EXISTS reports (
|
|||||||
handler_note TEXT
|
handler_note TEXT
|
||||||
);
|
);
|
||||||
|
|
||||||
-- 事件日志表
|
-- 事件日志表
|
||||||
CREATE TABLE IF NOT EXISTS event_logs (
|
CREATE TABLE IF NOT EXISTS event_logs (
|
||||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||||
user_id UUID REFERENCES users(id) ON DELETE SET NULL,
|
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()
|
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()
|
CREATE OR REPLACE FUNCTION update_updated_at()
|
||||||
RETURNS TRIGGER AS $$
|
RETURNS TRIGGER AS $$
|
||||||
BEGIN
|
BEGIN
|
||||||
|
|||||||
Reference in new issue
Block a user