36 行
1.2 KiB
SQL
36 行
1.2 KiB
SQL
CREATE TABLE IF NOT EXISTS material_categories (
|
|
category_id TEXT PRIMARY KEY,
|
|
name TEXT NOT NULL,
|
|
parent_id TEXT,
|
|
category_type TEXT NOT NULL DEFAULT 'material',
|
|
sort_order INTEGER NOT NULL DEFAULT 0,
|
|
metadata_json TEXT,
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
FOREIGN KEY(parent_id) REFERENCES material_categories(category_id) ON DELETE SET NULL
|
|
);
|
|
|
|
CREATE INDEX IF NOT EXISTS idx_material_categories_parent
|
|
ON material_categories(parent_id, sort_order);
|
|
|
|
CREATE TABLE IF NOT EXISTS materials (
|
|
material_id TEXT PRIMARY KEY,
|
|
category_id TEXT,
|
|
display_name TEXT NOT NULL,
|
|
image_uri TEXT,
|
|
thumbnail_uri TEXT,
|
|
prompt TEXT,
|
|
negative_prompt TEXT,
|
|
tags_json TEXT,
|
|
recognition_status TEXT NOT NULL DEFAULT 'pending_upload',
|
|
metadata_json TEXT,
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
FOREIGN KEY(category_id) REFERENCES material_categories(category_id) ON DELETE SET NULL
|
|
);
|
|
|
|
CREATE INDEX IF NOT EXISTS idx_materials_category
|
|
ON materials(category_id, created_at);
|
|
|
|
CREATE INDEX IF NOT EXISTS idx_materials_status
|
|
ON materials(recognition_status);
|