"""add capability version files

Revision ID: 0465047a3df1
Revises: a118f3d0a99e
Create Date: 2021-05-25 15:13:46.814174

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '0465047a3df1'
down_revision = 'a118f3d0a99e'
branch_labels = None
depends_on = None


def upgrade():
    op.create_table(
        "capability_version_files",
        sa.Column(
            "capability_request_id",
            sa.Integer,
            primary_key=True,
            comment="the id of the parent capability request"
        ),
        sa.Column(
            "version_number",
            sa.Integer,
            primary_key=True,
            comment="the version number of the parent capability request"
        ),
        sa.Column(
            "filename",
            sa.String,
            primary_key=True,
            comment="the name of this file",
            nullable=False
        ),
        sa.Column(
            "content",
            sa.LargeBinary,
            comment="the contents of this file",
            nullable=False
        ),
        sa.ForeignKeyConstraint(
            ("capability_request_id", "version_number"),
            ["capability_versions.capability_request_id", "capability_versions.version_number"]),
        comment="A many-to-many mapping table tracking which files were manually added to a capability version"
    )


def downgrade():
    op.drop_table("capability_version_files")