"""add vfolder_permissions table

Revision ID: 185852ff9872
Revises: 1fa6a31ea8e3
Create Date: 2018-07-05 16:02:05.225094

"""
from alembic import op
import sqlalchemy as sa
from ai.backend.manager.models.base import GUID


# revision identifiers, used by Alembic.
revision = '185852ff9872'
down_revision = '1fa6a31ea8e3'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        'vfolder_permissions',
        sa.Column('permission', sa.String(length=2), nullable=True),
        sa.Column('vfolder', GUID(), nullable=False),
        sa.Column('access_key', sa.String(length=20), nullable=False),
        sa.ForeignKeyConstraint(['access_key'], ['keypairs.access_key'],
                                name=op.f('fk_vfolder_permissions_access_key_keypairs')),
        sa.ForeignKeyConstraint(['vfolder'], ['vfolders.id'],
                                name=op.f('fk_vfolder_permissions_vfolder_vfolders'),
                                onupdate='CASCADE', ondelete='CASCADE')
    )
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table('vfolder_permissions')
    # ### end Alembic commands ###
