I have the following table:
my_table = sa.sql.table('my_table',
sa.Column('id', sa.BigInteger),
sa.Column('employee_id', sa.BigInteger)
)
and I want to add a 'rank' column using alembic.
The addition itself is pretty straight forward using add_column
but I also need to populate that column using sqlalchemy based on existing information (each employee_id has its own rank ordered by the id).
For example, the following table:
id employee_id rank -- ----------- ---- 1 1 1 2 1 2 5 1 3 3 2 1 4 3 1 6 3 2
The problem is similar to this one.
The only difference is that I need it working for sqlalchemy on top of both mysql and oracle (a more generic solution is needed).
How can I populate the rank column using engine.update?
EDIT 1: This question is not about how to insert or update records through alembic. It's about finding a query that will do a specific thing and running this query using engine.update