"""Add user preferences table

Revision ID: 8a6a7662eb37
Revises: f703f911d4ae
Create Date: 2018-11-20 17:02:26.408532

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '8a6a7662eb37'
down_revision = 'f703f911d4ae'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('user_preferences',
    sa.Column('user_id', sa.Integer(), nullable=False),
    sa.Column('hide_comments', sa.Boolean(), server_default=sa.sql.expression.false(), nullable=False),
    sa.ForeignKeyConstraint(['user_id'], ['users.id'], ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('user_id')
    )

    connection = op.get_bind()

    print('Populating user_preferences...')
    connection.execute(sa.sql.text('INSERT INTO user_preferences (user_id) SELECT id FROM users'))
    print('Done.')
    # ### end Alembic commands ###


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