fix(db): restore is_demo_org dropped in #1500
Context & Requests for Reviewers
#1500 dropped org_settings.is_demo_org. Current code doesn't use it (#1448 removed it), but released versions up to 1.2.3 still read it (myOrg.isDemoOrg) and write it (ensureOrgSettingsRow). So if you migrate the DB before upgrading the app, or roll the app back, those versions break. #1500 hasn't shipped in a release yet. See RFC #1627 for more context.
This adds a new migration that brings the column back as it was before #1500 (boolean NOT NULL DEFAULT false, no index). It uses ADD COLUMN IF NOT EXISTS with lock_timeout = 5s. With a constant default, Postgres 11+ makes this a metadata-only change. The #1500 migration is unchanged. Current code still doesn't use the column, and a column comment marks it as kept only for compatibility.
Tests (executed by Claude Code)
- Replayed api-server-pg migrations on a fresh DB, on a DB at the pre-#1500 state, and on a DB at the post-#1500 state. All three end up with identical
pg_dump -sschemas. - Re-ran the migration on an already-migrated DB: it's a no-op.
- New integration test
org-settings-legacy-compat.integ.test.tsruns 1.2.3'sorg_settingsinsert andis_demo_orgread. It fails without the column and passes with it. pnpm --filter server run typecheck,lint,prettier, and the org GraphQL module andncmec-org-settingsintegration tests pass.
(Optional) Rollout Plan
#1500 hasn't shipped, so deployments <= 1.2.3 that upgrade run #1500's drop and then this migration back to back. While the two run, a live 1.2.3 app can briefly fail org-settings queries. If the 5s lock timeout is hit, rerun the migration (it is idempotent).
Release notes
Checklist
Only check items that apply to this PR; leave the rest unchecked.
-
If you changed anything user-facing (i.e. user interface or APIs):
Did you update related docs? -
If the change is notable (refer to Keep a Changelog conventions):
Did you fill in the Release notes section above? -
If this PR fixes a security vulnerability:
Did you apply thesecurity-updatelabel, or ask a maintainer to? Don't describe the vulnerability here before its advisory is published. -
If you changed
db/src/scripts/**and usedCREATE TABLE,ADD COLUMN, orALTER COLUMN:
Are as many columns markedNOT NULLas possible? If some columns can sometimes be null depending on other columns, are thereCHECKconstraints capturing those relationships, and are these also reflected using unions in the associated Kysely types? -
If you added a new signal in
server/services/signalsService/signals/**:
Did you classify every error case as a permanent error (SignalPermanentError, no retry) or a normal error (retryable)? Any case where the signal can't determine a score should be aSignalPermanentError.