Skip to content

Commit

Permalink
Update migrations.
Browse files Browse the repository at this point in the history
* Combine waffle switch migrations.
* Set invisible and inactive registration schemas.
  • Loading branch information
caseyrollins committed Nov 30, 2018
1 parent ff50c49 commit 2146788
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 29 deletions.
Expand Up @@ -14,5 +14,6 @@ class Migration(migrations.Migration):
]

operations = [
AddWaffleSwitch(features.ENABLE_INACTIVE_SCHEMAS, active=False)
AddWaffleSwitch(features.ENABLE_INACTIVE_SCHEMAS, active=False),
AddWaffleSwitch(features.OSF_PREREGISTRATION, active=False)
]
Expand Up @@ -7,7 +7,7 @@
class Migration(migrations.Migration):

dependencies = [
('osf', '0145_prereg_winddown_switch'),
('osf', '0144_add_prereg_winddown_switches'),
]

operations = [
Expand Down
19 changes: 0 additions & 19 deletions osf/migrations/0145_prereg_winddown_switch.py

This file was deleted.

Expand Up @@ -3,26 +3,30 @@

from django.db import migrations

from osf.utils.migrations import UpdateRegistrationSchemas

V2_INVISIBLE_SCHEMAS = [
'RIDIE Registration - Study Complete',
'RIDIE Registration - Study Initiation',
'EGAP Project',
'Confirmatory - General',
]

V2_INACTIVE_SCHEMAS = [
'Election Research Preacceptance Competition',
'OSF Preregistration',
]

def remove_version_1_schemas(state, schema):
RegistrationSchema = state.get_model('osf', 'registrationschema')
assert RegistrationSchema.objects.filter(schema_version=1, abstractnode__isnull=False).count() == 0
assert RegistrationSchema.objects.filter(schema_version=1, draftregistration__isnull=False).count() == 0
RegistrationSchema.objects.filter(schema_version=1).delete()

def set_invisible_schemas(state, schema):
RegistrationSchema = state.get_model('osf', 'registrationschema')
RegistrationSchema.objects.filter(name__in=V2_INVISIBLE_SCHEMAS).update(visible=False)

def unset_invisible_schemas(state, schema):
def update_v2_schemas(state, schema):
RegistrationSchema = state.get_model('osf', 'registrationschema')
RegistrationSchema.objects.filter(name__in=V2_INVISIBLE_SCHEMAS).update(visible=True)
RegistrationSchema.objects.filter(name__in=V2_INVISIBLE_SCHEMAS).update(visible=False, active=False)
RegistrationSchema.objects.filter(name__in=V2_INACTIVE_SCHEMAS).update(active=False)

def noop(*args, **kwargs):
pass
Expand All @@ -31,10 +35,11 @@ def noop(*args, **kwargs):
class Migration(migrations.Migration):

dependencies = [
('osf', '0146_add_visible_to_registrationschema'),
('osf', '0145_add_visible_to_registrationschema'),
]

operations = [
migrations.RunPython(remove_version_1_schemas, noop),
migrations.RunPython(set_invisible_schemas, unset_invisible_schemas),
UpdateRegistrationSchemas(),
migrations.RunPython(update_v2_schemas, noop),
]

0 comments on commit 2146788

Please sign in to comment.