Merge pull request #345 from waketzheng/dev

Drop python3.7 support
This commit is contained in:
long2ice 2024-06-06 15:49:31 +08:00 committed by GitHub
commit f3b6f8f264
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 505 additions and 633 deletions

View File

@ -20,7 +20,7 @@ style: deps
check: deps
@black --check $(black_opts) $(checkfiles) || (echo "Please run 'make style' to auto-fix style issues" && false)
@ruff $(checkfiles)
@ruff check $(checkfiles)
test: deps
$(py_warn) TEST_DB=sqlite://:memory: py.test

View File

@ -66,11 +66,11 @@ class BaseDDL:
forward_type=db_field_types.get(self.DIALECT) or db_field_types.get(""),
on_delete=field_describe.get("on_delete"),
extra=self.schema_generator._table_generate_extra(table=through),
comment=self.schema_generator._table_comment_generator(
table=through, comment=description
)
if description
else "",
comment=(
self.schema_generator._table_comment_generator(table=through, comment=description)
if description
else ""
),
)
def drop_m2m(self, table_name: str):
@ -121,13 +121,15 @@ class BaseDDL:
field_type=db_field_types.get(self.DIALECT, db_field_types.get("")),
nullable="NOT NULL" if not field_describe.get("nullable") else "",
unique="UNIQUE" if field_describe.get("unique") else "",
comment=self.schema_generator._column_comment_generator(
table=db_table,
column=db_column,
comment=field_describe.get("description"),
)
if description
else "",
comment=(
self.schema_generator._column_comment_generator(
table=db_table,
column=db_column,
comment=field_describe.get("description"),
)
if description
else ""
),
is_primary_key=is_pk,
default=default,
),
@ -151,13 +153,15 @@ class BaseDDL:
field_type=db_field_types.get(self.DIALECT) or db_field_types.get(""),
nullable="NOT NULL" if not field_describe.get("nullable") else "",
unique="",
comment=self.schema_generator._column_comment_generator(
table=db_table,
column=field_describe.get("db_column"),
comment=field_describe.get("description"),
)
if field_describe.get("description")
else "",
comment=(
self.schema_generator._column_comment_generator(
table=db_table,
column=field_describe.get("db_column"),
comment=field_describe.get("description"),
)
if field_describe.get("description")
else ""
),
is_primary_key=is_pk,
default=default,
),

View File

@ -43,7 +43,9 @@ class PostgresDDL(BaseDDL):
return self._SET_COMMENT_TEMPLATE.format(
table_name=db_table,
column=field_describe.get("db_column") or field_describe.get("raw_field"),
comment="'{}'".format(field_describe.get("description"))
if field_describe.get("description")
else "NULL",
comment=(
"'{}'".format(field_describe.get("description"))
if field_describe.get("description")
else "NULL"
),
)

1051
poetry.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -15,30 +15,34 @@ packages = [
include = ["CHANGELOG.md", "LICENSE", "README.md"]
[tool.poetry.dependencies]
python = "^3.7"
python = "^3.8"
tortoise-orm = "*"
click = "*"
asyncpg = { version = "*", optional = true }
asyncmy = { version = "^0.2.8rc1", optional = true, allow-prereleases = true }
asyncmy = { version = "^0.2.9", optional = true, allow-prereleases = true }
pydantic = "^2.0"
dictdiffer = "*"
tomlkit = "*"
[tool.poetry.dev-dependencies]
[tool.poetry.group.dev.dependencies]
ruff = "*"
isort = "*"
black = "*"
pytest = "*"
pytest-xdist = "*"
pytest-asyncio = "*"
# Breaking change in 0.23.*
# https://github.com/pytest-dev/pytest-asyncio/issues/706
pytest-asyncio = "^0.21.2"
bandit = "*"
pytest-mock = "*"
cryptography = "*"
mypy = "^1.10.0"
[tool.poetry.extras]
asyncmy = ["asyncmy"]
asyncpg = ["asyncpg"]
[tool.aerich]
tortoise_orm = "conftest.tortoise_orm"
location = "./migrations"
@ -53,7 +57,7 @@ aerich = "aerich.cli:main"
[tool.black]
line-length = 100
target-version = ['py36', 'py37', 'py38', 'py39']
target-version = ['py38', 'py39', 'py310', 'py311', 'py312']
[tool.pytest.ini_options]
asyncio_mode = 'auto'
@ -62,5 +66,5 @@ asyncio_mode = 'auto'
pretty = true
ignore_missing_imports = true
[tool.ruff]
[tool.ruff.lint]
ignore = ['E501']

View File

@ -2,6 +2,7 @@ import tempfile
from pathlib import Path
import pytest
import tortoise
from pytest_mock import MockerFixture
from aerich.ddl.mysql import MysqlDDL
@ -791,6 +792,16 @@ old_models_describe = {
}
def should_add_user_id_column_type_alter_sql() -> bool:
# tortoise-orm>=0.21 changes IntField constraints
# from {"ge": 1, "le": 2147483647} to {"ge": -2147483648,"le": 2147483647}
user_id_constraints = old_models_describe["models.Category"]["data_fields"][-1]["constraints"]
return (
tortoise.__version__ >= "0.21"
and tortoise.fields.data.IntField.constraints != user_id_constraints
)
def test_migrate(mocker: MockerFixture):
"""
models.py diff with old_models.py
@ -887,6 +898,10 @@ def test_migrate(mocker: MockerFixture):
"ALTER TABLE `product` MODIFY COLUMN `body` LONGTEXT NOT NULL",
"ALTER TABLE `email` MODIFY COLUMN `is_primary` BOOL NOT NULL DEFAULT 0",
}
if should_add_user_id_column_type_alter_sql():
sql = "ALTER TABLE `category` MODIFY COLUMN `user_id` INT NOT NULL COMMENT 'User'"
expected_upgrade_operators.add(sql)
expected_downgrade_operators.add(sql)
assert not set(Migrate.upgrade_operators).symmetric_difference(expected_upgrade_operators)
assert not set(Migrate.downgrade_operators).symmetric_difference(
@ -960,6 +975,10 @@ def test_migrate(mocker: MockerFixture):
'DROP TABLE IF EXISTS "email_user"',
'DROP TABLE IF EXISTS "newmodel"',
}
if should_add_user_id_column_type_alter_sql():
sql = 'ALTER TABLE "category" ALTER COLUMN "user_id" TYPE INT USING "user_id"::INT'
expected_upgrade_operators.add(sql)
expected_downgrade_operators.add(sql)
assert not set(Migrate.upgrade_operators).symmetric_difference(expected_upgrade_operators)
assert not set(Migrate.downgrade_operators).symmetric_difference(
expected_downgrade_operators