Skip to content

Instantly share code, notes, and snippets.

@zindel
Created March 21, 2016 06:46
Show Gist options
  • Save zindel/3666c0c84373df313bcb to your computer and use it in GitHub Desktop.
Save zindel/3666c0c84373df313bcb to your computer and use it in GitHub Desktop.

Data Migration from RexStudy 4.14 to 4.15

Table of Contents

We're going to test the SQL migration scripts. For this purpose we restored from the RexStudy 4.14 sql dump 2 databases study_test_pre_4.15 and study_test_migrated_4.15. Then we deployed the current study model to the latter. The dump was previously updated with all required test data. Let's make a connection to both databases to compare results:

>>> from rex.core import Rex
>>> from webob import Request
>>> pre = Rex('rex.db', db='pgsql:study_test_pre_4.15',
...                     access={'rex.db': 'anybody'})
>>> migrated = Rex('rex.db', db='pgsql:study_test_migrated_4.15',
...                      access={'rex.db': 'anybody'})
>>> def run(app, query):
...   with app:
...     print Request.blank(query.strip()).get_response(app)

The pre database has 2 studies:

>>> run(pre, '/study{id(), is_configured}') # doctest: +ELLIPSIS
200 OK
...
 | study                   |
 +---------+---------------+
 | id()    | is_configured |
-+---------+---------------+-
 | complex | true          |
 | onereq  | true          |
...

With certain configuration in time_period, requirement_list and participant_group tables:

>>> run(pre, """
...   /time_period{id(), study := study.id()}
... """) # doctest: +ELLIPSIS
200 OK
...
 | time_period              |
 +----------------+---------+
 | id()           | study   |
-+----------------+---------+-
 | complex.tp1    | complex |
 | complex.tp2    | complex |
 | onereq.anytime | onereq  |
...

>>> run(pre, """
...   /participant_group{id(), study := study.id()}
... """) # doctest: +ELLIPSIS
200 OK
...
 | participant_group                 |
 +-------------------------+---------+
 | id()                    | study   |
-+-------------------------+---------+-
 | complex.pg1             | complex |
 | complex.pg2             | complex |
 | onereq.all-participants | onereq  |
...

>>> run(pre, """
...   /requirement_list{
...     id(),
...     study := study.id(),
...     time_period.id() :as time_period,
...     participant_group.id() :as participant_group
...   }
... """) # doctest: +ELLIPSIS
200 OK
...
 | requirement_list                                               |
 +-----------+---------+----------------+-------------------------+
 | id()      | study   | time_period    | participant_group       |
-+-----------+---------+----------------+-------------------------+-
 | complex.4 | complex | complex.tp1    | complex.pg1             |
 | complex.5 | complex | complex.tp1    | complex.pg2             |
 | complex.6 | complex | complex.tp2    | complex.pg1             |
 | complex.7 | complex | complex.tp2    | complex.pg2             |
 | onereq.1  | onereq  | onereq.anytime | onereq.all-participants |
...

The migrated database has one study_version per each study and the study.is_configured field is a part of study_version now with value properly transferred:

>>> run(migrated, """
...   /study_version{id(), study.id(), version, is_configured}
... """) # doctest: +ELLIPSIS
200 OK
...
 | study_version                                 |
 +-----------+---------+---------+---------------+
 | id()      | id()    | version | is_configured |
-+-----------+---------+---------+---------------+-
 | complex.1 | complex |       1 | true          |
 | onereq.1  | onereq  |       1 | true          |
...

Also the time_period, participant_group and requirement_list tables are branches of study_version:

>>> run(migrated, """
...   /time_period{id(), study_version := study_version.id()}
... """) # doctest: +ELLIPSIS
200 OK
...
 | time_period                      |
 +------------------+---------------+
 | id()             | study_version |
-+------------------+---------------+-
 | complex.1.tp1    | complex.1     |
 | complex.1.tp2    | complex.1     |
 | onereq.1.anytime | onereq.1      |
...

>>> run(migrated, """
...   /participant_group{id(), study_version := study_version.id()}
... """) # doctest: +ELLIPSIS
200 OK
...
 | participant_group                         |
 +---------------------------+---------------+
 | id()                      | study_version |
-+---------------------------+---------------+-
 | complex.1.pg1             | complex.1     |
 | complex.1.pg2             | complex.1     |
 | onereq.1.all-participants | onereq.1      |
...

>>> run(migrated, """
...   /requirement_list{id(), study_version := study_version.id()}
... """) # doctest: +ELLIPSIS
200 OK
...
 | requirement_list                                                          |
 +-----------------------------------------------------------+---------------+
 | id()                                                      | study_version |
-+-----------------------------------------------------------+---------------+-
 | (complex.1).(complex.1.pg1).(complex.1.tp1)               | complex.1     |
 | (complex.1).(complex.1.pg1).(complex.1.tp2)               | complex.1     |
 | (complex.1).(complex.1.pg2).(complex.1.tp1)               | complex.1     |
 | (complex.1).(complex.1.pg2).(complex.1.tp2)               | complex.1     |
 | (onereq.1).(onereq.1.all-participants).(onereq.1.anytime) | onereq.1      |
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment