Files
blogflare/migrations/0000_initial.sql
T

138 lines
4.0 KiB
SQL

-- BlogFlare baseline. This migration is safe to apply to a fresh database and
-- to databases previously initialized from the legacy schema.sql file.
CREATE TABLE IF NOT EXISTS users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
username TEXT NOT NULL UNIQUE,
password_hash TEXT NOT NULL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE IF NOT EXISTS categories (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL UNIQUE,
slug TEXT NOT NULL UNIQUE
);
CREATE TABLE IF NOT EXISTS 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 IF NOT EXISTS posts (
id INTEGER PRIMARY KEY AUTOINCREMENT,
slug TEXT NOT NULL UNIQUE,
title TEXT NOT NULL,
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 (series_id) REFERENCES series(id) ON DELETE SET NULL
);
CREATE INDEX IF NOT EXISTS idx_posts_series_order
ON posts(series_id, series_weight, published_at, id);
CREATE TABLE IF NOT EXISTS 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 IF NOT EXISTS tags (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL UNIQUE
);
CREATE TABLE IF NOT EXISTS post_tags (
post_id INTEGER NOT NULL,
tag_id INTEGER NOT NULL,
PRIMARY KEY (post_id, tag_id),
FOREIGN KEY (post_id) REFERENCES posts(id) ON DELETE CASCADE,
FOREIGN KEY (tag_id) REFERENCES tags(id) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS settings (
id INTEGER PRIMARY KEY AUTOINCREMENT,
key TEXT NOT NULL UNIQUE,
value TEXT NOT NULL,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE IF NOT EXISTS 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 OR IGNORE INTO users (username, password_hash) VALUES ('admin', 'admin');
INSERT OR IGNORE INTO categories (name, slug) VALUES
('默认分类', 'uncategorized'),
('技术分享', 'tech'),
('生活随笔', 'life');
INSERT OR IGNORE INTO posts (slug, title, content, author_id, category_id) VALUES
(
'hello-world',
'Hello, BlogFlare!',
'This is my first post on BlogFlare.
<!--more-->
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.',
(SELECT id FROM users WHERE username = 'admin'),
(SELECT id FROM categories WHERE slug = 'tech')
),
(
'void-theme',
'The Beauty of VOID',
'Typography is essential.
<!--more-->
Typecho Theme VOID inspired this design. It uses a very clean layout.',
(SELECT id FROM users WHERE username = 'admin'),
(SELECT id FROM categories WHERE slug = 'tech')
);
INSERT OR IGNORE INTO tags (name) VALUES ('Welcome'), ('Design');
INSERT OR IGNORE INTO post_tags (post_id, tag_id) VALUES
(
(SELECT id FROM posts WHERE slug = 'hello-world'),
(SELECT id FROM tags WHERE name = 'Welcome')
),
(
(SELECT id FROM posts WHERE slug = 'void-theme'),
(SELECT id FROM tags WHERE name = 'Design')
);
INSERT OR IGNORE 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 and R2.'),
('r2.public_domain', 'https://assets.yourdomain.com');