"""kql_flat

Revision ID: 0261
Revises: 0260
Create Date: 2019-02-19 22:34:16.800414

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '0261'
down_revision = '0260'
branch_labels = None
depends_on = None


def upgrade():
    op.execute("""
        CREATE OR REPLACE FUNCTION kql_flat(data timestamptz[]) RETURNS timestamptz
        AS
        $BODY$
            SELECT data[1];
        $BODY$
        LANGUAGE sql;
    """)


    op.execute("""
        CREATE OR REPLACE FUNCTION kql_flat(data timestamptz) RETURNS timestamptz
        AS
        $BODY$
            SELECT data;
        $BODY$
        LANGUAGE sql;
    """)


def downgrade():
    op.execute("DROP FUNCTION kql_flat(timestamptz[])")
    op.execute("DROP FUNCTION kql_flat(timestamptz)")
