Skip to content

Commit

Permalink
migrations must be reversible
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverb123 committed Jul 24, 2024
1 parent 5fdf680 commit deed322
Showing 1 changed file with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,13 @@ class Migration(migrations.Migration):
ALTER TABLE "posthog_plugin" DROP CONSTRAINT "posthog_plugin_organization_id_d040b9a9_fk_posthog_o"; -- existing-table-constraint-ignore
ALTER TABLE "posthog_plugin" ALTER COLUMN "organization_id" DROP NOT NULL;
ALTER TABLE "posthog_plugin" ADD CONSTRAINT "posthog_plugin_organization_id_d040b9a9_fk_posthog_o" FOREIGN KEY ("organization_id") REFERENCES "posthog_organization" ("id") DEFERRABLE INITIALLY DEFERRED; -- existing-table-constraint-ignore
"""
""",
reverse_sql="""
SET CONSTRAINTS "posthog_plugin_organization_id_d040b9a9_fk_posthog_o" IMMEDIATE; -- existing-table-constraint-ignore
ALTER TABLE "posthog_plugin" DROP CONSTRAINT "posthog_plugin_organization_id_d040b9a9_fk_posthog_o"; -- existing-table-constraint-ignore
ALTER TABLE "posthog_plugin" ALTER COLUMN "organization_id" SET NOT NULL;
ALTER TABLE "posthog_plugin" ADD CONSTRAINT "posthog_plugin_organization_id_d040b9a9_fk_posthog_o" FOREIGN KEY ("organization_id") REFERENCES "posthog_organization" ("id") DEFERRABLE INITIALLY DEFERRED; -- existing-table-constraint-ignore
""",
),
],
),
Expand Down Expand Up @@ -65,13 +71,19 @@ class Migration(migrations.Migration):
migrations.RunSQL(
"""
ALTER TABLE "posthog_plugin" ADD CONSTRAINT "posthog_plugin_url_bccac89d_uniq" UNIQUE ("url"); -- existing-table-constraint-ignore
"""
""",
reverse_sql="""
ALTER TABLE "posthog_plugin" DROP CONSTRAINT IF EXISTS "posthog_plugin_url_bccac89d_uniq";
""",
),
# We add the index seperately
migrations.RunSQL(
"""
CREATE INDEX CONCURRENTLY "posthog_plugin_url_bccac89d_like" ON "posthog_plugin" ("url" varchar_pattern_ops);
"""
""",
reverse_sql="""
DROP INDEX IF EXISTS "posthog_plugin_url_bccac89d_like";
""",
),
],
),
Expand Down

0 comments on commit deed322

Please sign in to comment.