feat: 添加文章系列数据库表结构及迁移文件
This commit is contained in:
1 parent
f72dd4df87
commit
fe37e26e5f
2 files changed
+30
-1
No files matched your search
@@ -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', '系列');
|
||||
+16
-1
@@ -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.'),
|
||||
|
||||
Reference in new issue
Block a user