-- +migrate Up CREATE TABLE categories ( id SERIAL PRIMARY KEY, name VARCHAR(100) NOT NULL, description TEXT, parent_id INTEGER REFERENCES categories(id), color VARCHAR(7) DEFAULT '#3b82f6', cover_image VARCHAR(500), sort INTEGER DEFAULT 0, is_active BOOLEAN DEFAULT true, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, deleted_at TIMESTAMP ); -- 创建索引 CREATE INDEX idx_categories_parent_id ON categories(parent_id); CREATE INDEX idx_categories_is_active ON categories(is_active); CREATE INDEX idx_categories_sort ON categories(sort); CREATE INDEX idx_categories_deleted_at ON categories(deleted_at); -- 插入默认分类 INSERT INTO categories (name, description, color, sort) VALUES ('风景摄影', '自然风景摄影作品', '#10b981', 1), ('人像摄影', '人物肖像摄影作品', '#f59e0b', 2), ('街头摄影', '街头纪实摄影作品', '#ef4444', 3), ('建筑摄影', '建筑和城市摄影作品', '#3b82f6', 4), ('抽象摄影', '抽象艺术摄影作品', '#8b5cf6', 5); -- +migrate Down DROP TABLE IF EXISTS categories;