From 2e94ab1584e9d7d092a0eaf2bde35fd17bb50e0c Mon Sep 17 00:00:00 2001 From: Aaron Louie Date: Fri, 22 May 2020 14:55:55 -0400 Subject: [PATCH 1/3] Only runs upgrade if env variable says to. --- Dockerfile | 1 - docker_run.sh | 12 +++++------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index fae1657f..fc86ddb0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,7 +17,6 @@ RUN pip install pipenv && \ COPY . /app/ ENV FLASK_APP=/app/crc/__init__.py -CMD ["pipenv", "run", "flask", "db", "upgrade"] CMD ["pipenv", "run", "python", "/app/run.py"] # expose ports diff --git a/docker_run.sh b/docker_run.sh index 95792392..1ff01c11 100755 --- a/docker_run.sh +++ b/docker_run.sh @@ -3,17 +3,15 @@ # run migrations export FLASK_APP=./crc/__init__.py -for entry in ./instance/* ; do - echo "$entry" - cat $entry -done - if [ "$DOWNGRADE_DB" = "true" ]; then - echo 'Downgrading...' + echo 'Downgrading database...' pipenv run flask db downgrade fi -pipenv run flask db upgrade +if [ "$UPGRADE_DB" = "true" ]; then + echo 'Upgrading database...' + pipenv run flask db upgrade +fi if [ "$RESET_DB" = "true" ]; then echo 'Resetting database...' From 20bf01a88800b6e36a64a4c12a9396e9ca4397ba Mon Sep 17 00:00:00 2001 From: Aaron Louie Date: Fri, 22 May 2020 22:04:11 -0400 Subject: [PATCH 2/3] Adds cascade to study relationship so data loader doesn't freak out. --- crc/models/approval.py | 2 +- example_data.py | 3 ++- migrations/versions/55c6cd407d89_.py | 39 ++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 migrations/versions/55c6cd407d89_.py diff --git a/crc/models/approval.py b/crc/models/approval.py index 4860bf59..7d513a7f 100644 --- a/crc/models/approval.py +++ b/crc/models/approval.py @@ -18,7 +18,7 @@ class ApprovalModel(db.Model): __tablename__ = 'approval' id = db.Column(db.Integer, primary_key=True) study_id = db.Column(db.Integer, db.ForeignKey(StudyModel.id), nullable=False) - study = db.relationship(StudyModel, backref='approval') + study = db.relationship(StudyModel, backref='approval', cascade='all,delete') workflow_id = db.Column(db.Integer, db.ForeignKey(WorkflowModel.id), nullable=False) workflow_version = db.Column(db.String) approver_uid = db.Column(db.String) # Not linked to user model, as they may not have logged in yet. diff --git a/example_data.py b/example_data.py index 22e6f95b..7f53b13c 100644 --- a/example_data.py +++ b/example_data.py @@ -14,7 +14,8 @@ class ExampleDataLoader: session.flush() # Clear out any transactions before deleting it all to avoid spurious errors. for table in reversed(db.metadata.sorted_tables): session.execute(table.delete()) - session.flush() + session.commit() + session.flush() def load_all(self): diff --git a/migrations/versions/55c6cd407d89_.py b/migrations/versions/55c6cd407d89_.py new file mode 100644 index 00000000..e5dd02ee --- /dev/null +++ b/migrations/versions/55c6cd407d89_.py @@ -0,0 +1,39 @@ +"""empty message + +Revision ID: 55c6cd407d89 +Revises: cc4bccc5e5a8 +Create Date: 2020-05-22 22:02:46.650170 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '55c6cd407d89' +down_revision = 'cc4bccc5e5a8' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.create_table('approval', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('study_id', sa.Integer(), nullable=False), + sa.Column('workflow_id', sa.Integer(), nullable=False), + sa.Column('workflow_version', sa.String(), nullable=True), + sa.Column('approver_uid', sa.String(), nullable=True), + sa.Column('status', sa.String(), nullable=True), + sa.Column('message', sa.String(), nullable=True), + sa.ForeignKeyConstraint(['study_id'], ['study.id'], ), + sa.ForeignKeyConstraint(['workflow_id'], ['workflow.id'], ), + sa.PrimaryKeyConstraint('id') + ) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_table('approval') + # ### end Alembic commands ### From 6c14248ef9fa8e0ecb86dff82d379de223f7f7b5 Mon Sep 17 00:00:00 2001 From: Aaron Louie Date: Sat, 23 May 2020 14:49:02 -0400 Subject: [PATCH 3/3] Adds 'v1.0/' to login route --- crc/api/user.py | 2 +- tests/test_authentication.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crc/api/user.py b/crc/api/user.py index 6924eb27..3e423fc6 100644 --- a/crc/api/user.py +++ b/crc/api/user.py @@ -32,7 +32,7 @@ def verify_token(token): def get_current_user(): return UserModelSchema().dump(g.user) -@app.route('/login') +@app.route('/v1.0/login') def sso_login(): # This what I see coming back: # X-Remote-Cn: Daniel Harold Funk (dhf8r) diff --git a/tests/test_authentication.py b/tests/test_authentication.py index 2767797a..7601a220 100644 --- a/tests/test_authentication.py +++ b/tests/test_authentication.py @@ -44,7 +44,7 @@ class TestAuthentication(BaseTest): self.assertIsNone(user) redirect_url = 'http://worlds.best.website/admin' headers = dict(Uid=new_uid) - rv = self.app.get('login', follow_redirects=False, headers=headers) + rv = self.app.get('v1.0/login', follow_redirects=False, headers=headers) self.assert_success(rv) user = db.session.query(UserModel).filter(UserModel.uid == new_uid).first() self.assertIsNotNone(user)