thermograph/infra/deploy/migrations/001-user-discord-id.sql
Emi Griffith ae1d9bb534 Subtree-merge thermograph-infra (origin/main) into infra/
git-subtree-dir: infra
git-subtree-mainline: d6df04eab2
git-subtree-split: 99b4b3f78d
2026-07-22 22:01:11 -07:00

17 lines
980 B
SQL

-- Adds User.discord_id for Discord account linking (backend/discord_link.py).
--
-- This project has no Alembic: SQLAlchemy create_all() only creates *missing
-- tables*, so it will NOT add this column to an existing accounts DB. deploy.sh
-- and deploy-dev.sh run deploy/migrate-db.py, which applies the pending files
-- here on every deploy (tracked in a schema_migrations table, backing the DB up
-- first). A fresh DB gets the column + uniqueness from the model and is baselined
-- rather than ALTERed. To apply by hand instead (back the DB up first):
--
-- sqlite3 /opt/thermograph/data/accounts.sqlite < deploy/migrations/001-user-discord-id.sql
ALTER TABLE user ADD COLUMN discord_id VARCHAR(32);
-- SQLite can't add a UNIQUE column via ALTER, so enforce it with a partial unique
-- index (NULLs are allowed to repeat; a real id links to at most one account).
CREATE UNIQUE INDEX IF NOT EXISTS ix_user_discord_id
ON user (discord_id) WHERE discord_id IS NOT NULL;