"""empty message

Revision ID: 5831feaf2ee0
Revises: b177e0dff464
Create Date: 2017-09-08 12:32:15.767437

"""
from alembic import op
import sqlalchemy as sa

# revision identifiers, used by Alembic.
revision = '5831feaf2ee0'
down_revision = 'b177e0dff464'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.alter_column('job', 'number',
               existing_type=sa.Float(),
               type_=sa.String(),
               existing_nullable=True)
    # ### end Alembic commands ###

    j = sa.sql.table('job',
                       sa.sql.column('number', sa.String),
                       sa.sql.column('product_id', sa.Integer),
                       sa.sql.column('', sa.String))
    p = sa.sql.table('product',
                           sa.sql.column('id', sa.Integer),
                           sa.sql.column('name', sa.String))

    # UPDATE job j
    # SET number = j.number || '0'
    # FROM product p
    # WHERE
    #   j.number LIKE '%.1' AND
    #   j.product_id = p.id AND
    #   p.name <> 'lint'
    op.execute(j.update().
               values(number=j.c.number.concat('0')).
               where(j.c.number.endswith('%.1')).
               where(j.c.product_id == p.c.id).
               where(p.c.name != 'lint'))


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.alter_column('job', 'number',
               existing_type=sa.String(),
               type_=sa.Float(),
               existing_nullable=True,
               postgresql_using='number::double precision')
    # ### end Alembic commands ###
