Fix v0.2.8 migration: backfill org_id instead of a bare NOT NULL add #20
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/token-org-id-migration"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Follow-up to #19.
Token.OrgIDlanded asNOT NULLwith no default, so AutoMigrate'sALTER TABLE api_tokens ADD COLUMN org_id ... NOT NULLfails against Postgres once the table has existing rows — which it does, since tokens were created via the tokens page before org scoping existed. This is why the v0.2.8 migration failed on redeploy.Fix, following the same pattern already used for
org_members.role(default:member) and the existing post-AutoMigrate backfill steps indb.go:org_idgetsdefault:0so the column add succeeds even with existing rowsbackfillTokenOrgIDstep sets each org-less token'sorg_idto its account's earliest org membership (accounts with no org membership are left at 0)TestBackfillTokenOrgIDcovering: backfill happens, an already-scoped token is left untouched, and an orphan account (no org membership) is left at the defaultgo build/go test ./...pass.