"""kql_flat

Revision: 0145
Revision ID: 2e10b78f004e
Revises: 3bcdc4dfe14c
Create Date: 2018-10-17 15:56:21.370847

"""

# revision identifiers, used by Alembic.
revision = '2e10b78f004e'
down_revision = '3bcdc4dfe14c'
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 integer[]) RETURNS integer
        AS
        $BODY$
            SELECT data[1];
        $BODY$
        LANGUAGE sql;
    """)


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


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


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


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


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


def downgrade():
    op.execute("DROP FUNCTION kql_flat(integer[])")
    op.execute("DROP FUNCTION kql_flat(numeric[])")
    op.execute("DROP FUNCTION kql_flat(text[])")
    op.execute("DROP FUNCTION kql_flat(integer)")
    op.execute("DROP FUNCTION kql_flat(numeric)")
    op.execute("DROP FUNCTION kql_flat(text)")
