"""add-agent-version

Revision ID: 02950808ca3d
Revises: 4cc87e7fbfdf
Create Date: 2019-06-02 21:14:12.320029

"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = '02950808ca3d'
down_revision = '4cc87e7fbfdf'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column(
        'agents',
        # Set the defualt to "19.06.0" for now (since it is the first version to have this field)
        # and let the heartbeat handler route to update with the exact value.
        sa.Column('compute_plugins', postgresql.JSONB(astext_type=sa.Text()), nullable=False,
                  server_default=sa.text("'{}'::jsonb")))
    op.add_column(
        'agents',
        sa.Column('version', sa.String(length=64), nullable=False,
                  server_default=sa.literal('19.06.0')))
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_column('agents', 'version')
    op.drop_column('agents', 'compute_plugins')
    # ### end Alembic commands ###
