A schema migration tool for Tortoise ORM
Project description
Tortoise Pathway
⚠️ This project is in development and some things might break. ⚠️ Only Postgres and Sqlite are supported for now.
🤓 Code contributions and assistance with testing are welcome and appreciated!
Tortoise Pathway is a migration system for Tortoise ORM, inspired by Django's migration approach.
See CHANGELOG.md for the latest changes.
Features
- Generate schema migrations from Tortoise models
- Apply and revert migrations
- No need for a database connection to generate migrations
- If you have used Django migrations, you will feel at home
Installation
You can install the package using pip:
pip install tortoise-pathway
Or if you prefer using uv:
uv add tortoise-pathway
Development
Running tests:
uv run pytest
Usage
Configuration
Create a configuration module with a TORTOISE_ORM dictionary. For example, in config.py:
TORTOISE_ORM = {
"connections": {
"default": {
"engine": "tortoise.backends.sqlite",
"credentials": {
"file_path": "db.sqlite3",
},
},
},
"apps": {
"models": {
"models": ["myapp.models"],
"default_connection": "default",
},
},
}
Defining Models
Define your Tortoise ORM models as usual:
# myapp/models.py
from tortoise import fields, models
class User(models.Model):
id = fields.IntField(primary_key=True)
name = fields.CharField(max_length=255)
email = fields.CharField(max_length=255, unique=True)
created_at = fields.DatetimeField(auto_now_add=True)
Working with Migrations
Generate migrations automatically based on model changes:
python -m tortoise_pathway --config myapp.config.TORTOISE_ORM make
or generate an empty migration with a name:
python -m tortoise_pathway --config myapp.config.TORTOISE_ORM make --empty --name "add_email_field"
Apply migrations:
python -m tortoise_pathway --config myapp.config.TORTOISE_ORM migrate
Revert a migration:
python -m tortoise_pathway --config myapp.config.TORTOISE_ORM rollback --migration <migration_name>
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tortoise_pathway-0.2.1.tar.gz.
File metadata
- Download URL: tortoise_pathway-0.2.1.tar.gz
- Upload date:
- Size: 35.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.21
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f3c8fa548975c19a4d6157f0dc5372782afa9970c37e0f9c03f5ecf7bc638f75
|
|
| MD5 |
93889f522596dc842176afd86a713a49
|
|
| BLAKE2b-256 |
367d0a711d838237bdb7411bdac605611c9632b2fa0cd9d8f9881d45628ba8fb
|
File details
Details for the file tortoise_pathway-0.2.1-py3-none-any.whl.
File metadata
- Download URL: tortoise_pathway-0.2.1-py3-none-any.whl
- Upload date:
- Size: 42.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.21
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3408e4b07f3e8c53d6982f2a0425f87b1d60d7b759e6ea70745d7ddb67a93327
|
|
| MD5 |
f20e62478e45b9baca43b440fca0828e
|
|
| BLAKE2b-256 |
09bbaef9192a2b1eb2d048e0950527c68d6593286dbb5815ca38723a5b6a33af
|