24 lines · 926 B
-- Adds the optional webview: a "View full email" link sent alongside the
-- chat message, backed by a sealed copy of the body that expires after a
-- week. Off unless an owner turns it on with /webview, so this table stays
-- empty on a deployment nobody opts into.
--
-- Only needed for databases created before this existed; schema.sql already
-- includes it for fresh installs.
--
--   wrangler d1 execute cinderbox --remote --file=migrations/0009_add_webview.sql

ALTER TABLE owner_preferences ADD COLUMN webview INTEGER NOT NULL DEFAULT 0;

CREATE TABLE webview_messages (
  id TEXT PRIMARY KEY,
  owner_type TEXT NOT NULL,
  owner_id TEXT NOT NULL,
  created_at INTEGER NOT NULL,
  expires_at INTEGER NOT NULL,
  iv TEXT NOT NULL,
  ciphertext TEXT NOT NULL
);
CREATE INDEX idx_webview_messages_expires ON webview_messages(expires_at);
CREATE INDEX idx_webview_messages_owner ON webview_messages(owner_type, owner_id);