Skip to content
Snippets Groups Projects
Commit 4e03acd0 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

Merge branch 'migration-issue' into 'master'

migration script issue

See merge request !401
parents 6a9f984f fbd6eea1
No related branches found
Tags v1.1.0-alpha.0
1 merge request!401migration script issue
Pipeline #49065 passed
......@@ -7,47 +7,8 @@ from web.models.study import FOLLOW_UP_INCREMENT_IN_YEARS
from ..migration_functions import is_sqlite_db
patient_prefix = 'P'
patient_delta_time = str(1)
patient_delta_units = FOLLOW_UP_INCREMENT_IN_YEARS
patient_type_id = 1
control_prefix = 'L'
control_delta_time = str(4)
control_delta_units = FOLLOW_UP_INCREMENT_IN_YEARS
control_type_id = 2
auto_create_follow_up = str(True)
def fetch_subject_type_data(apps, schema_editor) -> None:
# noinspection PyPep8Naming
Study = apps.get_model("web", "Study")
study = Study.objects.get(pk=GLOBAL_STUDY_ID)
global patient_delta_time, patient_delta_units, control_delta_time, control_delta_units, auto_create_follow_up
patient_delta_time = str(study.default_delta_time_for_patient_follow_up)
patient_delta_units = study.default_delta_time_for_follow_up_units
control_delta_time = str(study.default_delta_time_for_control_follow_up)
control_delta_units = study.default_delta_time_for_follow_up_units
auto_create_follow_up = str(study.auto_create_follow_up)
if is_sqlite_db():
if auto_create_follow_up.lower() == "false":
auto_create_follow_up = "0"
else:
auto_create_follow_up = "1"
pass
def fetch_subject_type_id_data(apps, schema_editor) -> None:
# noinspection PyPep8Naming
SubjectType = apps.get_model("web", "SubjectType")
global patient_type_id, control_type_id
patient_type_id = SubjectType.objects.get(name='PATIENT').id
control_type_id = SubjectType.objects.get(name='CONTROL').id
pass
class Migration(migrations.Migration):
......@@ -56,30 +17,26 @@ class Migration(migrations.Migration):
]
operations = [
migrations.RunPython(fetch_subject_type_data),
migrations.RunSQL("insert into web_subjecttype " +
"(name, screening_number_prefix, follow_up_delta_time, follow_up_delta_units, "
"auto_create_follow_up, study_id) " +
"values(" +
"'PATIENT','" +
"select 'PATIENT' , '" +
patient_prefix + "', " +
patient_delta_time + ",'" +
patient_delta_units + "'," +
auto_create_follow_up + "," +
str(GLOBAL_STUDY_ID) + ")"),
"default_delta_time_for_patient_follow_up," +
"default_delta_time_for_follow_up_units," +
"auto_create_follow_up," +
"id from web_study"),
migrations.RunSQL("update web_studysubject " +
" set new_type_id = (select max(id) from web_subjecttype) where type = 'P'"),
migrations.RunSQL("insert into web_subjecttype " +
"(name, screening_number_prefix, follow_up_delta_time, follow_up_delta_units, "
"auto_create_follow_up, study_id) " +
"values(" +
"'CONTROL','" +
"select 'CONTROL' , '" +
control_prefix + "', " +
control_delta_time + ",'" +
control_delta_units + "'," +
auto_create_follow_up + "," +
str(GLOBAL_STUDY_ID) + ")"),
migrations.RunPython(fetch_subject_type_id_data),
migrations.RunSQL("update web_studysubject " +
" set new_type_id = " + str(patient_type_id) + " where type = 'P'"),
"default_delta_time_for_control_follow_up," +
"default_delta_time_for_follow_up_units," +
"auto_create_follow_up," +
"id from web_study"),
migrations.RunSQL("update web_studysubject " +
" set new_type_id = " + str(control_type_id) + " where type = 'C'"),
" set new_type_id = (select max(id) from web_subjecttype) where type = 'C'"),
]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment