summaryrefslogtreecommitdiff
path: root/zuul/driver/sql/alembic/versions/60c119eb1e3f_use_build_set_results.py
blob: 1735d35f37fd22eb9530b7e1663385c26b97a0d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"""Use build_set results

Revision ID: 60c119eb1e3f
Revises: f86c9871ee67
Create Date: 2017-07-27 17:09:20.374782

"""

# revision identifiers, used by Alembic.
revision = '60c119eb1e3f'
down_revision = 'f86c9871ee67'
branch_labels = None
depends_on = None

from alembic import op
import sqlalchemy as sa

BUILDSET_TABLE = 'zuul_buildset'


def upgrade(table_prefix=''):
    op.add_column(
        table_prefix + BUILDSET_TABLE, sa.Column('result', sa.String(255)))

    connection = op.get_bind()
    connection.execute(
        sa.text(
            """
            UPDATE {buildset_table}
             SET result=(
                 SELECT CASE score
                    WHEN 1 THEN 'SUCCESS'
                    ELSE 'FAILURE' END)
            """.format(buildset_table=table_prefix + BUILDSET_TABLE)
        )
    )

    op.drop_column(table_prefix + BUILDSET_TABLE, 'score')


def downgrade():
    raise Exception("Downgrades not supported")