Peewee-migrate, currently at version 1.15.0, provides robust database migration support for the Peewee ORM. It enables developers to manage schema changes through versioned migrations, offering features like creation, application, and rollback of migrations. The library is actively maintained on GitHub with a regular release cadence, ensuring compatibility and ongoing improvements for Peewee projects.
pip install peewee-migrateVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize the `Router` with a Peewee database and run migrations. It sets up a dummy migration directory and file for the example to be runnable. In a real application, you would create migration files using `router.create()` and then manually define your schema changes within them.
Update `Router(db, '/path/to/migrations')` to `Router(db, migrate_dir='/path/to/migrations')`.
Ensure migration files are named `NNN_descriptive_name.py` and located in the directory passed via `migrate_dir`.
Always implement a corresponding `rollback` function that effectively reverses the changes made by its `migrate` counterpart. For example, `migrator.add_model()` in `migrate` should be paired with `migrator.remove_model()` in `rollback`.
Install the 'peewee' library using pip: `pip install peewee`
Activate your Python virtual environment if you are using one. Alternatively, run the command using Python's module execution: `python -m peewee_migrate <command>`
Ensure your Peewee database instance (e.g., `SqliteDatabase`, `PostgresqlDatabase`) is explicitly initialized and connected before passing it to `peewee_migrate.Router` or using it in migration scripts. If using a `Proxy` object, call `database_proxy.initialize(actual_database_instance)`.
Ensure the `--auto-source` argument provides a valid, importable Python module path (e.g., `my_app.models`) and that the directory containing this module is correctly in your `PYTHONPATH` or that you are running `pw_migrate` from the project's root directory.