|
5 | 5 | from importlib import import_module
|
6 | 6 | from io import StringIO
|
7 | 7 | from pathlib import Path
|
8 |
| -from typing import Dict, List, Optional, Tuple, Type, Union |
| 8 | +from typing import Dict, List, Optional, Tuple, Type |
9 | 9 |
|
10 | 10 | import click
|
11 |
| -from packaging import version |
12 |
| -from packaging.version import LegacyVersion, Version |
13 | 11 | from tortoise import (
|
14 | 12 | BackwardFKRelation,
|
15 | 13 | BackwardOneToOneRelation,
|
@@ -45,7 +43,7 @@ class Migrate:
|
45 | 43 | app: str
|
46 | 44 | migrate_location: str
|
47 | 45 | dialect: str
|
48 |
| - _db_version: Union[LegacyVersion, Version] = None |
| 46 | + _db_version: Optional[str] = None |
49 | 47 |
|
50 | 48 | @classmethod
|
51 | 49 | def get_old_model_file(cls, app: str, location: str):
|
@@ -77,7 +75,7 @@ async def _get_db_version(cls, connection: BaseDBAsyncClient):
|
77 | 75 | if cls.dialect == "mysql":
|
78 | 76 | sql = "select version() as version"
|
79 | 77 | ret = await connection.execute_query(sql)
|
80 |
| - cls._db_version = version.parse(ret[1][0].get("version")) |
| 78 | + cls._db_version = ret[1][0].get("version") |
81 | 79 |
|
82 | 80 | @classmethod
|
83 | 81 | async def init_with_old_models(cls, config: dict, app: str, location: str):
|
@@ -315,7 +313,7 @@ def diff_model(cls, old_model: Type[Model], new_model: Type[Model], upgrade=True
|
315 | 313 | if (
|
316 | 314 | cls.dialect == "mysql"
|
317 | 315 | and cls._db_version
|
318 |
| - and cls._db_version.major == 5 |
| 316 | + and cls._db_version.startswith("5.") |
319 | 317 | ):
|
320 | 318 | cls._add_operator(
|
321 | 319 | cls._change_field(new_model, old_field, new_field),
|
|
0 commit comments