Skip to content

Migration fixes and improvements, add example project with all fields#2076

Merged
abondar merged 15 commits intodevelopfrom
tech/improve-migrations
Feb 7, 2026
Merged

Migration fixes and improvements, add example project with all fields#2076
abondar merged 15 commits intodevelopfrom
tech/improve-migrations

Conversation

@abondar
Copy link
Member

@abondar abondar commented Feb 7, 2026

Improved number of things around migrations and fixed some bugs

Should resolve #2074 #2068 for most part

  • Fixed datetime field migration
  • Added some missing functionality
  • Improved output of CLI
  • Added example with all fields adding/altering/removing
  • Refactored sqlite alter table
  • Added sqlmigrate command

AI summary:
This pull request introduces a comprehensive example project demonstrating Tortoise ORM's migration system, along with significant improvements to the migration documentation. The example covers a realistic ERP schema with multiple migration operations and reversible migrations. The documentation is updated to clarify data migration procedures, including usage of RunPython and RunSQL, atomicity controls, and guidance for irreversible migrations.

Comprehensive example project:

  • Added examples/comprehensive_migrations_project, featuring a realistic ERP schema and 14 reversible migrations covering all field types and operations (CreateModel, AddField, AlterField, RemoveField, RenameField, RunPython, RunSQL, indexes, constraints).
  • Provided configuration file config.py for the example project.
  • Added initial and subsequent migration files, each demonstrating different migration operations and schema evolution: creating models, adding fields, altering types, and removing fields. [1] [2] [3] [4] [5] [6] [7] [8]

Migration documentation enhancements:

  • Expanded docs/migration.rst to explain data migrations, introduce RunPython and RunSQL, provide guidance on choosing between them, and document atomicity controls for migration operations. [1] [2]
  • Added FAQ entry describing how to make migrations irreversible by setting reverse_code=None for RunPython or omitting reverse_sql for RunSQL.
  • Updated migration package overview and public entry points to include RunSQL alongside RunPython and CreateModel.

@codspeed-hq
Copy link

codspeed-hq bot commented Feb 7, 2026

CodSpeed Performance Report

Merging this PR will not alter performance

Comparing tech/improve-migrations (af7542d) with develop (2aa8e0d)

Summary

✅ 16 untouched benchmarks

@coveralls
Copy link

coveralls commented Feb 7, 2026

Pull Request Test Coverage Report for Build 21785189655

Details

  • 268 of 546 (49.08%) changed or added relevant lines in 22 files are covered.
  • 5 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-1.8%) to 82.228%

Changes Missing Coverage Covered Lines Changed/Added Lines %
tortoise/migrations/schema_generator/state.py 18 19 94.74%
tortoise/migrations/schema_editor/mssql.py 4 6 66.67%
tortoise/migrations/schema_editor/mysql.py 2 4 50.0%
tortoise/migrations/writer.py 9 12 75.0%
tortoise/migrations/schema_generator/state_apps.py 44 49 89.8%
tortoise/migrations/schema_editor/base.py 19 28 67.86%
tortoise/migrations/api/sqlmigrate.py 13 33 39.39%
tortoise/migrations/migration.py 16 38 42.11%
tortoise/migrations/executor.py 26 57 45.61%
tortoise/cli/cli.py 30 76 39.47%
Files with Coverage Reduction New Missed Lines %
tortoise/migrations/migration.py 5 64.52%
Totals Coverage Status
Change from base Build 21736468513: -1.8%
Covered Lines: 10156
Relevant Lines: 11882

💛 - Coveralls

@abondar abondar merged commit d63573d into develop Feb 7, 2026
25 checks passed
@abondar abondar deleted the tech/improve-migrations branch February 7, 2026 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New migrations: LookupError: Model state models.Tournament is unknown

2 participants