-- 账户与设备（SQLite 方言）
CREATE TABLE users (
  id          INTEGER PRIMARY KEY AUTOINCREMENT,
  uuid        TEXT NOT NULL UNIQUE,
  email       TEXT NOT NULL UNIQUE,
  pw_hash     TEXT NOT NULL,                       -- argon2id
  dp_uuid     TEXT NOT NULL,                       -- 数据面凭证 UUID（可轮换）
  status      TEXT NOT NULL DEFAULT 'active' CHECK (status IN ('active','banned')),
  created_at  DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE devices (
  id          INTEGER PRIMARY KEY AUTOINCREMENT,
  uuid        TEXT NOT NULL UNIQUE,
  user_id     INTEGER NOT NULL,
  name        TEXT NOT NULL,
  platform    TEXT NOT NULL CHECK (platform IN ('ios','android','windows','macos')),
  last_seen   DATETIME NULL,
  created_at  DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  FOREIGN KEY (user_id) REFERENCES users(id)
);
CREATE INDEX idx_devices_user ON devices (user_id);
