From 8fb1f7da94cf1b692df32ec5e901a5ebe77a5ab4 Mon Sep 17 00:00:00 2001 From: seaHi Date: Sun, 26 Jul 2026 17:52:39 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E6=9E=B6=E6=9E=84=EF=BC=8C=E5=A2=9E=E5=8A=A0=E5=88=86?= =?UTF-8?q?=E7=B1=BB=E8=A1=A8=E5=8F=8A=E7=9B=B8=E5=85=B3=E7=BA=A6=E6=9D=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- schema.sql | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/schema.sql b/schema.sql index 471ac7a..e51f933 100644 --- a/schema.sql +++ b/schema.sql @@ -1,7 +1,8 @@ -DROP TABLE IF EXISTS posts; -DROP TABLE IF EXISTS users; -DROP TABLE IF EXISTS tags; DROP TABLE IF EXISTS post_tags; +DROP TABLE IF EXISTS posts; +DROP TABLE IF EXISTS tags; +DROP TABLE IF EXISTS categories; +DROP TABLE IF EXISTS users; CREATE TABLE users ( id INTEGER PRIMARY KEY AUTOINCREMENT, @@ -10,6 +11,12 @@ CREATE TABLE users ( created_at DATETIME DEFAULT CURRENT_TIMESTAMP ); +CREATE TABLE categories ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + name TEXT NOT NULL UNIQUE, + slug TEXT NOT NULL UNIQUE +); + CREATE TABLE posts ( id INTEGER PRIMARY KEY AUTOINCREMENT, slug TEXT NOT NULL UNIQUE, @@ -17,9 +24,11 @@ CREATE TABLE posts ( excerpt TEXT, content TEXT NOT NULL, author_id INTEGER NOT NULL, + category_id INTEGER, published_at DATETIME DEFAULT CURRENT_TIMESTAMP, updated_at DATETIME DEFAULT CURRENT_TIMESTAMP, - FOREIGN KEY (author_id) REFERENCES users(id) + FOREIGN KEY (author_id) REFERENCES users(id), + FOREIGN KEY (category_id) REFERENCES categories(id) ON DELETE SET NULL ); CREATE TABLE tags ( @@ -35,18 +44,21 @@ CREATE TABLE post_tags ( FOREIGN KEY (tag_id) REFERENCES tags(id) ON DELETE CASCADE ); --- Insert a default user (password should be hashed in a real scenario, this is a placeholder) +-- Insert a default user INSERT INTO users (username, password_hash) VALUES ('admin', 'admin'); --- Insert some dummy posts -INSERT INTO posts (slug, title, excerpt, content, author_id) VALUES +-- Insert default categories +INSERT INTO categories (name, slug) VALUES ('默认分类', 'uncategorized'), ('技术分享', 'tech'), ('生活随笔', 'life'); + +-- Insert dummy posts +INSERT INTO posts (slug, title, excerpt, content, author_id, category_id) VALUES ('hello-world', 'Hello, BlogFlare!', 'This is my first post on BlogFlare.', 'Welcome to my new blog powered by **SvelteKit** and **Cloudflare D1**. > [!NOTE] > This is a DoIt style admonition! -It is incredibly fast and cheap to host.', 1), -('void-theme', 'The Beauty of VOID', 'Typography is essential.', 'Typecho Theme VOID inspired this design. It uses a very clean layout.', 1); +It is incredibly fast and cheap to host.', 1, 2), +('void-theme', 'The Beauty of VOID', 'Typography is essential.', 'Typecho Theme VOID inspired this design. It uses a very clean layout.', 1, 2); INSERT INTO tags (name) VALUES ('Welcome'), ('Design'); INSERT INTO post_tags (post_id, tag_id) VALUES (1, 1), (2, 2);