-
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 #1053 - cohort genotype versions - make common cohort version m…
…atch cohort.version
- Loading branch information
Showing
5 changed files
with
82 additions
and
9 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
snpdb/migrations/0132_alter_cohortgenotypecollection_unique_together_and_more.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,26 @@ | ||
# Generated by Django 4.2.10 on 2024-05-20 01:39 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('snpdb', '0131_download_liftover_chain_files'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterUniqueTogether( | ||
name='cohortgenotypecollection', | ||
unique_together=set(), | ||
), | ||
migrations.AddField( | ||
model_name='cohortgenotypecollection', | ||
name='collection_type', | ||
field=models.CharField(choices=[('C', 'Common'), ('U', 'Uncommon')], default='U', max_length=1), | ||
), | ||
migrations.AlterUniqueTogether( | ||
name='cohortgenotypecollection', | ||
unique_together={('cohort', 'cohort_version', 'collection_type')}, | ||
), | ||
] |
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,27 @@ | ||
# Generated by Django 4.2.10 on 2024-05-20 01:39 | ||
|
||
from django.db import migrations | ||
from django.db.models import Subquery, OuterRef | ||
|
||
|
||
def _one_off_set_cgc_common(apps, _schema_editor): | ||
CohortGenotypeCollection = apps.get_model("snpdb", "CohortGenotypeCollection") | ||
Cohort = apps.get_model("snpdb", "Cohort") | ||
|
||
CGC_COMMON = "C" | ||
|
||
# To avoid the unique_together (cohort/version) the common ones were left as 0 | ||
cgc_qs = CohortGenotypeCollection.objects.filter(common_filter__isnull=False, cohort_version=0) | ||
cohort_version_subquery = Subquery(Cohort.objects.filter(id=OuterRef('cohort_id')).values('version')[:1]) | ||
cgc_qs.update(collection_type=CGC_COMMON, cohort_version=cohort_version_subquery) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('snpdb', '0132_alter_cohortgenotypecollection_unique_together_and_more'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(_one_off_set_cgc_common, reverse_code=lambda _, __: None), | ||
] |
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
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
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