Skip to content

Commit d1e60de

Browse files
committed
Merge branch 'develop' of github.com:tortoise/tortoise-orm into replace-pytz
2 parents cc77a36 + fa94d12 commit d1e60de

File tree

173 files changed

+15606
-3874
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

173 files changed

+15606
-3874
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
TORTOISE_MSSQL_DRIVER: ODBC Driver 18 for SQL Server
4646
strategy:
4747
matrix:
48-
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]
48+
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
4949
steps:
5050
- uses: actions/cache@v5
5151
with:
@@ -77,6 +77,11 @@ jobs:
7777
DEST_SANIC: examples/sanic
7878
PYTHONDEVMODE: 1
7979
PYTEST_ARGS: "-n auto --cov=tortoise --cov-append --cov-branch --tb=native -q"
80+
- name: Test No typing-extensions
81+
if: matrix.python-version == 'py3.11'
82+
run: |
83+
uv pip uninstall typing-extensions
84+
uv run --no-sync python examples/basic.py
8085
- name: Upload Coverage
8186
run: |
8287
uvx coveralls --service=github

.github/workflows/gh-pages-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
- uses: actions/checkout@v6
1111
- uses: actions/setup-python@v6
1212
with:
13-
python-version: "3.9"
13+
python-version: "3.10"
1414
- uses: astral-sh/setup-uv@v7
1515
- name: Build docs
1616
run: make docs

.github/workflows/gh-pages.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
- uses: actions/checkout@v6
1212
- uses: actions/setup-python@v6
1313
with:
14-
python-version: "3.9"
14+
python-version: "3.10"
1515
- uses: astral-sh/setup-uv@v7
1616
- name: Build docs
1717
run: make docs

.github/workflows/pypi.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
- uses: actions/checkout@v6
1111
- uses: actions/setup-python@v6
1212
with:
13-
python-version: '3.9'
13+
python-version: '3.10'
1414
- uses: astral-sh/setup-uv@v7
1515
- name: Build dists
1616
run: make build

CHANGELOG.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ Changelog
1212

