"""kql_flat

Revision: 0160
Revision ID: 1ef3e95bf70d
Revises: 2f1187b05f65
Create Date: 2019-02-19 22:34:16.800414

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '1ef3e95bf70d'
down_revision = '2f1187b05f65'
branch_labels = None
depends_on = None


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


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


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