-- The Small Business MBA. Per-member responses to interactive resources.
-- Members fill workbooks/tools in directly on the site; their answers are saved
-- to their account (not downloaded), so the work stays on the platform and
-- follows them across devices. One row per (member, resource); `data` is a JSON
-- map of field key -> value (textareas, checkbox states, table-cell inputs).
-- Wiped automatically if the parent resource is removed (re-import).

CREATE TABLE IF NOT EXISTS resource_responses (
  user_id     TEXT NOT NULL,
  resource_id TEXT NOT NULL REFERENCES lesson_resources(id) ON DELETE CASCADE,
  data        TEXT NOT NULL DEFAULT '{}',
  updated_at  INTEGER NOT NULL,
  PRIMARY KEY (user_id, resource_id)
);
CREATE INDEX IF NOT EXISTS idx_resource_responses_user ON resource_responses(user_id);
