aboutsummaryrefslogtreecommitdiff
path: root/ihatemoney/migrations/versions/a67119aa3ee5_migrate_negative_weights.py
blob: ec2347064707ac9ec1ed4f9fe00e6ed43b0f63f2 (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
"""Migrate negative weights

Revision ID: a67119aa3ee5
Revises: afbf27e6ef20
Create Date: 2018-12-25 18:34:20.220844

"""

# revision identifiers, used by Alembic.
revision = 'a67119aa3ee5'
down_revision = 'afbf27e6ef20'

from alembic import op
import sqlalchemy as sa
# Snapshot of the person table
person_helper = sa.Table(
    'person', sa.MetaData(),
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('project_id', sa.String(length=64), nullable=True),
    sa.Column('name', sa.UnicodeText(), nullable=True),
    sa.Column('activated', sa.Boolean(), nullable=True),
    sa.Column('weight', sa.Float(), nullable=True),
    sa.ForeignKeyConstraint(['project_id'], ['project.id'], ),
    sa.PrimaryKeyConstraint('id')
)


def upgrade():
    op.execute(
        person_helper.update()
        .where(person_helper.c.weight <= 0)
        .values(weight=1)
    )


def downgrade():
    # Downgrade path is not possible, because information has been lost.
    pass