Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(Persons): Remove foreign key constraints for all persons models #27654

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

timgl
Copy link
Collaborator

@timgl timgl commented Jan 17, 2025

Problem

We want to move persons and related models into its own DB. In order to do that, we need to remove foreign key constraints.

In the below set of models (which we'll move to the new DB), change all foreign keys that don't reference each other (just team_ids and cohort for cohortpeople) into ints, so that we can only move these tables over (or vice versa)
Person
PersonDistinctId
PersonlessDistinctId
PersonOverrideMapping
PersonOverride
PendingPersonOverride
FlatPersonOverride
FeatureFlagHashKeyOverride
CohortPeople

Also remove persons from admin, just to avoid another write path/django doing funky things without foreign keys

Changes

👉 Stay up-to-date with PostHog coding conventions for a smoother review.

Does this work well for both Cloud and self-hosted?

How did you test this code?

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

This migration removes foreign key constraints from person-related tables to prepare for moving them to a separate database, focusing on decoupling these models from the main PostHog database.

  • Drops team_id and is_user_id foreign key constraints from posthog_person table
  • Removes team_id foreign key constraints from posthog_persondistinctid and posthog_personlessdistinctid tables
  • Removes team_id constraint from posthog_featureflaghashkeyoverride table
  • Drops cohort_id foreign key constraint from posthog_cohortpeople table

2 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings | Greptile

""",
)
],
state_operations=[],
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Empty state_operations means Django's ORM will still expect foreign key relationships. Ensure application code is updated accordingly.

@timgl timgl force-pushed the remove-fk-constraints-on-persons branch from 8bd7e4e to 9395c62 Compare January 17, 2025 19:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant