CREATE TABLE IF NOT EXISTS site_settings (
  id INTEGER PRIMARY KEY CHECK (id = 1),
  generation_enabled INTEGER NOT NULL DEFAULT 0,
  comfyui_base_url TEXT,
  comfyui_workflow_json TEXT,
  comfyui_node_style_prompt TEXT,
  comfyui_node_lyrics_prompt TEXT,
  comfyui_node_bpm TEXT,
  comfyui_node_keyscale TEXT,
  comfyui_node_duration TEXT,
  comfyui_node_creativity TEXT,
  comfyui_node_seed TEXT
);
INSERT OR IGNORE INTO site_settings (id) VALUES (1);

CREATE TABLE IF NOT EXISTS generated_songs (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
  job_id TEXT UNIQUE,
  status TEXT NOT NULL DEFAULT 'pending',
  audio_path TEXT,
  style_prompt TEXT,
  lyrics_prompt TEXT,
  bpm INTEGER,
  keyscale TEXT,
  duration_seconds INTEGER,
  creativity INTEGER,
  seed INTEGER,
  error_message TEXT,
  created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
  completed_at DATETIME
);
CREATE INDEX IF NOT EXISTS generated_songs_user ON generated_songs (user_id, created_at DESC);
