"""programs

Revision ID: 7365b4898472
Revises: dbcc4e3ff1e0
Create Date: 2022-12-22 00:10:25.243623

"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = '7365b4898472'
down_revision = 'dbcc4e3ff1e0'
branch_labels = None
depends_on = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('programs',
    sa.Column('item_hash', sa.String(), nullable=False),
    sa.Column('owner', sa.String(), nullable=False),
    sa.Column('type', sa.String(), nullable=False),
    sa.Column('allow_amend', sa.Boolean(), nullable=False),
    sa.Column('metadata', postgresql.JSONB(astext_type=sa.Text()), nullable=True),
    sa.Column('variables', postgresql.JSONB(astext_type=sa.Text()), nullable=True),
    sa.Column('http_trigger', sa.Boolean(), nullable=False),
    sa.Column('message_triggers', postgresql.JSONB(astext_type=sa.Text()), nullable=True),
    sa.Column('persistent', sa.Boolean(), nullable=False),
    sa.Column('environment_reproducible', sa.Boolean(), nullable=False),
    sa.Column('environment_internet', sa.Boolean(), nullable=False),
    sa.Column('environment_aleph_api', sa.Boolean(), nullable=False),
    sa.Column('environment_shared_cache', sa.Boolean(), nullable=False),
    sa.Column('resources_vcpus', sa.Integer(), nullable=False),
    sa.Column('resources_memory', sa.Integer(), nullable=False),
    sa.Column('resources_seconds', sa.Integer(), nullable=False),
    sa.Column('cpu_architecture', sa.String(), nullable=True),
    sa.Column('cpu_vendor', sa.String(), nullable=True),
    sa.Column('node_owner', sa.String(), nullable=True),
    sa.Column('node_address_regex', sa.String(), nullable=True),
    sa.Column('replaces', sa.String(), nullable=True),
    sa.ForeignKeyConstraint(['replaces'], ['programs.item_hash'], ),
    sa.PrimaryKeyConstraint('item_hash')
    )
    op.create_index(op.f('ix_programs_owner'), 'programs', ['owner'], unique=False)
    op.create_table('program_code_volumes',
    sa.Column('encoding', sa.String(), nullable=False),
    sa.Column('ref', sa.String(), nullable=True),
    sa.Column('use_latest', sa.Boolean(), nullable=True),
    sa.Column('entrypoint', sa.String(), nullable=False),
    sa.Column('program_hash', sa.String(), nullable=False),
    sa.ForeignKeyConstraint(['program_hash'], ['programs.item_hash'], ),
    sa.PrimaryKeyConstraint('program_hash')
    )
    op.create_table('program_data_volumes',
    sa.Column('encoding', sa.String(), nullable=False),
    sa.Column('ref', sa.String(), nullable=True),
    sa.Column('use_latest', sa.Boolean(), nullable=True),
    sa.Column('mount', sa.String(), nullable=False),
    sa.Column('program_hash', sa.String(), nullable=False),
    sa.ForeignKeyConstraint(['program_hash'], ['programs.item_hash'], ),
    sa.PrimaryKeyConstraint('program_hash')
    )
    op.create_table('program_export_volumes',
    sa.Column('encoding', sa.String(), nullable=False),
    sa.Column('program_hash', sa.String(), nullable=False),
    sa.ForeignKeyConstraint(['program_hash'], ['programs.item_hash'], ),
    sa.PrimaryKeyConstraint('program_hash')
    )
    op.create_table('program_machine_volumes',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('type', sa.String(), nullable=False),
    sa.Column('program_hash', sa.String(), nullable=False),
    sa.Column('comment', sa.String(), nullable=True),
    sa.Column('mount', sa.String(), nullable=True),
    sa.Column('size_mib', sa.Integer(), nullable=True),
    sa.Column('ref', sa.String(), nullable=True),
    sa.Column('use_latest', sa.Boolean(), nullable=True),
    sa.Column('persistence', sa.String(), nullable=True),
    sa.Column('name', sa.String(), nullable=True),
    sa.ForeignKeyConstraint(['program_hash'], ['programs.item_hash'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_program_machine_volumes_program_hash'), 'program_machine_volumes', ['program_hash'], unique=False)
    op.create_table('program_runtimes',
    sa.Column('ref', sa.String(), nullable=True),
    sa.Column('use_latest', sa.Boolean(), nullable=True),
    sa.Column('program_hash', sa.String(), nullable=False),
    sa.Column('comment', sa.String(), nullable=False),
    sa.ForeignKeyConstraint(['program_hash'], ['programs.item_hash'], ),
    sa.PrimaryKeyConstraint('program_hash')
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table('program_runtimes')
    op.drop_index(op.f('ix_program_machine_volumes_program_hash'), table_name='program_machine_volumes')
    op.drop_table('program_machine_volumes')
    op.drop_table('program_export_volumes')
    op.drop_table('program_data_volumes')
    op.drop_table('program_code_volumes')
    op.drop_index(op.f('ix_programs_owner'), table_name='programs')
    op.drop_table('programs')
    # ### end Alembic commands ###
