"""Initial Migration

Revision ID: df2981bf24dd
Revises: 
Create Date: 2024-07-11 19:33:37.993767

"""
from typing import Sequence, Union

from alembic import op
from grpc import server # noqa: F401
import sqlalchemy as sa
import sqlmodel # noqa: F401


# revision identifiers, used by Alembic.
revision: str = 'df2981bf24dd'
down_revision: Union[str, None] = None
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('activity', sa.Column('published', sa.Boolean(), nullable=False, server_default=sa.true()))
    # If you need to rename columns instead of dropping them, use the rename_column command
    # For example, if we are changing the name 'published_version' to 'published', we would use:
    # op.alter_column('activity', 'published_version', new_column_name='published', existing_type=sa.Boolean())
    op.drop_column('activity', 'published_version')
    op.drop_column('activity', 'version')
    
    op.drop_column('assignmentusersubmission', 'assignment_user_uuid')

    op.drop_constraint('trail_org_id_fkey', 'trail', type_='foreignkey')
    op.create_foreign_key('trail_org_id_fkey', 'trail', 'organization', ['org_id'], ['id'], ondelete='CASCADE')
    op.drop_constraint('trail_user_id_fkey', 'trail', type_='foreignkey')
    op.create_foreign_key('trail_user_id_fkey', 'trail', 'user', ['user_id'], ['id'], ondelete='CASCADE')
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint('trail_org_id_fkey', 'trail', type_='foreignkey')
    op.create_foreign_key('trail_org_id_fkey', 'trail', 'organization', ['org_id'], ['id'])
    op.drop_constraint('trail_user_id_fkey', 'trail', type_='foreignkey')
    op.create_foreign_key('trail_user_id_fkey', 'trail', 'user', ['user_id'], ['id'])

    op.add_column('assignmentusersubmission', sa.Column('assignment_user_uuid', sa.VARCHAR(), autoincrement=False, nullable=False))

    op.add_column('activity', sa.Column('version', sa.INTEGER(), autoincrement=False, nullable=False, server_default=sa.text('1')))
    op.add_column('activity', sa.Column('published_version', sa.INTEGER(), autoincrement=False, nullable=False, server_default=sa.text('1')))
    op.drop_column('activity', 'published')
    # ### end Alembic commands ###

