-- 017_pair_tokens_fk_cascade.sql — fix the self-contradictory FK on -- pair_tokens.created_by. -- -- Migration 006 declared: -- created_by BIGINT NOT NULL REFERENCES users(id) ON DELETE SET NULL -- which is impossible: ON DELETE SET NULL tries to write NULL into a NOT NULL -- column, so deleting an admin that had ever minted a pair token would fail -- with a not-null-violation instead of cleaning up the tokens. -- -- Forward-safe fix: drop the old FK constraint and re-add it as ON DELETE -- CASCADE. Deleting a user now removes the (short-lived, mostly-expired) pair -- tokens they created, which is the sane behavior for onboarding tokens. -- -- The constraint name from an inline column REFERENCES is auto-generated by -- Postgres as