1313
0.26.0 (unreleased)
1414
-------------------
15+
Fixed
16+
^^^^^
17+
- Fix ``AttributeError`` when using ``tortoise-orm`` with Nuitka-compiled Python code (#2053)
18+
- Fix 'Self' in python standard library typing.py, but tortoise/model.py required it in 'typing_extensions' (#2051)
19+
- Fix annotations being selected in ValuesListQuery despite not specified in `.values_list` fields list (#2059)
20+
21+
Changed
22+
^^^^^
23+
- feat: foreignkey to model type (#2027)
1524

1625
0.25
1726
====

CONTRIBUTORS.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ Contributors
6666
* Frederic Aoustin ``@fraoustin``
6767
* Ludwig Hähne ``@pankrat``
6868
* Christian Tanul ``@scriptogre``
69+
* Qian Chen ``@shkey``
6970

7071
Special Thanks
7172
==============

README.rst

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ Tortoise ORM
1212
:target: https://github.com/tortoise/tortoise-orm/actions?query=workflow:ci
1313
.. image:: https://coveralls.io/repos/github/tortoise/tortoise-orm/badge.svg
1414
:target: https://coveralls.io/github/tortoise/tortoise-orm
15-
.. image:: https://app.codacy.com/project/badge/Grade/844030d0cb8240d6af92c71bfac764ff
16-
:target: https://www.codacy.com/gh/tortoise/tortoise-orm/dashboard?utm_source=github.com&utm_medium=referral&utm_content=tortoise/tortoise-orm&utm_campaign=Badge_Grade
1715

1816
Introduction
1917
============
@@ -26,7 +24,7 @@ You can find the docs at `Documentation <https://tortoise.github.io>`_
2624
Tortoise ORM is a young project and breaking changes are to be expected.
2725
We keep a `Changelog <https://tortoise.github.io/CHANGELOG.html>`_ and it will have possible breakage clearly documented.
2826

29-
Tortoise ORM supports CPython 3.9 and later for SQLite, MySQL, PostgreSQL, Microsoft SQL Server, and Oracle.
27+
Tortoise ORM supports CPython 3.10 and later for SQLite, MySQL, PostgreSQL, Microsoft SQL Server, and Oracle.
3028

3129
Why was Tortoise ORM built?
3230
---------------------------
@@ -108,7 +106,8 @@ Define the models by inheriting from ``tortoise.models.Model``.
108106
109107
After defining the models, Tortoise ORM needs to be initialized to establish the relationships between models and connect to the database.
110108
The code below creates a connection to a SQLite DB database with the ``aiosqlite`` client. ``generate_schema`` sets up schema on an empty database.
111-
``generate_schema`` is for development purposes only, check out ``aerich`` or other migration tools for production use.
109+
``generate_schema`` is for development purposes only; use the built-in
110+
migrations for production use.
112111

113112
.. code-block:: python3
114113
@@ -189,10 +188,12 @@ With the Tortoise initialized, the models are available for use:
189188
Learn more at the `documentation site <https://tortoise.github.io>`_
190189

191190

192-
Migration
193-
=========
191+
Migrations
192+
==========
194193

195-
Tortoise ORM uses `Aerich <https://github.com/tortoise/aerich>`_ as its database migration tool, see more detail at its `docs <https://github.com/tortoise/aerich>`_.
194+
Tortoise ORM ships with built-in migrations and a CLI. See the
195+
`migrations documentation <https://tortoise.github.io/migration.html>`_ for
196+
setup, commands, and examples.
196197

197198
Contributing
198199
============

docs/CONTRIBUTING.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ Tortoise ORM follows a the following agreed upon style:
9393
* Always try to separate out terms clearly rather than concatenate words directly:
9494
* ``some_purpose`` instead of ``somepurpose``
9595
* ``SomePurpose`` instead of ``Somepurpose``
96-
* Keep in mind the targeted Python versions of ``>=3.9``:
96+
* Keep in mind the targeted Python versions of ``>=3.10``:
9797
* Do use f-strings
9898
* Please try and provide type annotations where you can, it will improve auto-completion in editors, and better static analysis.
9999

docs/cli.rst

Lines changed: 96 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,130 @@
11
.. _cli:
22

33
===========
4-
TortoiseCLI
4+
Tortoise CLI
55
===========
66

7-
This document describes how to use `tortoise-cli`, a cli tool for tortoise-orm, build on top of click and ptpython.
7+
This page documents the built-in CLI for schema migrations and interactive use.
88

9-
You can see `https://github.com/tortoise/tortoise-cli <https://github.com/tortoise/tortoise-cli>`_ for more details.
9+
Overview
10+
========
1011

12+
The CLI resolves configuration from ``-c/--config``, ``--config-file``, or
13+
``[tool.tortoise]`` in ``pyproject.toml``. Migration commands mirror the
14+
runtime API while adding plan/history output.
1115

12-
Quick Start
16+
Basic usage
1317
===========
1418

1519
.. code-block:: shell
1620
17-
> tortoise-cli -h 23:59:38
18-
Usage: tortoise-cli [OPTIONS] COMMAND [ARGS]...
21+
tortoise -h
22+
tortoise -c settings.TORTOISE_ORM init
23+
tortoise makemigrations
24+
tortoise migrate
1925
20-
Options:
21-
-V, --version Show the version and exit.
22-
-c, --config TEXT TortoiseORM config dictionary path, like settings.TORTOISE_ORM
23-
-h, --help Show this message and exit.
26+
Configuration resolution
27+
========================
2428

25-
Commands:
26-
shell Start an interactive shell.
29+
You can supply configuration in one of these ways:
2730

28-
Usage
29-
=====
31+
- ``-c/--config`` with a dotted path to a config object
32+
(for example ``settings.TORTOISE_ORM``).
33+
- ``--config-file`` with a JSON/YAML config file path.
34+
- ``pyproject.toml`` with ``[tool.tortoise]`` and a ``tortoise_orm`` key.
3035

31-
First, you need make a TortoiseORM config object, assuming that in `settings.py`.
36+
Commands
37+
========
38+
39+
init
40+
----
41+
42+
Create migrations packages for configured apps. This ensures each app has a
43+
``migrations`` module and the package is importable.
44+
45+
.. code-block:: shell
46+
47+
tortoise init
48+
tortoise init users billing
49+
50+
makemigrations
51+
--------------
52+
53+
Autodetect model changes and create new migration files.
3254

3355
.. code-block:: shell
3456
35-
TORTOISE_ORM = {
36-
"connections": {
37-
"default": "sqlite://:memory:",
38-
},
39-
"apps": {
40-
"models": {"models": ["examples.models"], "default_connection": "default"},
41-
},
42-
}
57+
tortoise makemigrations
58+
tortoise makemigrations --name add_posts_table
59+
tortoise makemigrations users
60+
tortoise makemigrations --empty users
61+
62+
migrate / upgrade
63+
-----------------
64+
65+
Apply migrations. ``migrate`` can move forward or backward depending on the
66+
target. ``upgrade`` is forward-only and will refuse to roll back.
4367

68+
.. code-block:: shell
69+
70+
tortoise migrate
71+
tortoise migrate users
72+
tortoise migrate users 0002_add_field
73+
tortoise migrate users.0002_add_field
4474
45-
Interactive shell
46-
=================
75+
downgrade
76+
---------
4777

48-
Then you can start an interactive shell for TortoiseORM.
78+
Unapply migrations for a specific app. ``downgrade`` is backward-only and will
79+
refuse to apply forward migrations. If no migration name is provided, it
80+
targets the first migration for that app.
4981

5082
.. code-block:: shell
5183
52-
tortoise-cli -c settings.TORTOISE_ORM shell
84+
tortoise downgrade users
85+
tortoise downgrade users 0001_initial
5386
87+
history
88+
-------
5489

55-
Or you can set config by set environment variable.
90+
List applied migrations from the database.
5691

5792
.. code-block:: shell
5893
59-
export TORTOISE_ORM=settings.TORTOISE_ORM
94+
tortoise history
95+
tortoise history users
96+
97+
heads
98+
-----
99+
100+
List migration heads on disk.
101+
102+
.. code-block:: shell
103+
104+
tortoise heads
105+
tortoise heads users
106+
107+
shell
108+
-----
109+
110+
Start an interactive shell with Tortoise initialized.
111+
112+
.. code-block:: shell
113+
114+
tortoise shell
115+
116+
Target shorthand
117+
================
118+
119+
The migration commands accept Django-style targets:
60120

61-
Then just run:
121+
- ``APP_LABEL`` means "latest" for that app.
122+
- ``APP_LABEL MIGRATION`` targets a specific migration name.
123+
- ``APP_LABEL.MIGRATION`` is equivalent to ``APP_LABEL MIGRATION`` and is
124+
convenient for copy/paste from history output.
62125

63126
.. code-block:: shell
64127
65-
tortoise-cli shell
128+
tortoise migrate users.__latest__
129+
tortoise migrate users 0003_add_index
130+
tortoise downgrade users.__first__

docs/conf.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
#
32
# Configuration file for the Sphinx documentation builder.
43
#
@@ -182,10 +181,10 @@ def get_version_info():
182181

183182
# The name for this set of Sphinx documents. If None, it defaults to
184183
# "<project> v<release> documentation".
185-
html_title = "%s v%s Documentation" % (project, release)
184+
html_title = f"{project} v{release} Documentation"
186185

187186
# A shorter title for the navigation bar. Default is the same as html_title.
188-
html_short_title = "%s %s Documentation" % (project, version)
187+
html_short_title = f"{project} {version} Documentation"
189188

190189
# The name of an image file (relative to this directory) to place at the top
191190
# of the sidebar.

0 commit comments

Comments
 (0)