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);