: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
feat(personhog): add tmp mirror tables for the identity service (#80907)
José Sequeira03e9d47d8d43
diff --git a/rust/persons_migrations/20260810000001_add_is_user_id_to_personhog_person_tmp.sql b/rust/persons_migrations/20260810000001_add_is_user_id_to_personhog_person_tmp.sqlnew file mode 100644index 000000000000..9f1fd06d9f1e--- /dev/null+++ b/rust/persons_migrations/20260810000001_add_is_user_id_to_personhog_person_tmp.sql@@ -0,0 +1,5 @@+-- personhog-identity can be pointed at this table via PERSON_TABLE; its read+-- paths select is_user_id, which the original mirror omitted. Nullable and+-- never written by personhog, so it stays NULL — present only so the mirror+-- serves the same column set as posthog_person.+ALTER TABLE personhog_person_tmp ADD COLUMN IF NOT EXISTS is_user_id INTEGER;diff --git a/rust/persons_migrations/20260810000002_add_tmp_identity_tables.sql b/rust/persons_migrations/20260810000002_add_tmp_identity_tables.sqlnew file mode 100644index 000000000000..14fcbcf6241a--- /dev/null+++ b/rust/persons_migrations/20260810000002_add_tmp_identity_tables.sql@@ -0,0 +1,46 @@+-- Shadow tables for running personhog-identity against the validation table+-- set (see PERSON_TABLE in the identity config). The person table is shadowed+-- by personhog_person_tmp; identity's sync plane writes the distinct id+-- mapping in the same transaction, and its ids come from the tmp person+-- sequence, so the mapping (and the hash-key-override rows the delete saga+-- clears by person_id) must live in the same namespace — the real tables'+-- ids belong to posthog_person, and posthog_persondistinctid's FK rejects+-- tmp-namespace ids outright.+--+-- This migration is idempotent and safe to re-run.++CREATE TABLE IF NOT EXISTS personhog_persondistinctid_tmp (+ id BIGINT GENERATED BY DEFAULT AS IDENTITY,+ distinct_id VARCHAR(400) NOT NULL,+ version BIGINT,+ person_id BIGINT NOT NULL,+ team_id INTEGER NOT NULL,+ is_deleted BOOLEAN NOT NULL DEFAULT false,+ CONSTRAINT personhog_persondistinctid_tmp_pkey PRIMARY KEY (id),+ -- Mirrors posthog_persondistinctid's FK so a dangling person_id fails on+ -- the validation set the same way it would on the real pair.+ CONSTRAINT personhog_persondistinctid_tmp_person_id_fkey+ FOREIGN KEY (team_id, person_id) REFERENCES personhog_person_tmp (team_id, id)+);++-- The stub-create ON CONFLICT (team_id, distinct_id) infers this index.+CREATE UNIQUE INDEX IF NOT EXISTS personhog_persondistinctid_tmp_team_distinct_idx+ ON personhog_persondistinctid_tmp (team_id, distinct_id);++CREATE INDEX IF NOT EXISTS personhog_persondistinctid_tmp_person_id_idx+ ON personhog_persondistinctid_tmp (person_id);++CREATE TABLE IF NOT EXISTS personhog_featureflaghashkeyoverride_tmp (+ id INTEGER GENERATED BY DEFAULT AS IDENTITY,+ feature_flag_key VARCHAR(400) NOT NULL,+ hash_key VARCHAR(400) NOT NULL,+ person_id BIGINT NOT NULL,+ team_id INTEGER NOT NULL,+ CONSTRAINT personhog_featureflaghashkeyoverride_tmp_pkey PRIMARY KEY (id)+);++CREATE UNIQUE INDEX IF NOT EXISTS personhog_featureflaghashkeyoverride_tmp_unique_idx+ ON personhog_featureflaghashkeyoverride_tmp (team_id, person_id, feature_flag_key);++CREATE INDEX IF NOT EXISTS personhog_featureflaghashkeyoverride_tmp_person_id_idx+ ON personhog_featureflaghashkeyoverride_tmp (person_id);