aboutsummaryrefslogtreecommitdiff
path: root/ihatemoney/migrations/versions
diff options
context:
space:
mode:
authorAlexis Metaireau <alexis@notmyidea.org>2019-01-03 13:29:56 +0100
committerGitHub <noreply@github.com>2019-01-03 13:29:56 +0100
commitd55b9961704f913312ae17f837f62d1822802ecf (patch)
tree02bc27f0b6ffdaf15a08b651d2953f35356c0148 /ihatemoney/migrations/versions
parent04adfe4155e1bb37609edfe78ae67b361f51e0cf (diff)
downloadihatemoney-mirror-d55b9961704f913312ae17f837f62d1822802ecf.zip
ihatemoney-mirror-d55b9961704f913312ae17f837f62d1822802ecf.tar.gz
ihatemoney-mirror-d55b9961704f913312ae17f837f62d1822802ecf.tar.bz2
Do not allow negative weights on users (Fixes #362) (#366)
Diffstat (limited to 'ihatemoney/migrations/versions')
-rw-r--r--ihatemoney/migrations/versions/a67119aa3ee5_migrate_negative_weights.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/ihatemoney/migrations/versions/a67119aa3ee5_migrate_negative_weights.py b/ihatemoney/migrations/versions/a67119aa3ee5_migrate_negative_weights.py
new file mode 100644
index 0000000..ec23470
--- /dev/null
+++ b/ihatemoney/migrations/versions/a67119aa3ee5_migrate_negative_weights.py
@@ -0,0 +1,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