: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
# Generated by Django 4.2.28 on 2026-02-20 06:11
import django.db.models.deletion
from django.db import migrations, models
class UpdateParentLink(migrations.operations.base.Operation):
"""Atomically update a multi-table inheritance parent link (bases + ptr field)."""
reduces_to_sql = False
reversible = True
def __init__(self, model_name, old_base, new_base, ptr_field_name, ptr_field):
self.model_name = model_name
self.old_base = old_base
self.new_base = new_base
self.ptr_field_name = ptr_field_name
self.ptr_field = ptr_field
def state_forwards(self, app_label, state):
model_state = state.models[app_label, self.model_name.lower()]
model_state.bases = tuple(self.new_base if b == self.old_base else b for b in model_state.bases)
model_state.fields[self.ptr_field_name] = self.ptr_field
state.reload_model(app_label, self.model_name.lower())
def state_backwards(self, app_label, state):
model_state = state.models[app_label, self.model_name.lower()]
model_state.bases = tuple(self.old_base if b == self.new_base else b for b in model_state.bases)
# Reconstruct the old field pointing to the old base
old_field: models.Field = models.OneToOneField(
auto_created=True,
on_delete=django.db.models.deletion.CASCADE,
parent_link=True,
primary_key=True,
serialize=False,
to=self.old_base,
)
model_state.fields[self.ptr_field_name] = old_field
state.reload_model(app_label, self.model_name.lower())
def database_forwards(self, app_label, schema_editor, from_state, to_state):
pass
def database_backwards(self, app_label, schema_editor, from_state, to_state):
pass
def describe(self):
return f"Update parent link on {self.model_name} from {self.old_base} to {self.new_base}"
class Migration(migrations.Migration):
dependencies = [
("event_definitions", "0001_initial"),
("ee", "0037_add_conversation_approval_decisions"),
]
operations = [
migrations.SeparateDatabaseAndState(
database_operations=[],
state_operations=[
UpdateParentLink(
model_name="EnterpriseEventDefinition",
old_base="posthog.eventdefinition",
new_base="event_definitions.eventdefinition",
ptr_field_name="eventdefinition_ptr",
ptr_field=models.OneToOneField(
auto_created=True,
on_delete=django.db.models.deletion.CASCADE,
parent_link=True,
primary_key=True,
serialize=False,
to="event_definitions.eventdefinition",
),
),
UpdateParentLink(
model_name="EnterprisePropertyDefinition",
old_base="posthog.propertydefinition",
new_base="event_definitions.propertydefinition",
ptr_field_name="propertydefinition_ptr",
ptr_field=models.OneToOneField(
auto_created=True,
on_delete=django.db.models.deletion.CASCADE,
parent_link=True,
primary_key=True,
serialize=False,
to="event_definitions.propertydefinition",
),
),
],
),
]