diff --git a/migrations/0001_add_series.sql b/migrations/0001_add_series.sql new file mode 100644 index 0000000..4b9c4cf --- /dev/null +++ b/migrations/0001_add_series.sql @@ -0,0 +1,14 @@ +CREATE TABLE series ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + name TEXT NOT NULL UNIQUE COLLATE NOCASE, + slug TEXT NOT NULL UNIQUE, + description TEXT, + created_at DATETIME DEFAULT CURRENT_TIMESTAMP +); + +ALTER TABLE posts ADD COLUMN series_id INTEGER REFERENCES series(id) ON DELETE SET NULL; +ALTER TABLE posts ADD COLUMN series_weight INTEGER; + +CREATE INDEX idx_posts_series_order ON posts(series_id, series_weight, published_at, id); + +INSERT OR IGNORE INTO settings (key, value) VALUES ('alias.series', '系列'); diff --git a/schema.sql b/schema.sql index 0755e31..5b4b114 100644 --- a/schema.sql +++ b/schema.sql @@ -1,5 +1,6 @@ DROP TABLE IF EXISTS post_tags; DROP TABLE IF EXISTS posts; +DROP TABLE IF EXISTS series; DROP TABLE IF EXISTS tags; DROP TABLE IF EXISTS categories; DROP TABLE IF EXISTS pages; @@ -20,6 +21,14 @@ CREATE TABLE categories ( slug TEXT NOT NULL UNIQUE ); +CREATE TABLE series ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + name TEXT NOT NULL UNIQUE COLLATE NOCASE, + slug TEXT NOT NULL UNIQUE, + description TEXT, + created_at DATETIME DEFAULT CURRENT_TIMESTAMP +); + CREATE TABLE posts ( id INTEGER PRIMARY KEY AUTOINCREMENT, slug TEXT NOT NULL UNIQUE, @@ -27,13 +36,18 @@ CREATE TABLE posts ( content TEXT NOT NULL, author_id INTEGER NOT NULL, category_id INTEGER, + series_id INTEGER, + series_weight INTEGER, published_at DATETIME DEFAULT CURRENT_TIMESTAMP, updated_at DATETIME DEFAULT CURRENT_TIMESTAMP, cover TEXT, FOREIGN KEY (author_id) REFERENCES users(id), - FOREIGN KEY (category_id) REFERENCES categories(id) ON DELETE SET NULL + FOREIGN KEY (category_id) REFERENCES categories(id) ON DELETE SET NULL, + FOREIGN KEY (series_id) REFERENCES series(id) ON DELETE SET NULL ); +CREATE INDEX idx_posts_series_order ON posts(series_id, series_weight, published_at, id); + CREATE TABLE pages ( id INTEGER PRIMARY KEY AUTOINCREMENT, slug TEXT NOT NULL UNIQUE, @@ -102,6 +116,7 @@ INSERT INTO settings (key, value) VALUES ('alias.post', '文章'), ('alias.category', '分类'), ('alias.tag', '标签'), +('alias.series', '系列'), ('alias.page', '页面'), ('site.title', 'BlogFlare'), ('site.description', 'A high-performance blog powered by Cloudflare D1, R2, and KV.'),