Fix bugs in migrations

This commit is contained in:
Tulir Asokan
2018-08-17 00:06:02 +03:00
parent 1ef790ce31
commit bb04231880
5 changed files with 19 additions and 8 deletions
@@ -21,4 +21,5 @@ def upgrade():
def downgrade():
op.drop_column('puppet', 'is_bot')
with op.batch_alter_table("puppet") as batch_op:
batch_op.drop_column('is_bot')
@@ -20,4 +20,5 @@ def upgrade():
def downgrade():
op.drop_column('portal', 'megagroup')
with op.batch_alter_table("portal") as batch_op:
batch_op.drop_column('megagroup')
@@ -72,10 +72,17 @@ def upgrade():
sa.Column("avatar_url", sa.String(), nullable=True),
sa.PrimaryKeyConstraint("room_id", "user_id"))
try:
migrate_state_store()
except Exception as e:
print("Failed to migrate state store:", e)
print("Migrating the state store isn't required, but you can retry by alembic downgrading "
"to revision 2228d49c383f and upgrading again.")
def migrate_state_store():
conn = op.get_bind()
session = orm.sessionmaker(bind=conn)
session = orm.scoping.scoped_session(session)
Puppet.query = session.query_property()
session = orm.sessionmaker(bind=conn)() # type: orm.Session
try:
with open("mx-state.json") as file:
@@ -99,7 +106,7 @@ def upgrade():
if not match:
continue
puppet = Puppet.query.get(match.group(1))
puppet = session.query(Puppet).get(match.group(1))
if not puppet:
continue
@@ -22,4 +22,5 @@ def upgrade():
def downgrade():
op.drop_column('telegram_file', 'timestamp')
with op.batch_alter_table("telegram_file") as batch_op:
batch_op.drop_column('timestamp')
@@ -20,4 +20,5 @@ def upgrade():
def downgrade():
op.drop_column('puppet', 'displayname_source')
with op.batch_alter_table("puppet") as batch_op:
batch_op.drop_column('displayname_source')