Skip to content

Instantly share code, notes, and snippets.

@inklesspen
Created April 4, 2017 07:10
Show Gist options
  • Save inklesspen/dc6c7c55ab44b2d6b3bf355c3e4b7c0a to your computer and use it in GitHub Desktop.
Save inklesspen/dc6c7c55ab44b2d6b3bf355c3e4b7c0a to your computer and use it in GitHub Desktop.
from alembic import op
import sqlalchemy as sa
def upgrade():
t_files = sa.table('files', sa.column('id', sa.String(32)), sa.column('content', sa.Blob()))
# we have to use get_bind() because op.execute() doesn't have a return value
# but by using get_bind() we can no longer generate SQL scripts for the migration; we have to run it live
connection = op.get_bind()
my_id = '14c3e928ed9d4ecaa57226bc5b628132'
data = connection.execute(sa.select([t_files.c.content]).where(t_files.c.id == my_id)).scalar()
new_data = transform_data(data)
connection.execute(t_files.update().where(t_files.c.id == my_id).values(content=new_data))
def downgrade():
pass
@jenstroeger
Copy link

I need to update my Alchemy then, yes.

And after the instant commit, will there be a new transaction or instant commits from thereon?

@jenstroeger
Copy link

I’ve finally updated the SO answer here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment