Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
scheduling-system
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SMASCH
scheduling-system
Commits
4e03acd0
Commit
4e03acd0
authored
3 years ago
by
Piotr Gawron
Browse files
Options
Downloads
Plain Diff
Merge branch 'migration-issue' into 'master'
migration script issue See merge request
!401
parents
6a9f984f
fbd6eea1
No related branches found
Branches containing commit
Tags
v1.1.0-alpha.0
Tags containing commit
1 merge request
!401
migration script issue
Pipeline
#49065
passed
3 years ago
Changes
1
Pipelines
3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
smash/web/migrations/0194_migrate_subject_type_to_new_structure.py
+13
-56
13 additions, 56 deletions
.../migrations/0194_migrate_subject_type_to_new_structure.py
with
13 additions
and
56 deletions
smash/web/migrations/0194_migrate_subject_type_to_new_structure.py
+
13
−
56
View file @
4e03acd0
...
...
@@ -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
'"
),
]
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment