Skip to main content

A schema migration tool for Tortoise ORM

Project description

Tortoise Pathway

⚠️ This project is in VERY early development and not yet ready for production use. Most things are broken and they will break again, APIs will change.

⚠️ Most of the code is written with Claude, there are issues with code style that are common for AI generated code.

🤓 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

tortoise_pathway-0.2.0.tar.gz (35.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tortoise_pathway-0.2.0-py3-none-any.whl (42.3 kB view details)

Uploaded Python 3

File details

Details for the file tortoise_pathway-0.2.0.tar.gz.

File metadata

  • Download URL: tortoise_pathway-0.2.0.tar.gz
  • Upload date:
  • Size: 35.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.18

File hashes

Hashes for tortoise_pathway-0.2.0.tar.gz
Algorithm Hash digest
SHA256 0c8e0afc8021ddf6e882699d9be3ba62a334d756c6a135b59f6a448edbe58bda
MD5 cf3743fdab7a21f34872002998fee97a
BLAKE2b-256 1c9a62965b352dd7e323a111a6c48ec55e4b348adc528429d9ba27763ef717ff

See more details on using hashes here.

File details

Details for the file tortoise_pathway-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for tortoise_pathway-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fd390e6ef705f4d9fce89e600758b33894df5a318aad6488f70ac55374c061c1
MD5 53dd22064cf7e3605043251874036d4b
BLAKE2b-256 ca5eedbb3a73826d7eedc202dc3ca07323b82c0763852c01cf8c23d56d08525d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page