-- pages.elijah.run — incremental migration: users.trusted + pages.trusted
--
-- pages-shqc: adds the admin-granted "trust" escape hatch (design §2.1
-- addendum) — trusted pages/users are served WITHOUT the CSP sandbox so
-- local-first apps (e.g. a habit tracker) can use localStorage. Effective
-- trust for a page is `pages.trusted OR <owner's> users.trusted`, computed
-- at serve time (src/db.rs::PageRow::effective_trust).
--
-- `migrations/schema.sql` already has both columns for fresh installs
-- (`CREATE TABLE IF NOT EXISTS` there is a no-op against a live DB that
-- already has the tables). This file is for the *existing* production D1
-- database, which needs the columns added in place.
--
-- SQLite has no `ALTER TABLE ... ADD COLUMN IF NOT EXISTS`, so re-running
-- this file against a database that has already applied it will fail with
-- an error like `duplicate column name: trusted` on each statement below —
-- that is expected and safe to ignore (same precedent as quotesdb's
-- `ALTER_QUOTES_ADD_HIDDEN` migration, src/db/migrations.rs). Do NOT run
-- this more than once per database; check first if unsure
-- (`PRAGMA table_info(users)` / `PRAGMA table_info(pages)`).
--
-- Apply with (NOT run automatically by this ticket — remote apply is a
-- separate, manual, human-triggered step):
--   wrangler d1 execute <DB_NAME> --file=migrations/0002-trust.sql          (remote)
--   wrangler d1 execute <DB_NAME> --local --file=migrations/0002-trust.sql  (local dev)

ALTER TABLE users ADD COLUMN trusted INTEGER NOT NULL DEFAULT 0;

ALTER TABLE pages ADD COLUMN trusted INTEGER NOT NULL DEFAULT 0;
