Skip to content

Commit

Permalink
issue #1146 - rename index for old deployments
Browse files Browse the repository at this point in the history
  • Loading branch information
davmlaw committed Sep 9, 2024
1 parent bafccdd commit 1f67304
Showing 1 changed file with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Generated by Django 4.2.15 on 2024-09-09 07:09

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('snpdb', '0144_add_vgc_descriptions'),
]

operations = [
# We need to explicitly inherit sequences now (see RelatedModelsPartitionModel)
# and when Django renames tables it doesn't rename indexes, so we need to rename it in old deployments
migrations.RunSQL(sql="""
DO $$
BEGIN
-- Check if the sequence exists
IF EXISTS (SELECT 1 FROM pg_class WHERE relname = 'snpdb_variantcount_id_seq' AND relkind = 'S') THEN
-- Rename the sequence
ALTER SEQUENCE snpdb_variantcount_id_seq RENAME TO snpdb_cohortgenotype_id_seq;
-- Update the table's column default to use the new sequence name
ALTER TABLE snpdb_cohortgenotype
ALTER COLUMN id
SET DEFAULT nextval('snpdb_cohortgenotype_id_seq'::regclass);
END IF;
END $$;
""", reverse_sql=migrations.RunSQL.noop)
]

0 comments on commit 1f67304

Please sign in to comment.