New task_log model with schema, and migration
This commit is contained in:
parent
e0d1f63c08
commit
b0c479420d
|
@ -0,0 +1,23 @@
|
|||
from crc import db, ma
|
||||
from crc.models.study import StudyModel
|
||||
from crc.models.workflow import WorkflowModel
|
||||
from sqlalchemy import func
|
||||
|
||||
|
||||
class TaskLogModel(db.Model):
|
||||
__tablename__ = 'task_log'
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
level = db.Column(db.String)
|
||||
code = db.Column(db.String)
|
||||
message = db.Column(db.String)
|
||||
study_id = db.Column(db.Integer, db.ForeignKey(StudyModel.id), nullable=False)
|
||||
workflow_id = db.Column(db.Integer, db.ForeignKey(WorkflowModel.id), nullable=False)
|
||||
task = db.Column(db.String)
|
||||
timestamp = db.Column(db.DateTime(timezone=True), default=func.now())
|
||||
|
||||
|
||||
class TaskLogModelSchema(ma.Schema):
|
||||
|
||||
class Meta:
|
||||
model = TaskLogModel
|
||||
fields = ["id", "level", "code", "message", "study_id", "workflow_id", "timestamp"]
|
|
@ -0,0 +1,36 @@
|
|||
"""add log table
|
||||
|
||||
Revision ID: a4f87f90cc64
|
||||
Revises: ba6df7e560a1
|
||||
Create Date: 2021-10-27 10:54:40.233325
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'a4f87f90cc64'
|
||||
down_revision = 'ba6df7e560a1'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
op.create_table('task_log',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('level', sa.String(), nullable=True),
|
||||
sa.Column('code', sa.String(), nullable=True),
|
||||
sa.Column('message', sa.String(), nullable=True),
|
||||
sa.Column('study_id', sa.Integer(), nullable=False),
|
||||
sa.Column('workflow_id', sa.Integer(), nullable=False),
|
||||
sa.Column('task', sa.String(), nullable=True),
|
||||
sa.Column('timestamp', sa.DateTime(timezone=True), nullable=True),
|
||||
sa.ForeignKeyConstraint(['study_id'], ['study.id'], ),
|
||||
sa.ForeignKeyConstraint(['workflow_id'], ['workflow.id'], ),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.drop_table('task_log')
|
Loading…
Reference in New Issue