diff options
| author | Jocelyn Delande <jocelyn@crapouillou.net> | 2016-06-15 10:19:08 +0200 |
|---|---|---|
| committer | Jocelyn Delande <jocelyn@crapouillou.net> | 2016-06-16 15:52:24 +0200 |
| commit | d3bb04c1bfdd24cc09db939ac9bbaf540bfdfc0c (patch) | |
| tree | d85a38f2557674c9a28e156ad9cead7cbcd0847e /budget/migrations/versions | |
| parent | 7a630b78eae90a57033f785a2253fd490868352d (diff) | |
| download | ihatemoney-mirror-d3bb04c1bfdd24cc09db939ac9bbaf540bfdfc0c.zip ihatemoney-mirror-d3bb04c1bfdd24cc09db939ac9bbaf540bfdfc0c.tar.gz ihatemoney-mirror-d3bb04c1bfdd24cc09db939ac9bbaf540bfdfc0c.tar.bz2 | |
Add migration to initialize Person weights
That's for Persons that existed before the weights were added to model.
Diffstat (limited to 'budget/migrations/versions')
| -rw-r--r-- | budget/migrations/versions/f629c8ef4ab0_initialize_all_members_weights_to_1.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/budget/migrations/versions/f629c8ef4ab0_initialize_all_members_weights_to_1.py b/budget/migrations/versions/f629c8ef4ab0_initialize_all_members_weights_to_1.py new file mode 100644 index 0000000..5542146 --- /dev/null +++ b/budget/migrations/versions/f629c8ef4ab0_initialize_all_members_weights_to_1.py @@ -0,0 +1,39 @@ +"""Initialize all members weights to 1 + +Revision ID: f629c8ef4ab0 +Revises: 26d6a218c329 +Create Date: 2016-06-15 09:40:30.400862 + +""" + +# revision identifiers, used by Alembic. +revision = 'f629c8ef4ab0' +down_revision = '26d6a218c329' + +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 == None) + .values(weight=1) + ) + + +def downgrade(): + # Downgrade path is not possible, because information has been lost. + pass |
