-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
issue #1146 - rename index for old deployments
- Loading branch information
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
snpdb/migrations/0145_one_off_handle_renamed_table_inherited_index.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 |
---|---|---|
@@ -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) | ||
] |