ALTER TABLE user ADD COLUMN can_use_stems TINYINT(1) NOT NULL DEFAULT 0;

CREATE TABLE IF NOT EXISTS stem_jobs (
  id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  uuid CHAR(32) NOT NULL UNIQUE,
  user_id INT NOT NULL,
  original_filename VARCHAR(255) NOT NULL,
  safe_filename VARCHAR(255) NOT NULL,
  status ENUM('queued','analyzing','uploading','separating','processing','downloading','waveforms','completed','failed') NOT NULL DEFAULT 'queued',
  progress TINYINT UNSIGNED NOT NULL DEFAULT 0,
  stage VARCHAR(160) NOT NULL DEFAULT 'В опашката',
  bpm DECIMAL(6,2) NULL,
  musical_key VARCHAR(16) NULL,
  camelot_key VARCHAR(4) NULL,
  duration DECIMAL(10,3) NULL,
  error_message TEXT NULL,
  created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  started_at DATETIME NULL,
  completed_at DATETIME NULL,
  INDEX idx_stem_jobs_user_created (user_id, created_at),
  CONSTRAINT fk_stem_jobs_user FOREIGN KEY (user_id) REFERENCES user(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
