Skip to content

Commit

Permalink
Create index concurrently
Browse files Browse the repository at this point in the history
  • Loading branch information
Twixes committed Oct 21, 2024
1 parent da72e7b commit 2d0726d
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions posthog/migrations/0495_grouptypemapping_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,37 @@


class Migration(migrations.Migration):
atomic = False # Added to support concurrent index creation
dependencies = [
("posthog", "0494_team_project_non_null"),
]

operations = [
migrations.AddField(
model_name="grouptypemapping",
name="project",
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to="posthog.project"),
migrations.SeparateDatabaseAndState(
state_operations=[
migrations.AddField(
model_name="grouptypemapping",
name="project",
field=models.ForeignKey(
null=True, on_delete=django.db.models.deletion.CASCADE, to="posthog.project"
),
),
],
database_operations=[
migrations.RunSQL(
"""
ALTER TABLE "posthog_grouptypemapping" ADD COLUMN "project_id" bigint NULL CONSTRAINT "posthog_grouptypemap_project_id_239c0515_fk_posthog_p" REFERENCES "posthog_project"("id") DEFERRABLE INITIALLY DEFERRED;
SET CONSTRAINTS "posthog_grouptypemap_project_id_239c0515_fk_posthog_p" IMMEDIATE;""",
reverse_sql="""
ALTER TABLE "posthog_grouptypemapping" DROP COLUMN IF EXISTS "project_id";""",
),
# We add CONCURRENTLY to the create command
migrations.RunSQL(
"""
CREATE INDEX CONCURRENTLY "posthog_grouptypemapping_project_id_239c0515" ON "posthog_grouptypemapping" ("project_id");""",
reverse_sql="""
DROP INDEX IF EXISTS "posthog_grouptypemapping_project_id_239c0515";""",
),
],
),
]

0 comments on commit 2d0726d

Please sign in to comment.