"""empty message

Revision ID: 469154bafe22
Revises: 450edaa5f10d
Create Date: 2017-04-30 22:28:25.540557

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '469154bafe22'
down_revision = '450edaa5f10d'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('cluster', sa.Column('k8s_service_account_private_key', sa.Binary(), nullable=True))
    op.add_column('cluster', sa.Column('k8s_service_account_public_key', sa.Binary(), nullable=True))
    op.execute('UPDATE cluster SET k8s_service_account_private_key=(SELECT key FROM credentials_data WHERE credentials_data.id = cluster.service_account_keypair_id)')
    op.execute('UPDATE cluster SET k8s_service_account_public_key=(SELECT cert FROM credentials_data WHERE credentials_data.id = cluster.service_account_keypair_id)')
    op.alter_column('cluster', 'k8s_service_account_private_key', nullable=False)
    op.alter_column('cluster', 'k8s_service_account_public_key', nullable=False)
    op.drop_constraint('cluster_service_account_keypair_id_fkey', 'cluster', type_='foreignkey')
    op.drop_column('cluster', 'service_account_keypair_id')
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('cluster', sa.Column('service_account_keypair_id', sa.INTEGER(), autoincrement=False, nullable=False))
    op.create_foreign_key('cluster_service_account_keypair_id_fkey', 'cluster', 'credentials_data', ['service_account_keypair_id'], ['id'])
    op.drop_column('cluster', 'k8s_service_account_public_key')
    op.drop_column('cluster', 'k8s_service_account_private_key')
    # ### end Alembic commands ###
