Skip to content

Commit

Permalink
Adjust migration
Browse files Browse the repository at this point in the history
  • Loading branch information
webjunkie committed Aug 21, 2024
1 parent 3b2a7da commit 8f02219
Showing 1 changed file with 62 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,28 +1,76 @@
# Generated by Django 4.2.14 on 2024-08-19 10:03
# Generated by Django 4.2.14 on 2024-08-21 07:01

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):
atomic = False # Allow concurrent operations

dependencies = [
("posthog", "0457_datawarehousejoin_deleted_at_and_more"),
]

operations = [
migrations.AlterField(
model_name="insightviewed",
name="team",
field=models.ForeignKey(
blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to="posthog.team"
),
),
migrations.AlterField(
model_name="insightviewed",
name="user",
field=models.ForeignKey(
blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL
),
migrations.SeparateDatabaseAndState(
state_operations=[
migrations.AlterField(
model_name="insightviewed",
name="team",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.CASCADE,
to="posthog.team",
),
),
migrations.AlterField(
model_name="insightviewed",
name="user",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.CASCADE,
to=settings.AUTH_USER_MODEL,
),
),
],
database_operations=[
migrations.RunSQL(
"""
-- Drop the existing constraint on the team_id column
ALTER TABLE "posthog_insightviewed" DROP CONSTRAINT IF EXISTS "posthog_insightviewed_team_id_167733dd_fk_posthog_team_id";
-- Drop the NOT NULL constraint from the team_id column
ALTER TABLE "posthog_insightviewed" ALTER COLUMN "team_id" DROP NOT NULL;
-- Add the foreign key constraint back with DEFERRABLE INITIALLY DEFERRED to avoid blocking
ALTER TABLE "posthog_insightviewed" ADD CONSTRAINT "posthog_insightviewed_team_id_167733dd_fk_posthog_team_id" FOREIGN KEY ("team_id") REFERENCES "posthog_team" ("id") DEFERRABLE INITIALLY DEFERRED;
-- Enforce the constraint immediately
SET CONSTRAINTS "posthog_insightviewed_team_id_167733dd_fk_posthog_team_id" IMMEDIATE;
""",
reverse_sql="""
ALTER TABLE "posthog_insightviewed" DROP CONSTRAINT IF EXISTS "posthog_insightviewed_team_id_167733dd_fk_posthog_team_id";
ALTER TABLE "posthog_insightviewed" ALTER COLUMN "team_id" SET NOT NULL;
ADD CONSTRAINT "posthog_insightviewed_team_id_167733dd_fk_posthog_team_id" FOREIGN KEY ("team_id") REFERENCES "posthog_team" ("id");
""",
),
migrations.RunSQL(
"""
-- Drop the existing constraint on the user_id column
ALTER TABLE "posthog_insightviewed" DROP CONSTRAINT IF EXISTS "posthog_insightviewed_user_id_6ec3e25a_fk_posthog_user_id";
-- Drop the NOT NULL constraint from the user_id column
ALTER TABLE "posthog_insightviewed" ALTER COLUMN "user_id" DROP NOT NULL;
-- Add the foreign key constraint back with DEFERRABLE INITIALLY DEFERRED to avoid blocking
ALTER TABLE "posthog_insightviewed" ADD CONSTRAINT "posthog_insightviewed_user_id_6ec3e25a_fk_posthog_user_id" FOREIGN KEY ("user_id") REFERENCES "posthog_user" ("id") DEFERRABLE INITIALLY DEFERRED;
-- Enforce the constraint immediately
SET CONSTRAINTS "posthog_insightviewed_user_id_6ec3e25a_fk_posthog_user_id" IMMEDIATE;
""",
reverse_sql="""
ALTER TABLE "posthog_insightviewed" DROP CONSTRAINT IF EXISTS "posthog_insightviewed_user_id_6ec3e25a_fk_posthog_user_id";
ALTER TABLE "posthog_insightviewed" ALTER COLUMN "user_id" SET NOT NULL;
ADD CONSTRAINT "posthog_insightviewed_user_id_6ec3e25a_fk_posthog_user_id" FOREIGN KEY ("user_id") REFERENCES "posthog_user" ("id");
""",
),
],
),
]

0 comments on commit 8f02219

Please sign in to comment.