Skip to content

Commit

Permalink
Temporarily make migrations SQLite-compatible
Browse files Browse the repository at this point in the history
These migrations include PostgreSQL-specific syntax and will not run
properly against SQLite. This commit temporarily comments them out.

A preferred solution is to squash these migrations away, which is
proposed in consumerfinance.gov cfpb#8701.
  • Loading branch information
chosak committed Jan 6, 2025
1 parent 46bd283 commit 7fb1479
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 52 deletions.
26 changes: 1 addition & 25 deletions cfgov/v1/migrations/0015_grouppagepermission_index_fix.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,9 @@
from django.db import migrations


# This is a one-off fix to convert an existing unique index on a Wagtail
# table into a unique constraint. See internal Design-and-Content-Team#389.
#
# https://github.com/wagtail/wagtail/blob/b6ba78de814f9bc293e55957ac70d890d950053e/wagtail/models/__init__.py#L3060
table_name = "wagtailcore_grouppagepermission"


index_name = "idx_17388_wagtailcore_grouppagepermission_group_id_16e761a17265"


# "nosec" is used here to suppress Bandit warning about this raw SQL.
# https://bandit.readthedocs.io/en/1.7.6/plugins/b608_hardcoded_sql_expressions.html
sql = f"""
DO $$ BEGIN
IF EXISTS (SELECT FROM pg_indexes WHERE indexname='{index_name}') THEN
DROP INDEX {index_name};
ALTER TABLE {table_name} ADD CONSTRAINT {index_name} UNIQUE(group_id, page_id, permission_type);
END IF;
END $$;
""".strip() # nosec


class Migration(migrations.Migration):
dependencies = [
("v1", "0014_update_ds_links"),
]

operations = [
migrations.RunSQL(sql, migrations.RunSQL.noop, elidable=True)
]
operations = []
27 changes: 0 additions & 27 deletions cfgov/v1/migrations/0033_wagtailsearch_querydailyhits_index_fix.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,6 @@

from django.db import migrations

# This is a one-off fix to convert an existing unique index on a Wagtail
# table into a unique constraint. See internal Design-and-Content-Team#389
# for a description of the problem with a different constraint,
# https://github.com/cfpb/consumerfinance.gov/pull/8066 for the fix this is
# based on.
#
# The mode QueryDailyHits is and its `UNIQUE` constraints are removed in
# wagtail.search.migrations.0008_remove_query_and_querydailyhits_models.py
# in Wagtail 6.0. This migration will prepare our database for the constraint's
# constraint's removal.

table_name = "wagtailsearch_querydailyhits"
index_name = "idx_17496_wagtailsearch_querydailyhits_query_id_4e12c633921cb0c"
unique_together = "query_id, date"

# nosec used here to suppress Bandit warning about this raw SQL.
# https://bandit.readthedocs.io/en/latest/plugins/b608_hardcoded_sql_expressions.html
sql = f"""
DO $$ BEGIN
IF EXISTS (SELECT FROM pg_indexes WHERE indexname='{index_name}') THEN
DROP INDEX {index_name};
ALTER TABLE {table_name} ADD CONSTRAINT {index_name} UNIQUE({unique_together});
END IF;
END $$;
""".strip() # nosec B608


class Migration(migrations.Migration):
dependencies = [
Expand All @@ -39,5 +13,4 @@ class Migration(migrations.Migration):
]

operations = [
migrations.RunSQL(sql, migrations.RunSQL.noop, elidable=True)
]

0 comments on commit 7fb1479

Please sign in to comment.