diff --git a/smash/web/migration_functions.py b/smash/web/migration_functions.py new file mode 100644 index 0000000000000000000000000000000000000000..fe2d0d65b1b68780089b50eb288fd092cc613682 --- /dev/null +++ b/smash/web/migration_functions.py @@ -0,0 +1,8 @@ +from django.conf import settings + +db_name = 'default' +db_backend = settings.DATABASES[db_name]['ENGINE'].split('.')[-1] + + +def is_sqlite_db(): + return db_backend == 'sqlite3' diff --git a/smash/web/migrations/0030_subject_information_sent.py b/smash/web/migrations/0030_subject_information_sent.py index 6bef7fd371e208a5740a550b79c57f315636aaf8..2225e2787716ff79961c6ad284d2f0371bcc3010 100644 --- a/smash/web/migrations/0030_subject_information_sent.py +++ b/smash/web/migrations/0030_subject_information_sent.py @@ -2,7 +2,9 @@ # Generated by Django 1.10.3 on 2017-04-04 14:16 -from django.db import migrations, models +from django.db import migrations + +from ..migration_functions import is_sqlite_db class Migration(migrations.Migration): @@ -10,10 +12,19 @@ class Migration(migrations.Migration): ('web', '0029_auto_20170404_1616'), ] - operations = [ - migrations.RunSQL( - "update web_subject set information_sent=true where id in" + - "(select web_subject.id from web_appointment " + - " left join web_visit on visit_id = web_visit.id " + - " left join web_subject on web_visit.subject_id = web_subject.id where status = 'FINISHED');"), - ] + if is_sqlite_db(): + operations = [ + migrations.RunSQL( + "update web_subject set information_sent=1 where id in" + + "(select web_subject.id from web_appointment " + + " left join web_visit on visit_id = web_visit.id " + + " left join web_subject on web_visit.subject_id = web_subject.id where status = 'FINISHED');"), + ] + else: + operations = [ + migrations.RunSQL( + "update web_subject set information_sent=true where id in" + + "(select web_subject.id from web_appointment " + + " left join web_visit on visit_id = web_visit.id " + + " left join web_subject on web_visit.subject_id = web_subject.id where status = 'FINISHED');"), + ] diff --git a/smash/web/migrations/0039_pd_family_default_unknown.py b/smash/web/migrations/0039_pd_family_default_unknown.py index 7c718a07dde4a5defc9521e5d9c8e40752914cbd..d8f27658ff2c7fb3e8db7906b489e5028e66201f 100644 --- a/smash/web/migrations/0039_pd_family_default_unknown.py +++ b/smash/web/migrations/0039_pd_family_default_unknown.py @@ -4,6 +4,8 @@ from django.db import migrations, models +from ..migration_functions import is_sqlite_db + class Migration(migrations.Migration): dependencies = [ @@ -15,8 +17,14 @@ class Migration(migrations.Migration): model_name='subject', name='pd_in_family', field=models.NullBooleanField(default=None, verbose_name=b'PD in family'), - ), - migrations.RunSQL( - "UPDATE web_subject SET pd_in_family=NULL WHERE pd_in_family = FALSE;", - reverse_sql="UPDATE web_subject SET pd_in_family=FALSE WHERE pd_in_family = NULL;") - ] + )] + if is_sqlite_db(): + operations.append( + migrations.RunSQL( + "UPDATE web_subject SET pd_in_family=NULL WHERE pd_in_family = 0;", + reverse_sql="UPDATE web_subject SET pd_in_family=0 WHERE pd_in_family = NULL;")) + else: + operations.append( + migrations.RunSQL( + "UPDATE web_subject SET pd_in_family=NULL WHERE pd_in_family = FALSE;", + reverse_sql="UPDATE web_subject SET pd_in_family=FALSE WHERE pd_in_family = NULL;")) diff --git a/smash/web/migrations/0047_subject_flying_team_from_annotation.py b/smash/web/migrations/0047_subject_flying_team_from_annotation.py index 375fcb896572c7c5ff0fac648200856b65c5b495..4747e562d85c1daeedbb908caf4c2e51d3c3734e 100644 --- a/smash/web/migrations/0047_subject_flying_team_from_annotation.py +++ b/smash/web/migrations/0047_subject_flying_team_from_annotation.py @@ -2,21 +2,33 @@ # assigns default flying team location for subjects that had in the past finished appointment at flying team location - from django.db import migrations +from ..migration_functions import is_sqlite_db + class Migration(migrations.Migration): dependencies = [ ('web', '0046_subject_flying_team'), ] + if is_sqlite_db(): + operations = [ + migrations.RunSQL( + "update web_subject set flying_team_id = (select flying_team_id from web_visit, web_appointment " + + "where web_subject.id=web_visit.subject_id and " + + "web_visit.id = web_appointment.visit_id and " + + "web_appointment.flying_team_id is not null and status = 'FINISHED') " + "where web_subject.flying_team_id is null" - operations = [ - migrations.RunSQL( - "update web_subject set flying_team_id = web_appointment.flying_team_id from web_visit, web_appointment " + - "where web_subject.id=web_visit.subject_id and " + - "web_subject.flying_team_id is null and " + - "web_visit.id = web_appointment.visit_id and " + - "web_appointment.flying_team_id is not null and status = 'FINISHED';" - ), - ] + ), + ] + else: + operations = [ + migrations.RunSQL( + "update web_subject set flying_team_id = web_appointment.flying_team_id from web_visit, web_appointment " + + "where web_subject.id=web_visit.subject_id and " + + "web_subject.flying_team_id is null and " + + "web_visit.id = web_appointment.visit_id and " + + "web_appointment.flying_team_id is not null and status = 'FINISHED';" + ), + ] diff --git a/smash/web/migrations/0057_update_visit_number_for_existing_visits.py b/smash/web/migrations/0057_update_visit_number_for_existing_visits.py index 53f8c82d2e440dbe96a539d6b8cba6b4ebbf51a5..b9fbe5d17d51d475edac7d0ce71b94c577ab9f5c 100644 --- a/smash/web/migrations/0057_update_visit_number_for_existing_visits.py +++ b/smash/web/migrations/0057_update_visit_number_for_existing_visits.py @@ -2,7 +2,9 @@ # Generated by Django 1.10.7 on 2017-10-27 10:22 -from django.db import migrations, models +from django.db import migrations + +from ..migration_functions import is_sqlite_db class Migration(migrations.Migration): @@ -10,8 +12,15 @@ class Migration(migrations.Migration): ('web', '0056_visit_visit_number'), ] - operations = [ - migrations.RunSQL( - "update web_visit s set visit_number= (select count(*) from web_visit t " + - "where t.subject_id=s.subject_id and t.datetime_begin<= s.datetime_begin);") - ] + if is_sqlite_db(): + operations = [ + migrations.RunSQL( + "update web_visit set visit_number= (select count(*) from web_visit t " + + "where t.subject_id=subject_id and t.datetime_begin<= datetime_begin);") + ] + else: + operations = [ + migrations.RunSQL( + "update web_visit s set visit_number= (select count(*) from web_visit t " + + "where t.subject_id=s.subject_id and t.datetime_begin<= s.datetime_begin);") + ] diff --git a/smash/web/migrations/0060_remove_subject_country.py b/smash/web/migrations/0060_remove_subject_country.py index 872629057b5410ee6363382cbc1490641fc5a49c..7ec9f237a35be39cecd424780078cae820e9d2b8 100644 --- a/smash/web/migrations/0060_remove_subject_country.py +++ b/smash/web/migrations/0060_remove_subject_country.py @@ -4,6 +4,8 @@ from django.db import migrations, models +from ..migration_functions import is_sqlite_db + class Migration(migrations.Migration): dependencies = [ @@ -163,7 +165,8 @@ class Migration(migrations.Migration): migrations.RunSQL('insert into web_country (name, "order") values(\'Rwanda\', 244);'), migrations.RunSQL('insert into web_country (name, "order") values(\'St Kitts & Nevis\', 245);'), migrations.RunSQL('insert into web_country (name, "order") values(\'St Lucia\', 246);'), - migrations.RunSQL('insert into web_country (name, "order") values(\'Saint Vincent & the Grenadines\', 247);'), + migrations.RunSQL( + 'insert into web_country (name, "order") values(\'Saint Vincent & the Grenadines\', 247);'), migrations.RunSQL('insert into web_country (name, "order") values(\'Samoa\', 248);'), migrations.RunSQL('insert into web_country (name, "order") values(\'San Marino\', 249);'), migrations.RunSQL('insert into web_country (name, "order") values(\'Sao Tome & Principe\', 250);'), @@ -213,7 +216,12 @@ class Migration(migrations.Migration): migrations.RunSQL('insert into web_country (name, "order") values(\'Zambia\', 294);'), migrations.RunSQL('insert into web_country (name, "order") values(\'Zimbabwe\', 295);'), - migrations.RunSQL('update web_subject t set country_2_id = ' - 'case when (select id from web_country u where t.country=u.name) is Null then 1 ' - 'else (select id from web_country u where t.country=u.name) end;'), ] + if is_sqlite_db(): + operations.append(migrations.RunSQL('update web_subject set country_2_id = ' + 'case when (select id from web_country u where country=u.name) is Null then 1 ' + 'else (select id from web_country u where country=u.name) end;')) + else: + operations.append(migrations.RunSQL('update web_subject t set country_2_id = ' + 'case when (select id from web_country u where t.country=u.name) is Null then 1 ' + 'else (select id from web_country u where t.country=u.name) end;')) diff --git a/smash/web/migrations/0066_subject.py b/smash/web/migrations/0066_subject.py index 3b3fa93766dc8fa7f7e4879e40a31903c61f7f73..a0d3357d62299e6f926ebb27b38befef3ea692e9 100644 --- a/smash/web/migrations/0066_subject.py +++ b/smash/web/migrations/0066_subject.py @@ -2,9 +2,10 @@ # Generated by Django 1.10.7 on 2017-11-27 10:42 -from django.db import migrations, models -import django.db.models.deletion -from django import VERSION as DJANGO_VERSION +from django.db import migrations + +from ..migration_functions import is_sqlite_db + class Migration(migrations.Migration): @@ -12,26 +13,7 @@ class Migration(migrations.Migration): ('web', '0065_auto_20171127_0957'), ] - if DJANGO_VERSION[:2] < (1, 11): - operations = [ - migrations.RunSQL('alter sequence web_subject_id_seq rename to web_studysubject_id_seq;'), - migrations.RunSQL('alter sequence web_subject_languages_id_seq rename to web_studysubject_languages_id_seq;'), - migrations.RunSQL('alter table web_studysubject rename constraint web_subject_flying_team_id_ef78de5d_fk_web_flyingteam_id to web_studysubject_flying_team_id_ef78de5d_fk_web_flyingteam_id;'), - migrations.RunSQL('alter table web_studysubject_languages rename constraint web_subject_languages_language_id_80eca4c1_fk_web_language_id to web_studysubject_languages_language_id_80eca4c1_fk_web_language_id;'), - migrations.RunSQL('alter table web_studysubject rename constraint web_subject_country_id_5d976875_fk_web_country_id to web_studysubject_country_id_5d976875_fk_web_country_id;'), - migrations.RunSQL('alter table web_studysubject rename constraint web_subject_default_location_id_da83b714_fk_web_location_id to web_studyubject_default_location_id_da83b714_fk_web_location_id;'), - migrations.RunSQL('alter table web_studysubject rename constraint web_subject_pkey to web_studysubject_pkey;'), - migrations.RunSQL('alter table web_studysubject_languages rename constraint web_subject_languages_pkey to web_studysubject_languages_pkey;'), - migrations.RunSQL('alter table web_studysubject_languages rename constraint web_subject_languages_subject_id_a5eb4f49_uniq to web_studysubject_languages_subject_id_a5eb4f49_uniq;'), - migrations.RunSQL('alter index if exists web_subject_15d1b6cd rename to web_studysubject_15d1b6cd;'), - migrations.RunSQL('alter index if exists web_subject_496f9482 rename to web_studysubject_496f9482;'), - migrations.RunSQL('alter index if exists web_subject_84b500ff rename to web_studysubject_84b500ff;'), - migrations.RunSQL('alter index if exists web_subject_9571fdf9 rename to web_studysubject_9571fdf9;'), - migrations.RunSQL('alter index if exists web_subject_languages_468679bd rename to web_studysubject_languages_468679bd;'), - migrations.RunSQL('alter index if exists web_subject_languages_ffaba1d1 rename to web_studysubject_languages_ffaba1d1;'), - migrations.RunSQL('alter index if exists web_subject_screening_number_75aa70c7_like rename to web_studysubject_screening_number_75aa70c7_like;') - ] - else: + if not is_sqlite_db(): operations = [ migrations.RunSQL('alter sequence web_subject_id_seq rename to web_studysubject_id_seq;'), migrations.RunSQL('alter sequence web_subject_languages_id_seq rename to web_studysubject_languages_id_seq;'), @@ -50,3 +32,5 @@ class Migration(migrations.Migration): migrations.RunSQL('alter index if exists web_subject_languages_ffaba1d1 rename to web_studysubject_languages_ffaba1d1;'), migrations.RunSQL('alter index if exists web_subject_screening_number_75aa70c7_like rename to web_studysubject_screening_number_75aa70c7_like;') ] + else: + operations = [] diff --git a/smash/web/migrations/0067_subject.py b/smash/web/migrations/0067_subject.py index 42d8161b890631c54629120b78c11f49ea4a71ad..890b3572f02498e8d25b039f34374878494bd116 100644 --- a/smash/web/migrations/0067_subject.py +++ b/smash/web/migrations/0067_subject.py @@ -4,6 +4,7 @@ import django.db.models.deletion from django.db import migrations, models +from ..migration_functions import is_sqlite_db class Migration(migrations.Migration): @@ -11,10 +12,17 @@ class Migration(migrations.Migration): ('web', '0066_subject'), ] - operations = [ - migrations.RunSQL('alter index if exists web_subject_default_written_communication_language_id_0bce1d22 rename to web_studysubject_default_written_communication_language_id_0bce1d22;'), - migrations.RunSQL('alter index if exists web_subject_languages_subject_id_2cf93044 rename to web_studysubject_languages_subject_id_2cf93044;'), - migrations.RunSQL('alter index if exists web_subject_languages_language_id_80eca4c1 rename to web_studysubject_languages_language_id_80eca4c1;'), + operations = [] + if not is_sqlite_db(): + operations = operations + [ + migrations.RunSQL( + 'alter index if exists web_subject_default_written_communication_language_id_0bce1d22 rename to web_studysubject_default_written_communication_language_id_0bce1d22;'), + migrations.RunSQL( + 'alter index if exists web_subject_languages_subject_id_2cf93044 rename to web_studysubject_languages_subject_id_2cf93044;'), + migrations.RunSQL( + 'alter index if exists web_subject_languages_language_id_80eca4c1 rename to web_studysubject_languages_language_id_80eca4c1;'), + ] + operations = operations + [ migrations.CreateModel( name='Subject', fields=[ diff --git a/smash/web/migrations/0079_auto_20171204_1235.py b/smash/web/migrations/0079_auto_20171204_1235.py index a02da51ce887069f0345e29669ed5c10509d26f5..e8f0588c25c8530dcce06a6857fb04976f933373 100644 --- a/smash/web/migrations/0079_auto_20171204_1235.py +++ b/smash/web/migrations/0079_auto_20171204_1235.py @@ -5,6 +5,8 @@ import django.db.models.deletion from django.db import migrations, models +from ..migration_functions import is_sqlite_db + class Migration(migrations.Migration): dependencies = [ @@ -34,23 +36,36 @@ class Migration(migrations.Migration): ('unfinished_appointments_visible', models.BooleanField(default=True, verbose_name=b'unfinished appointments')), ], - ), - migrations.RunSQL('insert into web_studynotificationparameters (exceeded_visits_visible,' + - 'missing_redcap_subject_visible,' + - 'inconsistent_redcap_subject_visible,' + - 'subject_require_contact_visible,' + - 'subject_no_visits_visible,' + - 'unfinished_visits_visible,' + - 'visits_with_missing_appointments_visible,' + - 'approaching_visits_without_appointments_visible,' + - 'approaching_visits_for_mail_contact_visible,' + - 'unfinished_appointments_visible' + - ') values(true, true, true, true, true, true, true, true, true, true)'), - migrations.AddField( - model_name='study', - name='notification_parameters', - field=models.OneToOneField(default=1, on_delete=django.db.models.deletion.CASCADE, - to='web.StudyNotificationParameters'), - preserve_default=False, - ), - ] + )] + + if not is_sqlite_db(): + operations.append(migrations.RunSQL('insert into web_studynotificationparameters (exceeded_visits_visible,' + + 'missing_redcap_subject_visible,' + + 'inconsistent_redcap_subject_visible,' + + 'subject_require_contact_visible,' + + 'subject_no_visits_visible,' + + 'unfinished_visits_visible,' + + 'visits_with_missing_appointments_visible,' + + 'approaching_visits_without_appointments_visible,' + + 'approaching_visits_for_mail_contact_visible,' + + 'unfinished_appointments_visible' + + ') values(true, true, true, true, true, true, true, true, true, true)')) + else: + operations.append(migrations.RunSQL('insert into web_studynotificationparameters (exceeded_visits_visible,' + + 'missing_redcap_subject_visible,' + + 'inconsistent_redcap_subject_visible,' + + 'subject_require_contact_visible,' + + 'subject_no_visits_visible,' + + 'unfinished_visits_visible,' + + 'visits_with_missing_appointments_visible,' + + 'approaching_visits_without_appointments_visible,' + + 'approaching_visits_for_mail_contact_visible,' + + 'unfinished_appointments_visible' + + ') values(1, 1, 1, 1, 1, 1, 1, 1, 1, 1)')) + operations.append(migrations.AddField( + model_name='study', + name='notification_parameters', + field=models.OneToOneField(default=1, on_delete=django.db.models.deletion.CASCADE, + to='web.StudyNotificationParameters'), + preserve_default=False, + )) diff --git a/smash/web/migrations/0080_auto_20171204_1341.py b/smash/web/migrations/0080_auto_20171204_1341.py index 6988fe552f44ce3073f7107fe70efc6f4790becb..07c8ee1a842eac8c287934b55431bcb7dba6aa99 100644 --- a/smash/web/migrations/0080_auto_20171204_1341.py +++ b/smash/web/migrations/0080_auto_20171204_1341.py @@ -4,6 +4,8 @@ from django.db import migrations, models +from ..migration_functions import is_sqlite_db + # noinspection PyUnusedLocal # noinspection PyPep8Naming @@ -61,11 +63,15 @@ class Migration(migrations.Migration): name='datetime_contact_reminder', field=models.BooleanField(choices=[(True, b'Yes'), (False, b'No')], default=True, verbose_name=b'Last contact attempt'), - ), - migrations.RunSQL('UPDATE web_studycolumns SET datetime_contact_reminder =FALSE WHERE ' + - 'NOT(id IN (SELECT columns_id FROM web_study));'), + )] + if is_sqlite_db(): + operations.append(migrations.RunSQL('UPDATE web_studycolumns SET datetime_contact_reminder =0 WHERE ' + + 'NOT(id IN (SELECT columns_id FROM web_study));')) + else: + operations.append(migrations.RunSQL('UPDATE web_studycolumns SET datetime_contact_reminder =FALSE WHERE ' + + 'NOT(id IN (SELECT columns_id FROM web_study));')) - migrations.RunPython(create_default_columns_for_SUBJECT_LIST_REQUIRE_CONTACT), + operations = operations + [migrations.RunPython(create_default_columns_for_SUBJECT_LIST_REQUIRE_CONTACT), migrations.RunSQL('INSERT INTO web_studysubjectlist (' + 'study_id, ' + diff --git a/smash/web/migrations/0081_studysubjectlist_last_contact_attempt.py b/smash/web/migrations/0081_studysubjectlist_last_contact_attempt.py index da4c5e8bc3542e32a76b55564122df2be82a19d9..c3f963b4872f1da250feabfd8eb6f0b227713abc 100644 --- a/smash/web/migrations/0081_studysubjectlist_last_contact_attempt.py +++ b/smash/web/migrations/0081_studysubjectlist_last_contact_attempt.py @@ -4,6 +4,8 @@ from django.db import migrations, models +from ..migration_functions import is_sqlite_db + # noinspection PyUnusedLocal # noinspection PyPep8Naming @@ -67,19 +69,34 @@ class Migration(migrations.Migration): field=models.BooleanField(default=False, verbose_name=b'Last contact attempt'), ), migrations.RunPython(create_default_columns_for_SUBJECT_LIST_NO_VISIT), - - migrations.RunSQL('INSERT INTO web_studysubjectlist (' + - 'study_id, ' + - 'visible_subject_study_columns_id, ' + - 'visible_subject_columns_id, ' + - 'last_contact_attempt,' - 'visits,' - 'type) ' + - "SELECT " + - "1, " + - "max(web_studycolumns.id), " + - "max(web_subjectcolumns.id), " + - "false, " + - "false, " + - "'NO_VISIT' FROM web_studycolumns, web_subjectcolumns;"), ] + if is_sqlite_db(): + operations.append(migrations.RunSQL('INSERT INTO web_studysubjectlist (' + + 'study_id, ' + + 'visible_subject_study_columns_id, ' + + 'visible_subject_columns_id, ' + + 'last_contact_attempt,' + 'visits,' + 'type) ' + + "SELECT " + + "1, " + + "max(web_studycolumns.id), " + + "max(web_subjectcolumns.id), " + + "0, " + + "0, " + + "'NO_VISIT' FROM web_studycolumns, web_subjectcolumns;")) + else: + operations.append(migrations.RunSQL('INSERT INTO web_studysubjectlist (' + + 'study_id, ' + + 'visible_subject_study_columns_id, ' + + 'visible_subject_columns_id, ' + + 'last_contact_attempt,' + 'visits,' + 'type) ' + + "SELECT " + + "1, " + + "max(web_studycolumns.id), " + + "max(web_subjectcolumns.id), " + + "false, " + + "false, " + + "'NO_VISIT' FROM web_studycolumns, web_subjectcolumns;")) diff --git a/smash/web/migrations/0085_auto_20171205_1650.py b/smash/web/migrations/0085_auto_20171205_1650.py index a579ab205678ed0b02b8a101afa6b064202d09ee..d0d6190d59ba30c0d3118363c68d13cb55775baa 100644 --- a/smash/web/migrations/0085_auto_20171205_1650.py +++ b/smash/web/migrations/0085_auto_20171205_1650.py @@ -3,6 +3,7 @@ from django.db import migrations, models +from ..migration_functions import is_sqlite_db # noinspection PyUnusedLocal # noinspection PyPep8Naming @@ -70,8 +71,10 @@ class Migration(migrations.Migration): name='type', field=models.CharField(blank=True, choices=[(b'GENERIC', b'Generic'), (b'NO_VISIT', b'Subjects without visit'), (b'REQUIRE_CONTACT', b'Subjects required contact')], max_length=50, null=True, verbose_name=b'Type of list'), ), - migrations.RunPython(create_default_columns_for_VISIT_LIST_EXCEEDED_TIME), - migrations.RunSQL('INSERT INTO web_studyvisitlist (' + + migrations.RunPython(create_default_columns_for_VISIT_LIST_EXCEEDED_TIME) + ] + if is_sqlite_db(): + operations.append(migrations.RunSQL('INSERT INTO web_studyvisitlist (' + 'study_id, ' + 'visible_visit_columns_id, ' + 'visible_subject_columns_id, ' + @@ -85,8 +88,26 @@ class Migration(migrations.Migration): "max(web_visitcolumns.id), " + "max(web_subjectcolumns.id), " + "max(web_studycolumns.id), " + - "TRUE, " + - "TRUE, " + - "TRUE, " + - "'EXCEEDED_TIME' FROM web_visitcolumns, web_studycolumns, web_subjectcolumns;"), - ] + "0, " + + "0, " + + "0, " + + "'EXCEEDED_TIME' FROM web_visitcolumns, web_studycolumns, web_subjectcolumns;")) + else: + operations.append(migrations.RunSQL('INSERT INTO web_studyvisitlist (' + + 'study_id, ' + + 'visible_visit_columns_id, ' + + 'visible_subject_columns_id, ' + + 'visible_study_subject_columns_id, ' + + 'visible_appointment_types_done,' + 'visible_appointment_types_in_progress,' + 'visible_appointment_types_missing,' + 'type) ' + + "SELECT " + + "1, " + + "max(web_visitcolumns.id), " + + "max(web_subjectcolumns.id), " + + "max(web_studycolumns.id), " + + "TRUE, " + + "TRUE, " + + "TRUE, " + + "'EXCEEDED_TIME' FROM web_visitcolumns, web_studycolumns, web_subjectcolumns;")) diff --git a/smash/web/migrations/0086_unfinished_visit_list.py b/smash/web/migrations/0086_unfinished_visit_list.py index 30a4f25b4c72eb282858df251a24d3bea91f8925..460b1d99c285e1762599e57790165d6aad8ae982 100644 --- a/smash/web/migrations/0086_unfinished_visit_list.py +++ b/smash/web/migrations/0086_unfinished_visit_list.py @@ -3,6 +3,7 @@ from django.db import migrations, models +from ..migration_functions import is_sqlite_db # noinspection PyUnusedLocal # noinspection PyPep8Naming @@ -65,8 +66,11 @@ class Migration(migrations.Migration): ] operations = [ - migrations.RunPython(create_default_columns_for_VISIT_LIST_EXCEEDED_TIME), - migrations.RunSQL('INSERT INTO web_studyvisitlist (' + + migrations.RunPython(create_default_columns_for_VISIT_LIST_EXCEEDED_TIME) + ] + + if is_sqlite_db(): + operations.append(migrations.RunSQL('INSERT INTO web_studyvisitlist (' + 'study_id, ' + 'visible_visit_columns_id, ' + 'visible_subject_columns_id, ' + @@ -80,8 +84,26 @@ class Migration(migrations.Migration): "max(web_visitcolumns.id), " + "max(web_subjectcolumns.id), " + "max(web_studycolumns.id), " + - "TRUE, " + - "TRUE, " + - "TRUE, " + - "'UNFINISHED' FROM web_visitcolumns, web_studycolumns, web_subjectcolumns;"), - ] + "1, " + + "1, " + + "1, " + + "'UNFINISHED' FROM web_visitcolumns, web_studycolumns, web_subjectcolumns;")) + else: + operations.append(migrations.RunSQL('INSERT INTO web_studyvisitlist (' + + 'study_id, ' + + 'visible_visit_columns_id, ' + + 'visible_subject_columns_id, ' + + 'visible_study_subject_columns_id, ' + + 'visible_appointment_types_done,' + 'visible_appointment_types_in_progress,' + 'visible_appointment_types_missing,' + 'type) ' + + "SELECT " + + "1, " + + "max(web_visitcolumns.id), " + + "max(web_subjectcolumns.id), " + + "max(web_studycolumns.id), " + + "TRUE, " + + "TRUE, " + + "TRUE, " + + "'UNFINISHED' FROM web_visitcolumns, web_studycolumns, web_subjectcolumns;")) diff --git a/smash/web/migrations/0087_approaching_visit_wihout_appointment_list.py b/smash/web/migrations/0087_approaching_visit_wihout_appointment_list.py index 5ea8c79fcf489be83b49a5728111f31f8d0e519b..55d62fd48b6c93c8c6e2cc6b61d58a0b23481d6f 100644 --- a/smash/web/migrations/0087_approaching_visit_wihout_appointment_list.py +++ b/smash/web/migrations/0087_approaching_visit_wihout_appointment_list.py @@ -4,6 +4,8 @@ from django.db import migrations +from ..migration_functions import is_sqlite_db + # noinspection PyUnusedLocal # noinspection PyPep8Naming @@ -66,8 +68,11 @@ class Migration(migrations.Migration): ] operations = [ - migrations.RunPython(create_default_columns_for_VISIT_LIST_APPROACHING_WITHOUT_APPOINTMENTS), - migrations.RunSQL('INSERT INTO web_studyvisitlist (' + + migrations.RunPython(create_default_columns_for_VISIT_LIST_APPROACHING_WITHOUT_APPOINTMENTS) + ] + + if is_sqlite_db(): + operations.append(migrations.RunSQL('INSERT INTO web_studyvisitlist (' + 'study_id, ' + 'visible_visit_columns_id, ' + 'visible_subject_columns_id, ' + @@ -81,8 +86,26 @@ class Migration(migrations.Migration): "max(web_visitcolumns.id), " + "max(web_subjectcolumns.id), " + "max(web_studycolumns.id), " + - "FALSE, " + - "FALSE, " + - "FALSE, " + - "'APPROACHING_WITHOUT_APPOINTMENTS' FROM web_visitcolumns, web_studycolumns, web_subjectcolumns;"), - ] + "0, " + + "0, " + + "0, " + + "'APPROACHING_WITHOUT_APPOINTMENTS' FROM web_visitcolumns, web_studycolumns, web_subjectcolumns;")) + else: + operations.append(migrations.RunSQL('INSERT INTO web_studyvisitlist (' + + 'study_id, ' + + 'visible_visit_columns_id, ' + + 'visible_subject_columns_id, ' + + 'visible_study_subject_columns_id, ' + + 'visible_appointment_types_done,' + 'visible_appointment_types_in_progress,' + 'visible_appointment_types_missing,' + 'type) ' + + "SELECT " + + "1, " + + "max(web_visitcolumns.id), " + + "max(web_subjectcolumns.id), " + + "max(web_studycolumns.id), " + + "FALSE, " + + "FALSE, " + + "FALSE, " + + "'APPROACHING_WITHOUT_APPOINTMENTS' FROM web_visitcolumns, web_studycolumns, web_subjectcolumns;")) diff --git a/smash/web/migrations/0104_contact_required_list_update.py b/smash/web/migrations/0104_contact_required_list_update.py index dbfb503e7e32a850b6e4cb2736289d2713b103c3..29da7956f7ff3aed5fe6f6fa0da08d4845d03fc2 100644 --- a/smash/web/migrations/0104_contact_required_list_update.py +++ b/smash/web/migrations/0104_contact_required_list_update.py @@ -2,7 +2,9 @@ # Generated by Django 1.10.7 on 2018-02-14 10:26 -from django.db import migrations, models +from django.db import migrations + +from ..migration_functions import is_sqlite_db class Migration(migrations.Migration): @@ -10,7 +12,13 @@ class Migration(migrations.Migration): ('web', '0103_auto_20180214_1026'), ] - operations = [ - migrations.RunSQL( - 'UPDATE web_studysubjectlist SET last_contact_attempt = TRUE WHERE type=\'REQUIRE_CONTACT\';'), - ] + if is_sqlite_db(): + operations = [ + migrations.RunSQL( + 'UPDATE web_studysubjectlist SET last_contact_attempt = 1 WHERE type=\'REQUIRE_CONTACT\';'), + ] + else: + operations = [ + migrations.RunSQL( + 'UPDATE web_studysubjectlist SET last_contact_attempt = TRUE WHERE type=\'REQUIRE_CONTACT\';'), + ] diff --git a/smash/web/migrations/0105_unfinished_appointments_list_update.py b/smash/web/migrations/0105_unfinished_appointments_list_update.py index cfef1c66bec909c70ffbfbd7345a8d284dd1cc35..c3e926cc00a0d07dcad0732f0c274d5f192dc34c 100644 --- a/smash/web/migrations/0105_unfinished_appointments_list_update.py +++ b/smash/web/migrations/0105_unfinished_appointments_list_update.py @@ -2,7 +2,9 @@ # Generated by Django 1.10.7 on 2018-02-14 10:26 -from django.db import migrations, models +from django.db import migrations + +from ..migration_functions import is_sqlite_db class Migration(migrations.Migration): @@ -10,8 +12,15 @@ class Migration(migrations.Migration): ('web', '0104_contact_required_list_update'), ] - operations = [ - migrations.RunSQL( - 'UPDATE web_studycolumns SET nd_number=TRUE, type=TRUE WHERE id IN ' + - '(SELECT visible_study_subject_columns_id FROM web_appointmentlist WHERE type = \'UNFINISHED\');'), - ] + if is_sqlite_db(): + operations = [ + migrations.RunSQL( + 'UPDATE web_studycolumns SET nd_number=1, type=1 WHERE id IN ' + + '(SELECT visible_study_subject_columns_id FROM web_appointmentlist WHERE type = \'UNFINISHED\');'), + ] + else: + operations = [ + migrations.RunSQL( + 'UPDATE web_studycolumns SET nd_number=TRUE, type=TRUE WHERE id IN ' + + '(SELECT visible_study_subject_columns_id FROM web_appointmentlist WHERE type = \'UNFINISHED\');'), + ] diff --git a/smash/web/migrations/0106_approaching_post_mail_list_update.py b/smash/web/migrations/0106_approaching_post_mail_list_update.py index 80e966cd89ec449da9546b151d54ff98059e2aa6..93095d3e564a5525613ce5cced349e2cb46474c1 100644 --- a/smash/web/migrations/0106_approaching_post_mail_list_update.py +++ b/smash/web/migrations/0106_approaching_post_mail_list_update.py @@ -4,6 +4,8 @@ from django.db import migrations, models +from ..migration_functions import is_sqlite_db + def create_default_columns_for_VISIT_LIST_APPROACHING_FOR_MAIL_CONTACT(apps, schema_editor): # We can't import the Study model directly as it may be a newer # version than this migration expects. We use the historical version. @@ -63,8 +65,11 @@ class Migration(migrations.Migration): ] operations = [ - migrations.RunPython(create_default_columns_for_VISIT_LIST_APPROACHING_FOR_MAIL_CONTACT), - migrations.RunSQL('INSERT INTO web_studyvisitlist (' + + migrations.RunPython(create_default_columns_for_VISIT_LIST_APPROACHING_FOR_MAIL_CONTACT) + ] + + if is_sqlite_db(): + operations.append(migrations.RunSQL('INSERT INTO web_studyvisitlist (' + 'study_id, ' + 'visible_visit_columns_id, ' + 'visible_subject_columns_id, ' + @@ -78,8 +83,26 @@ class Migration(migrations.Migration): "max(web_visitcolumns.id), " + "max(web_subjectcolumns.id), " + "max(web_studycolumns.id), " + - "FALSE, " + - "FALSE, " + - "FALSE, " + - "'APPROACHING_FOR_MAIL_CONTACT' FROM web_visitcolumns, web_studycolumns, web_subjectcolumns;"), - ] + "0, " + + "0, " + + "0, " + + "'APPROACHING_FOR_MAIL_CONTACT' FROM web_visitcolumns, web_studycolumns, web_subjectcolumns;")) + else: + operations.append(migrations.RunSQL('INSERT INTO web_studyvisitlist (' + + 'study_id, ' + + 'visible_visit_columns_id, ' + + 'visible_subject_columns_id, ' + + 'visible_study_subject_columns_id, ' + + 'visible_appointment_types_done,' + 'visible_appointment_types_in_progress,' + 'visible_appointment_types_missing,' + 'type) ' + + "SELECT " + + "1, " + + "max(web_visitcolumns.id), " + + "max(web_subjectcolumns.id), " + + "max(web_studycolumns.id), " + + "FALSE, " + + "FALSE, " + + "FALSE, " + + "'APPROACHING_FOR_MAIL_CONTACT' FROM web_visitcolumns, web_studycolumns, web_subjectcolumns;")) diff --git a/smash/web/migrations/0107_exceeded_visit_time_list_update.py b/smash/web/migrations/0107_exceeded_visit_time_list_update.py index 934b455ffa411359a9279d0f909ce2999ebbaf3d..c9f7672026fbc65f4964bd05647176849aaa18ff 100644 --- a/smash/web/migrations/0107_exceeded_visit_time_list_update.py +++ b/smash/web/migrations/0107_exceeded_visit_time_list_update.py @@ -2,7 +2,9 @@ # Generated by Django 1.10.7 on 2018-02-14 10:26 -from django.db import migrations, models +from django.db import migrations + +from ..migration_functions import is_sqlite_db class Migration(migrations.Migration): @@ -10,8 +12,15 @@ class Migration(migrations.Migration): ('web', '0106_approaching_post_mail_list_update'), ] - operations = [ - migrations.RunSQL( - 'UPDATE web_studycolumns SET nd_number=TRUE WHERE id IN ' + - '(SELECT visible_study_subject_columns_id FROM web_studyvisitlist WHERE type = \'EXCEEDED_TIME\');'), - ] + if is_sqlite_db(): + operations = [ + migrations.RunSQL( + 'UPDATE web_studycolumns SET nd_number=1 WHERE id IN ' + + '(SELECT visible_study_subject_columns_id FROM web_studyvisitlist WHERE type = \'EXCEEDED_TIME\');'), + ] + else: + operations = [ + migrations.RunSQL( + 'UPDATE web_studycolumns SET nd_number=TRUE WHERE id IN ' + + '(SELECT visible_study_subject_columns_id FROM web_studyvisitlist WHERE type = \'EXCEEDED_TIME\');'), + ] diff --git a/smash/web/migrations/0108_unfinished_visit_list_update.py b/smash/web/migrations/0108_unfinished_visit_list_update.py index b357d3e21f91cb918eaa8f1869c5b3eb81fa8963..6301b9d641b3ec0a5b8a185934ca5cc9c858adf4 100644 --- a/smash/web/migrations/0108_unfinished_visit_list_update.py +++ b/smash/web/migrations/0108_unfinished_visit_list_update.py @@ -2,7 +2,9 @@ # Generated by Django 1.10.7 on 2018-02-14 10:26 -from django.db import migrations, models +from django.db import migrations + +from ..migration_functions import is_sqlite_db class Migration(migrations.Migration): @@ -10,8 +12,15 @@ class Migration(migrations.Migration): ('web', '0107_exceeded_visit_time_list_update'), ] - operations = [ - migrations.RunSQL( - 'UPDATE web_studycolumns SET nd_number=TRUE where id IN ' + - '(SELECT visible_study_subject_columns_id FROM web_studyvisitlist WHERE type = \'UNFINISHED\');'), - ] + if is_sqlite_db(): + operations = [ + migrations.RunSQL( + 'UPDATE web_studycolumns SET nd_number=1 where id IN ' + + '(SELECT visible_study_subject_columns_id FROM web_studyvisitlist WHERE type = \'UNFINISHED\');'), + ] + else: + operations = [ + migrations.RunSQL( + 'UPDATE web_studycolumns SET nd_number=TRUE where id IN ' + + '(SELECT visible_study_subject_columns_id FROM web_studyvisitlist WHERE type = \'UNFINISHED\');'), + ] diff --git a/smash/web/migrations/0109_missing_appointment_list_update.py b/smash/web/migrations/0109_missing_appointment_list_update.py index bbfc2d9dda4daa5d918e6d4a9404615019ac07f1..fad72c2cbff6990ae0217da624856d9844c55d70 100644 --- a/smash/web/migrations/0109_missing_appointment_list_update.py +++ b/smash/web/migrations/0109_missing_appointment_list_update.py @@ -2,7 +2,10 @@ # Generated by Django 1.10.7 on 2018-02-14 10:26 -from django.db import migrations, models +from django.db import migrations + +from ..migration_functions import is_sqlite_db + def create_default_columns_for_VISIT_LIST_MISSING_APPOINTMENT(apps, schema_editor): # We can't import the Study model directly as it may be a newer @@ -64,22 +67,43 @@ class Migration(migrations.Migration): operations = [ migrations.RunPython(create_default_columns_for_VISIT_LIST_MISSING_APPOINTMENT), - migrations.RunSQL('INSERT INTO web_studyvisitlist (' + - 'study_id, ' + - 'visible_visit_columns_id, ' + - 'visible_subject_columns_id, ' + - 'visible_study_subject_columns_id, ' + - 'visible_appointment_types_done,' - 'visible_appointment_types_in_progress,' - 'visible_appointment_types_missing,' - 'type) ' + - "SELECT " + - "1, " + - "max(web_visitcolumns.id), " + - "max(web_subjectcolumns.id), " + - "max(web_studycolumns.id), " + - "TRUE, " + - "TRUE, " + - "TRUE, " + - "'MISSING_APPOINTMENTS' FROM web_visitcolumns, web_studycolumns, web_subjectcolumns;"), ] + + if is_sqlite_db(): + operations.append(migrations.RunSQL('INSERT INTO web_studyvisitlist (' + + 'study_id, ' + + 'visible_visit_columns_id, ' + + 'visible_subject_columns_id, ' + + 'visible_study_subject_columns_id, ' + + 'visible_appointment_types_done,' + 'visible_appointment_types_in_progress,' + 'visible_appointment_types_missing,' + 'type) ' + + "SELECT " + + "1, " + + "max(web_visitcolumns.id), " + + "max(web_subjectcolumns.id), " + + "max(web_studycolumns.id), " + + "1, " + + "1, " + + "1, " + + "'MISSING_APPOINTMENTS' FROM web_visitcolumns, web_studycolumns, web_subjectcolumns;")) + else: + operations.append(migrations.RunSQL('INSERT INTO web_studyvisitlist (' + + 'study_id, ' + + 'visible_visit_columns_id, ' + + 'visible_subject_columns_id, ' + + 'visible_study_subject_columns_id, ' + + 'visible_appointment_types_done,' + 'visible_appointment_types_in_progress,' + 'visible_appointment_types_missing,' + 'type) ' + + "SELECT " + + "1, " + + "max(web_visitcolumns.id), " + + "max(web_subjectcolumns.id), " + + "max(web_studycolumns.id), " + + "TRUE, " + + "TRUE, " + + "TRUE, " + + "'MISSING_APPOINTMENTS' FROM web_visitcolumns, web_studycolumns, web_subjectcolumns;")) diff --git a/smash/web/migrations/0140_auto_20190528_0953.py b/smash/web/migrations/0140_auto_20190528_0953.py index e573406c0b806860c80ae341b3745fe8beb7222a..2c7c1a1927e8b946a1e347dfe557ae6ce40ebfa6 100644 --- a/smash/web/migrations/0140_auto_20190528_0953.py +++ b/smash/web/migrations/0140_auto_20190528_0953.py @@ -2,12 +2,13 @@ # Generated by Django 1.11.5 on 2019-05-28 09:53 -from django.db import migrations, models import django.db.models.deletion +from django.db import migrations, models +from ..migration_functions import is_sqlite_db -class Migration(migrations.Migration): +class Migration(migrations.Migration): dependencies = [ ('web', '0139_auto_20190321_1400'), ] @@ -23,17 +24,27 @@ class Migration(migrations.Migration): ('mpower_id', models.BooleanField(default=True, verbose_name=b'MPower ID')), ('languages', models.BooleanField(default=True, verbose_name=b'Languages')), ], - ), - migrations.RunSQL('insert into web_studyredcapcolumns (sex,' + - 'date_born,' + - 'dead,' + - 'mpower_id,' + - 'languages' + - ') values(true, true, true, true, true)'), - migrations.AddField( - model_name='study', - name='redcap_columns', - field=models.OneToOneField(default=True, on_delete=django.db.models.deletion.CASCADE, to='web.StudyRedCapColumns'), - preserve_default=False, - ), - ] + )] + if is_sqlite_db(): + operations.append( + migrations.RunSQL('insert into web_studyredcapcolumns (sex,' + + 'date_born,' + + 'dead,' + + 'mpower_id,' + + 'languages' + + ') values(1, 1, 1, 1, 1)')) + else: + operations.append( + migrations.RunSQL('insert into web_studyredcapcolumns (sex,' + + 'date_born,' + + 'dead,' + + 'mpower_id,' + + 'languages' + + ') values(true, true, true, true, true)')) + operations.append(migrations.AddField( + model_name='study', + name='redcap_columns', + field=models.OneToOneField(default=True, on_delete=django.db.models.deletion.CASCADE, + to='web.StudyRedCapColumns'), + preserve_default=False, + ))