Esempio n. 1
0
def upgrade():
    hannara_id = Party.query.filter_by(name='한나라당').one().id
    fannara_id = Party.query.order_by(desc(Party.id)).limit(1).one().id + 1

    # New party
    op.execute(party_t.insert().values({
        'id': fannara_id,
        'name': '한나라당(2012)'
    }))

    for candidacy in Candidacy.query.filter_by(party_id=hannara_id,
                                               age=19):
        # Update party affiliation
        op.execute(party_affiliation.update()\
                         .values({
                             'party_id': fannara_id
                         })\
                         .where(and_(
                             party_affiliation.c.party_id == hannara_id,
                             party_affiliation.c.person_id == candidacy.person_id
                         ))
        )

        # Update candidacy
        op.execute(candidacy_t.update()\
                              .values({
                                  'party_id': fannara_id
                              })\
                              .where(candidacy_t.c.id == candidacy.id)
        )

    update_party_meta()
Esempio n. 2
0
def downgrade():
    hannara_id = Party.query.filter_by(name='한나라당').one().id
    fannara_id = Party.query.filter_by(name='한나라당(2012)').one().id

    op.execute(party_affiliation.update()\
                     .values({
                         'party_id': hannara_id
                     })\
                     .where(party_affiliation.c.party_id == fannara_id)
    )

    op.execute(candidacy_t.update()\
                          .values({
                              'party_id': hannara_id
                          })\
                          .where(candidacy_t.c.party_id == fannara_id)
    )

    op.execute(party_t.delete().where(party_t.c.id == fannara_id))
    update_party_meta()