"""missing_kql_flat

Revision: 0150
Revision ID: 476d0278b0a7
Revises: 49495b7b574
Create Date: 2018-11-26 14:54:22.734393

"""

# revision identifiers, used by Alembic.
revision = '476d0278b0a7'
down_revision = '49495b7b574'
branch_labels = None
depends_on = None

from alembic import op
import sqlalchemy as sa


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


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


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