-- Migration: 012_add_record_extras
-- Description: 工作记录版本历史表 + 人员调站历史表
-- Date: 2026-08-01

CREATE TABLE IF NOT EXISTS record_versions (
  id         INTEGER PRIMARY KEY AUTOINCREMENT,
  record_id  TEXT    NOT NULL REFERENCES work_records(id),
  version_no INTEGER NOT NULL,
  title      TEXT,
  type       TEXT,
  platform   TEXT,
  description TEXT,
  attachments TEXT,
  edited_by  TEXT    NOT NULL,
  edited_at  TEXT    NOT NULL DEFAULT (datetime('now', 'localtime'))
);

CREATE INDEX IF NOT EXISTS idx_record_versions_record ON record_versions(record_id);

CREATE TABLE IF NOT EXISTS person_transfers (
  id         INTEGER PRIMARY KEY AUTOINCREMENT,
  person_id  INTEGER NOT NULL REFERENCES people(id),
  from_station TEXT  NOT NULL,
  to_station   TEXT  NOT NULL,
  reason     TEXT,
  operated_by TEXT NOT NULL,
  transferred_at TEXT NOT NULL DEFAULT (datetime('now', 'localtime'))
);

CREATE INDEX IF NOT EXISTS idx_person_transfers_person ON person_transfers(person_id);
