Currently only supports PostgreSQL
The Drifter project provides custom Django management commands to manage database migrations. It includes commands to revert and redo migrations for a specified app or the entire project.
These commands are most useful during development and so cannot be
run in production (DEBUG = False
).
- Revert Migration: Reverts one or more migrations, optionally for a specified app.
- Redo Migration: Reverts and re-applies the last migration, optionally for a specified app.
- Reset Database: Drops all tables and runs all migrations.
- Install the package:
pip install django-drifter
- Add
drifter
to theINSTALLED_APPS
setting in your Django project'ssettings.py
file:INSTALLED_APPS = [ "drifter", ..., ]
The revert_migration
command reverts the last migration for a specified app.
python manage.py revert_migration [app_name] [--num N]
app_name
: The name of the app whose migration you want to revert.--num N
: (Optional) The number of migrations to revert. Defaults to 1.
The redo_migration
command undoes and redoes the last migration for a specified app.
python manage.py redo_migration [--app app_name]
--app app_name
: (Optional) The name of the app whose migration you want to redo.
The reset_database
command drops all tables and runs all migrations.
python manage.py reset_database [--yes]
--yes
: (Optional) Skips the confirmation prompt.
Before running the tests, start a local Postgres database:
docker run --name drifter-postgres -e POSTGRES_USER=django -e POSTGRES_PASSWORD=django -p 5432:5432 -d polls
To run the tests, use the following command:
pytest
python manage.py revert_migration polls --num 2
This command reverts the last two migrations for the polls
app.
python manage.py redo_migration --app polls
This command redoes the last migration for the polls
app.
python manage.py reset_database
This command drops all tables and runs all migrations.
Contributions are more than welcome! Please follow these steps to contribute:
- Fork the repository.
- Create a new branch (
git checkout -b feature-branch
). - Make your changes.
- Commit your changes (
git commit -am 'Add new feature'
). - Push to the branch (
git push origin feature-branch
). - Create a new Pull Request.
This project is licensed under the Apache 2.0 License. See the LICENSE
file for more details.