:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(personhog): add the hash key override FK to the persons migrations (#104071)
Nick Best9e030d04d649
diff --git a/rust/persons_migrations/20260921000001_add_hash_key_override_person_fk.sql b/rust/persons_migrations/20260921000001_add_hash_key_override_person_fk.sqlnew file mode 100644index 000000000000..2fdd5ea73721--- /dev/null+++ b/rust/persons_migrations/20260921000001_add_hash_key_override_person_fk.sql@@ -0,0 +1,27 @@+-- The partition migration dropped the foreign key from+-- posthog_featureflaghashkeyoverride to posthog_person and nothing put it back,+-- so databases built from these migrations kept override rows after a person+-- delete. This restores it in the shape production already has, NOT VALID+-- included. Skipped where a key to posthog_person exists, and where+-- posthog_person is not partitioned (hobby), because its (id) primary key+-- cannot back a composite key. lock_timeout bounds the wait for the partition+-- locks; on timeout the file aborts unrecorded and the next run retries it.+SET LOCAL lock_timeout = '2s';++DO $$+BEGIN+ IF (SELECT relkind FROM pg_class WHERE oid = 'posthog_person'::regclass) = 'p'+ AND NOT EXISTS (+ SELECT 1+ FROM pg_constraint+ WHERE conrelid = 'posthog_featureflaghashkeyoverride'::regclass+ AND contype = 'f'+ AND confrelid = 'posthog_person'::regclass+ ) THEN+ ALTER TABLE posthog_featureflaghashkeyoverride+ ADD CONSTRAINT posthog_featureflagh_person_id_7e517f7c_fk_posthog_p+ FOREIGN KEY (team_id, person_id) REFERENCES posthog_person (team_id, id)+ ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED NOT VALID;+ END IF;+END+$$;