"""add usernotes constraints

Revision ID: 16d6335dd9a3
Revises: 4a1f7859151b
Create Date: 2022-05-16 19:42:28.708577+00:00

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '16d6335dd9a3'
down_revision = '4a1f7859151b'
branch_labels = None
depends_on = None


def upgrade():
	# ### commands auto generated by Alembic - please adjust! ###
	op.alter_column('usernotes', 'note',
			   existing_type=sa.VARCHAR(length=10000),
			   nullable=False)
	op.alter_column('usernotes', 'tag',
			   existing_type=sa.VARCHAR(length=10),
			   nullable=False)
	op.create_foreign_key('usernotes_author_id_fkey', 'usernotes', 'users', ['author_id'], ['id'])
	op.create_foreign_key('usernotes_reference_comment_fkey', 'usernotes', 'comments', ['reference_comment'], ['id'], ondelete='SET NULL')
	op.create_foreign_key('usernotes_reference_post_fkey', 'usernotes', 'submissions', ['reference_post'], ['id'], ondelete='SET NULL')
	op.create_foreign_key('usernotes_reference_user_fkey', 'usernotes', 'users', ['reference_user'], ['id'], ondelete='CASCADE')
	# ### end Alembic commands ###


def downgrade():
	# ### commands auto generated by Alembic - please adjust! ###
	op.drop_constraint('usernotes_reference_user_fkey', 'usernotes', type_='foreignkey')
	op.drop_constraint('usernotes_reference_post_fkey', 'usernotes', type_='foreignkey')
	op.drop_constraint('usernotes_reference_comment_fkey', 'usernotes', type_='foreignkey')
	op.drop_constraint('usernotes_author_id_fkey', 'usernotes', type_='foreignkey')
	op.alter_column('usernotes', 'tag',
			   existing_type=sa.VARCHAR(length=10),
			   nullable=True)
	op.alter_column('usernotes', 'note',
			   existing_type=sa.VARCHAR(length=10000),
			   nullable=True)
	# ### end Alembic commands ###
