Harshal Patil
Harshal Patil

Reputation: 21030

How do I handle migrations in sqlalchemy without any framework?

I have seen sqlalchemy-migrate and alembic, but I do not want to use those frameworks. How can I write the migration script? Most of the migrations as I understand revolve around altering/dropping existing tables? Additionally, I use sqlalchemy mostly at orm level than schema/core/engine level?

The reasons I wish to do-it-myself is mostly a learning purpose and understanding how django orm automatically generates a migration script?

Upvotes: 1

Views: 2156

Answers (1)

Ian Wilson
Ian Wilson

Reputation: 9109

You should just use alembic to execute raw sql to start. Then if you decide to try to use more alembic features you'll be all set.

For example after creating a new revision named drop nick you can execute raw sql:

op.execute ('ALTER TABLE users DROP COLUMN nickname')

This way alembic can handle the version numbers but you can, or rather have to, do all the sql manipulations manually.

Upvotes: 2

Related Questions