{"id":6407,"library":"peewee-migrate","title":"Peewee Migrate","description":"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.","status":"active","version":"1.15.0","language":"en","source_language":"en","source_url":"https://github.com/klen/peewee_migrate","tags":["peewee","orm","database","migrations"],"install":[{"cmd":"pip install peewee-migrate","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Core ORM that peewee-migrate extends for database migrations.","package":"peewee","optional":false}],"imports":[{"symbol":"Router","correct":"from peewee_migrate import Router"}],"quickstart":{"code":"import os\nfrom peewee import *\nfrom peewee_migrate import Router\n\n# 1. Initialize a Peewee database instance\ndb = SqliteDatabase('example.db')\n\n# 2. Define the directory where your migration files are stored\nmigrations_dir = 'my_migrations'\n\n# Create a dummy migration directory and file for the example to be runnable\nos.makedirs(migrations_dir, exist_ok=True)\nwith open(os.path.join(migrations_dir, '001_initial.py'), 'w') as f:\n    f.write('from peewee import *\\ndef migrate(migrator, database, **kwargs):\\n    pass\\ndef rollback(migrator, database, **kwargs):\\n    pass')\n\n# 3. Initialize the Peewee-Migrate Router\nrouter = Router(db, migrate_dir=migrations_dir)\n\n# 4. Run all pending migrations\n# In a real scenario, you would have migration files in 'my_migrations'\n# defining schema changes.\nprint(\"Running migrations...\")\nrouter.run()\nprint(\"Migrations completed successfully.\")\n\n# Clean up created files/dirs for a repeatable example\nif os.path.exists('example.db'):\n    os.remove('example.db')\nif os.path.exists(migrations_dir):\n    import shutil\n    shutil.rmtree(migrations_dir)","lang":"python","description":"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."},"warnings":[{"fix":"Update `Router(db, '/path/to/migrations')` to `Router(db, migrate_dir='/path/to/migrations')`.","message":"The `Router` constructor signature changed significantly in version 1.0.0. The second positional argument (path to migrations) was removed in favor of a keyword argument `migrate_dir`.","severity":"breaking","affected_versions":">=1.0.0 (breaking change from <1.0.0)"},{"fix":"Ensure migration files are named `NNN_descriptive_name.py` and located in the directory passed via `migrate_dir`.","message":"Migration files must adhere to the `NNN_name.py` naming convention (e.g., `001_create_user_table.py`) and be placed in the `migrate_dir` specified to the `Router` instance. Files not following this format or placed elsewhere will be ignored.","severity":"gotcha","affected_versions":"All versions"},{"fix":"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`.","message":"Rollback functions (`rollback(migrator, database, **kwargs)`) are optional but highly recommended. If a `rollback` function is not provided for a `migrate` operation, that specific migration cannot be reversed using `peewee-migrate`'s rollback command.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z"}