feat: add categories migration and model
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
41c8d1e2f5
commit
641b402d4a
4 changed files with 113 additions and 0 deletions
23
sql/schema/04_categories.up.sql
Normal file
23
sql/schema/04_categories.up.sql
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
CREATE TABLE categories (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
site_id INTEGER NOT NULL,
|
||||
guid TEXT NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
slug TEXT NOT NULL,
|
||||
description TEXT NOT NULL DEFAULT '',
|
||||
created_at INTEGER NOT NULL,
|
||||
updated_at INTEGER NOT NULL,
|
||||
FOREIGN KEY (site_id) REFERENCES sites (id) ON DELETE CASCADE
|
||||
);
|
||||
CREATE INDEX idx_categories_site ON categories (site_id);
|
||||
CREATE UNIQUE INDEX idx_categories_guid ON categories (guid);
|
||||
CREATE UNIQUE INDEX idx_categories_site_slug ON categories (site_id, slug);
|
||||
|
||||
CREATE TABLE post_categories (
|
||||
post_id INTEGER NOT NULL,
|
||||
category_id INTEGER NOT NULL,
|
||||
PRIMARY KEY (post_id, category_id),
|
||||
FOREIGN KEY (post_id) REFERENCES posts (id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (category_id) REFERENCES categories (id) ON DELETE CASCADE
|
||||
);
|
||||
CREATE INDEX idx_post_categories_category ON post_categories (category_id);
|
||||
Loading…
Add table
Add a link
Reference in a new issue