-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
62 additions
and
14 deletions.
There are no files selected for viewing
76 changes: 62 additions & 14 deletions
76
posthog/migrations/0458_alter_insightviewed_team_alter_insightviewed_user.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
""", | ||
), | ||
], | ||
), | ||
] |