CREATE TABLE IF NOT EXISTS sidebar_shortcuts (
  id TEXT PRIMARY KEY,
  user_id TEXT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
  workspace_id TEXT NOT NULL,
  kind TEXT NOT NULL,
  source_kind TEXT NOT NULL DEFAULT 'local_folder',
  target_id TEXT NOT NULL,
  relative_path TEXT,
  document_id TEXT,
  title TEXT NOT NULL,
  icon TEXT,
  sort_order INTEGER NOT NULL DEFAULT 0,
  status TEXT NOT NULL DEFAULT 'active',
  metadata_json TEXT NOT NULL DEFAULT '{}',
  created_at TEXT NOT NULL,
  updated_at TEXT NOT NULL,
  revision INTEGER NOT NULL DEFAULT 1,
  UNIQUE(user_id, workspace_id, kind, target_id)
);

CREATE INDEX IF NOT EXISTS idx_sidebar_shortcuts_user_workspace
  ON sidebar_shortcuts(user_id, workspace_id, status, sort_order);
