Django Drifter Project
Currently only supports PostgreSQL
Overview
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).
Features
- 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.
Installation
- Install the package:
sh pip install django-drifter - Add
drifterto theINSTALLED_APPSsetting in your Django project'ssettings.pyfile:python INSTALLED_APPS = [ "drifter", ..., ]
Usage
Revert Migration
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.
Redo Migration
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.
Reset Database
The reset_database command drops all tables and runs all migrations.
python manage.py reset_database [--yes]
--yes: (Optional) Skips the confirmation prompt.
Running Tests
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
Example
Revert Migration Example
python manage.py revert_migration polls --num 2
This command reverts the last two migrations for the polls app.
Redo Migration Example
python manage.py redo_migration --app polls
This command redoes the last migration for the polls app.
Reset Database Example
python manage.py reset_database
This command drops all tables and runs all migrations.
Contributing
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.
License
This project is licensed under the Apache 2.0 License. See the LICENSE file for more details.