"""multiple_revision_authors

Revision ID: 2174d4350f40
Revises: f8851082b9d9
Create Date: 2020-01-06 15:57:52.051760

"""
import zeus
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "2174d4350f40"
down_revision = "f8851082b9d9"
branch_labels = ()
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "revision_author",
        sa.Column("repository_id", zeus.db.types.guid.GUID(), nullable=False),
        sa.Column("revision_sha", sa.String(length=40), nullable=False),
        sa.Column("author_id", zeus.db.types.guid.GUID(), nullable=False),
        sa.ForeignKeyConstraint(["author_id"], ["author.id"], ondelete="CASCADE"),
        sa.ForeignKeyConstraint(
            ["repository_id", "revision_sha"],
            ["revision.repository_id", "revision.sha"],
            ondelete="CASCADE",
        ),
        sa.ForeignKeyConstraint(
            ["repository_id"], ["repository.id"], ondelete="CASCADE"
        ),
        sa.PrimaryKeyConstraint("repository_id", "revision_sha", "author_id"),
    )
    op.drop_index("ix_revision_repository_id", table_name="revision")
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_index(
        "ix_revision_repository_id", "revision", ["repository_id"], unique=False
    )
    op.drop_table("revision_author")
    # ### end Alembic commands ###
