feat: 更新数据库结构并添加 R2 存储支持

This commit is contained in:
seahi committed 2026-07-29 10:49:01 +08:00
1 parent 5e116b4a2a
commit d5a4846a05
4 files changed
+56 -5

No files matched your search

+47 -4
View File
@@ -2,7 +2,10 @@ DROP TABLE IF EXISTS post_tags;
DROP TABLE IF EXISTS posts; DROP TABLE IF EXISTS posts;
DROP TABLE IF EXISTS tags; DROP TABLE IF EXISTS tags;
DROP TABLE IF EXISTS categories; DROP TABLE IF EXISTS categories;
DROP TABLE IF EXISTS pages;
DROP TABLE IF EXISTS settings;
DROP TABLE IF EXISTS users; DROP TABLE IF EXISTS users;
DROP TABLE IF EXISTS attachments;
CREATE TABLE users ( CREATE TABLE users (
id INTEGER PRIMARY KEY AUTOINCREMENT, id INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -21,7 +24,6 @@ CREATE TABLE posts (
id INTEGER PRIMARY KEY AUTOINCREMENT, id INTEGER PRIMARY KEY AUTOINCREMENT,
slug TEXT NOT NULL UNIQUE, slug TEXT NOT NULL UNIQUE,
title TEXT NOT NULL, title TEXT NOT NULL,
excerpt TEXT,
content TEXT NOT NULL, content TEXT NOT NULL,
author_id INTEGER NOT NULL, author_id INTEGER NOT NULL,
category_id INTEGER, category_id INTEGER,
@@ -31,6 +33,17 @@ CREATE TABLE posts (
FOREIGN KEY (category_id) REFERENCES categories(id) ON DELETE SET NULL FOREIGN KEY (category_id) REFERENCES categories(id) ON DELETE SET NULL
); );
CREATE TABLE pages (
id INTEGER PRIMARY KEY AUTOINCREMENT,
slug TEXT NOT NULL UNIQUE,
title TEXT NOT NULL,
content TEXT NOT NULL,
author_id INTEGER NOT NULL,
published_at DATETIME DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (author_id) REFERENCES users(id)
);
CREATE TABLE tags ( CREATE TABLE tags (
id INTEGER PRIMARY KEY AUTOINCREMENT, id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL UNIQUE name TEXT NOT NULL UNIQUE
@@ -44,6 +57,22 @@ CREATE TABLE post_tags (
FOREIGN KEY (tag_id) REFERENCES tags(id) ON DELETE CASCADE FOREIGN KEY (tag_id) REFERENCES tags(id) ON DELETE CASCADE
); );
CREATE TABLE settings (
id INTEGER PRIMARY KEY AUTOINCREMENT,
key TEXT NOT NULL UNIQUE,
value TEXT NOT NULL,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE attachments (
id INTEGER PRIMARY KEY AUTOINCREMENT,
filename TEXT NOT NULL,
key TEXT NOT NULL UNIQUE,
mime_type TEXT,
size INTEGER,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
-- Insert a default user -- Insert a default user
INSERT INTO users (username, password_hash) VALUES ('admin', 'admin'); INSERT INTO users (username, password_hash) VALUES ('admin', 'admin');
@@ -51,14 +80,28 @@ INSERT INTO users (username, password_hash) VALUES ('admin', 'admin');
INSERT INTO categories (name, slug) VALUES ('默认分类', 'uncategorized'), ('技术分享', 'tech'), ('生活随笔', 'life'); INSERT INTO categories (name, slug) VALUES ('默认分类', 'uncategorized'), ('技术分享', 'tech'), ('生活随笔', 'life');
-- Insert dummy posts -- Insert dummy posts
INSERT INTO posts (slug, title, excerpt, content, author_id, category_id) VALUES INSERT INTO posts (slug, title, 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**. ('hello-world', 'Hello, BlogFlare!', 'This is my first post on BlogFlare.
<!--more-->
Welcome to my new blog powered by **SvelteKit** and **Cloudflare D1**.
> [!NOTE] > [!NOTE]
> This is a DoIt style admonition! > This is a DoIt style admonition!
It is incredibly fast and cheap to host.', 1, 2), 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); ('void-theme', 'The Beauty of VOID', 'Typography is essential.
<!--more-->
Typecho Theme VOID inspired this design. It uses a very clean layout.', 1, 2);
INSERT INTO tags (name) VALUES ('Welcome'), ('Design'); INSERT INTO tags (name) VALUES ('Welcome'), ('Design');
INSERT INTO post_tags (post_id, tag_id) VALUES (1, 1), (2, 2); INSERT INTO post_tags (post_id, tag_id) VALUES (1, 1), (2, 2);
-- Insert default aliases settings
INSERT INTO settings (key, value) VALUES
('alias.post', '文章'),
('alias.category', '分类'),
('alias.tag', '标签'),
('alias.page', '页面'),
('site.title', 'BlogFlare'),
('site.description', 'A high-performance blog powered by Cloudflare D1, R2, and KV.'),
('r2.public_domain', 'https://assets.yourdomain.com');
+1
View File
@@ -5,6 +5,7 @@ declare global {
interface Platform { interface Platform {
env: { env: {
DB: D1Database; DB: D1Database;
R2: R2Bucket;
} & Env; } & Env;
context: ExecutionContext; context: ExecutionContext;
caches: CacheStorage & { default: Cache }; caches: CacheStorage & { default: Cache };
+2 -1
View File
@@ -1,7 +1,8 @@
/* eslint-disable */ /* eslint-disable */
// Generated by Wrangler by running `wrangler types` (hash: 8a4682da07c612009fc47d01bb388537) // Generated by Wrangler by running `wrangler types` (hash: 595eaffe197c5cd34fd594e9940c7cf0)
// Runtime types generated with workerd@1.20260708.1 2026-07-12 nodejs_als // Runtime types generated with workerd@1.20260708.1 2026-07-12 nodejs_als
interface __BaseEnv_Env { interface __BaseEnv_Env {
R2: R2Bucket;
DB: D1Database; DB: D1Database;
} }
declare namespace Cloudflare { declare namespace Cloudflare {
+6
View File
@@ -12,5 +12,11 @@
"database_name": "blogflare-db", "database_name": "blogflare-db",
"database_id": "local" "database_id": "local"
} }
],
"r2_buckets": [
{
"binding": "R2",
"bucket_name": "blogflare-assets"
}
] ]
} }