Adds cascade to study relationship so data loader doesn't freak out.

This commit is contained in:
Aaron Louie 2020-05-22 22:04:11 -04:00
parent 00955723b0
commit 20bf01a888
3 changed files with 42 additions and 2 deletions

View File

@ -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.

View File

@ -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):

View File

@ -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 ###