"""user name organization

Revision ID: 7ee0d022e8d6
Revises: 3e7e65c44fc2
Create Date: 2016-08-22 22:27:02.630331

"""

# revision identifiers, used by Alembic.
revision = '7ee0d022e8d6'
down_revision = '3e7e65c44fc2'
branch_labels = None
depends_on = None

from alembic import op
import sqlalchemy as sa
from _15thnight.models import User


def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.add_column(
        'users', sa.Column('name', sa.String(length=255), nullable=True))
    op.add_column(
        'users',
        sa.Column('organization', sa.String(length=255), nullable=True))
    op.execute(
        User.__table__.update()
        .where(User.__table__.c.name == None)
        .values(**{'name': ''})
    )
    op.alter_column(
        'users', 'name', existing_type=sa.String(length=255),
        nullable=False)
    op.execute(
        User.__table__.update()
        .where(User.__table__.c.organization == None)
        .values(**{'organization': ''})
    )
    op.alter_column(
        'users', 'organization', existing_type=sa.String(length=255),
        nullable=False)
    ### end Alembic commands ###


def downgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.drop_column('users', 'organization')
    op.drop_column('users', 'name')
    ### end Alembic commands ###
