Skip to content
Snippets Groups Projects
44d5bbbf2615_workspaces_init.py 3.33 KiB
"""workspaces-init

Revision ID: 44d5bbbf2615
Revises: 
Create Date: 2020-09-02 11:25:01.571392

"""
from alembic import op
import sqlalchemy as sa

revision = '44d5bbbf2615'
down_revision = None
branch_labels = None
depends_on = None


def upgrade():
    op.create_table('workflows',
                    sa.Column('workflow_name', sa.String, primary_key=True, comment='the human-readable name for the workflow.'),
                    comment='A listing of the available workflows in the system.')

    op.create_table('workflow_templates',
                    sa.Column('filename', sa.String, primary_key=True, comment='the filename of the template'),
                    sa.Column('content', sa.LargeBinary, nullable=False, comment='the content of the template'),
                    sa.Column('workflow_name', sa.String, sa.ForeignKey('workflows.workflow_name'), primary_key=True,
                              comment='the name of the workflow this template belongs to'),
                    comment='Templates associated with workflows')

    op.create_table('workflow_requests',
                    sa.Column('workflow_request_id', sa.Integer, primary_key=True, autoincrement=True,
                              comment='the unique id of the request. auto-generated'),
                    sa.Column('workflow_name', sa.String, sa.ForeignKey('workflows.workflow_name')),
                    sa.Column('argument', sa.JSON, comment='the argument(s) used for the workflow in this request.'),
                    sa.Column('state', sa.String, comment='the current state of the workflow in this request.'),
                    sa.Column('execution_id', sa.Integer,
                              comment='the id of the parent execution awaiting the workflow'),
                    comment='A listing of requests for workflow execution.')

    op.create_table('workflow_request_files',
                    sa.Column('workflow_request_id', sa.Integer, sa.ForeignKey('workflow_requests.workflow_request_id'),
                              comment='the id of the workflow request.'),
                    sa.Column('filename', sa.String, comment='the name of this file', nullable=False),
                    sa.Column('content', sa.LargeBinary, comment='the contents of the file', nullable=False),
                    comment='A man-to-many mapping table tracking which files were used for workflow requests.')

    op.create_unique_constraint('workflow_request_filenames_uniq', 'workflow_request_files',
                                ['workflow_request_id', 'filename'])

    # populate with some initial data
    op.execute("INSERT INTO workflows (workflow_name) VALUES ('null')")
    op.execute("INSERT INTO workflow_templates (workflow_name, filename, content) "
               "VALUES ('null', 'null.condor', E'executable = null.sh\narguments = \"{{arguments}}\""
               "\nerror = null.err\nlog = condor.log\nqueue')")
    op.execute("INSERT INTO workflow_templates (workflow_name, filename, content) VALUES "
               "('null', 'null.sh', E'#!/bin/sh\n\nnull $*')")
    op.execute("INSERT INTO workflow_templates (workflow_name, filename, content) VALUES "
               "('null', 'null.dag', 'JOB null null.condor')")


def downgrade():
    op.drop_table('workflow_request_files')
    op.drop_table('workflow_requests')
    op.drop_table('workflow_templates')
    op.drop_table('workflows')