feat(ai-studio): add image studio persistence layer
This commit is contained in:
@@ -289,6 +289,89 @@ CREATE TABLE IF NOT EXISTS run_log_events (
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_run_logs_started ON run_logs(started_at DESC, id DESC);
|
||||
CREATE INDEX IF NOT EXISTS idx_run_log_events_run ON run_log_events(run_id, id);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS image_studio_projects (
|
||||
id INTEGER PRIMARY KEY,
|
||||
account_alias TEXT NOT NULL,
|
||||
account_slug TEXT NOT NULL,
|
||||
account_name TEXT,
|
||||
item_id TEXT NOT NULL,
|
||||
target_main_count INTEGER NOT NULL DEFAULT 9,
|
||||
target_detail_count INTEGER NOT NULL DEFAULT 12,
|
||||
draft_prompt TEXT,
|
||||
status TEXT NOT NULL DEFAULT 'active',
|
||||
created_at TEXT NOT NULL,
|
||||
updated_at TEXT NOT NULL,
|
||||
deleted_at TEXT,
|
||||
deleted_reason TEXT,
|
||||
UNIQUE(account_alias, item_id)
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_image_studio_projects_status
|
||||
ON image_studio_projects(status, updated_at DESC);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS image_studio_assets (
|
||||
id INTEGER PRIMARY KEY,
|
||||
project_id INTEGER NOT NULL REFERENCES image_studio_projects(id) ON DELETE CASCADE,
|
||||
kind TEXT NOT NULL,
|
||||
remote_url TEXT,
|
||||
local_path TEXT,
|
||||
aspect_ratio TEXT,
|
||||
parent_asset_id INTEGER REFERENCES image_studio_assets(id) ON DELETE SET NULL,
|
||||
prompt TEXT,
|
||||
status TEXT NOT NULL DEFAULT 'available',
|
||||
source_order INTEGER NOT NULL DEFAULT 0,
|
||||
created_at TEXT NOT NULL,
|
||||
updated_at TEXT NOT NULL
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_image_studio_assets_project_kind
|
||||
ON image_studio_assets(project_id, kind, source_order, id);
|
||||
CREATE INDEX IF NOT EXISTS idx_image_studio_assets_parent
|
||||
ON image_studio_assets(parent_asset_id);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS image_studio_jobs (
|
||||
id INTEGER PRIMARY KEY,
|
||||
project_id INTEGER NOT NULL REFERENCES image_studio_projects(id) ON DELETE CASCADE,
|
||||
source_asset_id INTEGER REFERENCES image_studio_assets(id) ON DELETE SET NULL,
|
||||
output_asset_id INTEGER REFERENCES image_studio_assets(id) ON DELETE SET NULL,
|
||||
generation_source TEXT NOT NULL DEFAULT 'cmhub',
|
||||
provider TEXT NOT NULL DEFAULT 'cmhub',
|
||||
job_type TEXT NOT NULL,
|
||||
task_key TEXT NOT NULL UNIQUE,
|
||||
task_id TEXT,
|
||||
status TEXT NOT NULL DEFAULT 'pending',
|
||||
prompt TEXT,
|
||||
error TEXT,
|
||||
attempts INTEGER NOT NULL DEFAULT 0,
|
||||
points_cost INTEGER,
|
||||
points_balance INTEGER,
|
||||
call_id TEXT,
|
||||
created_at TEXT NOT NULL,
|
||||
updated_at TEXT NOT NULL,
|
||||
submitted_at TEXT,
|
||||
finished_at TEXT
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_image_studio_jobs_project_status
|
||||
ON image_studio_jobs(project_id, status, id);
|
||||
CREATE INDEX IF NOT EXISTS idx_image_studio_jobs_task_id
|
||||
ON image_studio_jobs(task_id);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS image_studio_selections (
|
||||
id INTEGER PRIMARY KEY,
|
||||
project_id INTEGER NOT NULL REFERENCES image_studio_projects(id) ON DELETE CASCADE,
|
||||
selection_type TEXT NOT NULL,
|
||||
position INTEGER NOT NULL,
|
||||
asset_id INTEGER NOT NULL REFERENCES image_studio_assets(id) ON DELETE CASCADE,
|
||||
created_at TEXT NOT NULL,
|
||||
updated_at TEXT NOT NULL,
|
||||
UNIQUE(project_id, selection_type, position),
|
||||
UNIQUE(project_id, selection_type, asset_id)
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_image_studio_selections_project
|
||||
ON image_studio_selections(project_id, selection_type, position);
|
||||
"""
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user