Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kennethlove/django-drifter
A small Django utility to make it easier to revert and redo migrations or to recreate your database.
https://github.com/kennethlove/django-drifter
django migrations
Last synced: 17 days ago
JSON representation
A small Django utility to make it easier to revert and redo migrations or to recreate your database.
- Host: GitHub
- URL: https://github.com/kennethlove/django-drifter
- Owner: kennethlove
- License: apache-2.0
- Created: 2024-09-04T00:36:16.000Z (2 months ago)
- Default Branch: main
- Last Pushed: 2024-09-26T19:49:21.000Z (about 2 months ago)
- Last Synced: 2024-10-15T04:32:50.695Z (about 1 month ago)
- Topics: django, migrations
- Language: Python
- Homepage:
- Size: 50.8 KB
- Stars: 47
- Watchers: 4
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.txt
- License: LICENSE.txt
Awesome Lists containing this project
README
# 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
1. Install the package:
```sh
pip install django-drifter
```
2. Add `drifter` to the `INSTALLED_APPS` setting in your Django project's `settings.py` file:
```python
INSTALLED_APPS = [
"drifter",
...,
]
```## Usage
### Revert Migration
The `revert_migration` command reverts the last migration for a specified app.
```sh
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.
```sh
python manage.py redo_migration [--app app_name]
```- `--app app_name`: (Optional) The name of the app whose migration you want to redo.
### Reset DatabaseThe `reset_database` command drops all tables and runs all migrations.
```sh
python manage.py reset_database [--yes]
```- `--yes`: (Optional) Skips the confirmation prompt.
## Running Tests
Before running the tests, start a local Postgres database:
```shell
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:
```sh
pytest
```## Example
### Revert Migration Example
```sh
python manage.py revert_migration polls --num 2
```This command reverts the last two migrations for the `polls` app.
### Redo Migration Example
```sh
python manage.py redo_migration --app polls
```This command redoes the last migration for the `polls` app.
### Reset Database Example
```sh
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:
1. Fork the repository.
2. Create a new branch (`git checkout -b feature-branch`).
3. Make your changes.
4. Commit your changes (`git commit -am 'Add new feature'`).
5. Push to the branch (`git push origin feature-branch`).
6. Create a new Pull Request.## License
This project is licensed under the Apache 2.0 License. See the `LICENSE` file for more details.