I am attempting to include Alembic migrations as part of a python package distribution. Since this distribution will be installed, the Alembic scripting directory (which holds the migrations) will end up being copied to the python packages folders. In this case, how can I tell Alembic where to find this directory?
In the Alembic documentation, it says that the migration
directory can be specified in the config.ini
file as a package reference:
- script_location - this is the location of the Alembic environment. It is normally specified as a filesystem location, either relative or absolute. If the location is a relative path, it’s interpreted as relative to the current directory.
(snip)
For support of applications that package themselves into .egg files, the value can also be specified as a package resource, in which case resource_filename() is used to find the file (new in 0.2.2). Any non-absolute URI which contains colons is interpreted here as a resource name, rather than a straight filename.
The documentation gives no further information or examples.
Has anyone successfully implemented this? How exactly do you make your migration
scripting_folder into a "package resource"? How then do you tell alembic where to find it?
If you want to run to downgrade() of a version, you will need to run alembic downgrade the-version-before-it , which mean it will revert to the version after the version that you want to downgrade. Which is the version before the version that we want to revert. Hope it's clear enough.
Delete (or move to another folder) the specific migration file (in migrations/versions folder). The head will automatically revert to the most recent remaining migration. Using stamp will set the db version value to the specified revision; not alter the head revision number.
¶ Alembic is a lightweight database migration tool for usage with the SQLAlchemy Database Toolkit for Python. Front Matter. Project Homepage. Installation.
For instance:
script_location = mypackage:somewhere/inside/it
This requires that you include the migrations inside your distribution: you should look at your MANIFEST.in file, etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With