Skip to content

Commit

Permalink
Fix packaging error. (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
long2ice committed Dec 2, 2020
1 parent ee6cc20 commit d2e0a68
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- Use `pathlib` for path resolving. (#89)
- Fix upgrade in new db. (#96)
- Fix packaging error. (#92)

### 0.4.1

Expand Down
10 changes: 4 additions & 6 deletions aerich/migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
from importlib import import_module
from io import StringIO
from pathlib import Path
from typing import Dict, List, Optional, Tuple, Type, Union
from typing import Dict, List, Optional, Tuple, Type

import click
from packaging import version
from packaging.version import LegacyVersion, Version
from tortoise import (
BackwardFKRelation,
BackwardOneToOneRelation,
Expand Down Expand Up @@ -45,7 +43,7 @@ class Migrate:
app: str
migrate_location: str
dialect: str
_db_version: Union[LegacyVersion, Version] = None
_db_version: Optional[str] = None

@classmethod
def get_old_model_file(cls, app: str, location: str):
Expand Down Expand Up @@ -77,7 +75,7 @@ async def _get_db_version(cls, connection: BaseDBAsyncClient):
if cls.dialect == "mysql":
sql = "select version() as version"
ret = await connection.execute_query(sql)
cls._db_version = version.parse(ret[1][0].get("version"))
cls._db_version = ret[1][0].get("version")

@classmethod
async def init_with_old_models(cls, config: dict, app: str, location: str):
Expand Down Expand Up @@ -315,7 +313,7 @@ def diff_model(cls, old_model: Type[Model], new_model: Type[Model], upgrade=True
if (
cls.dialect == "mysql"
and cls._db_version
and cls._db_version.major == 5
and cls._db_version.startswith("5.")
):
cls._add_operator(
cls._change_field(new_model, old_field, new_field),
Expand Down
12 changes: 9 additions & 3 deletions aerich/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@
from tortoise import BaseDBAsyncClient, Tortoise


def get_app_connection_name(config, app) -> str:
def get_app_connection_name(config, app_name: str) -> str:
"""
get connection name
:param config:
:param app:
:param app_name:
:return:
"""
return config.get("apps").get(app).get("default_connection", "default")
app = config.get("apps").get(app_name)
if app:
return app.get("default_connection", "default")
raise BadOptionUsage(
option_name="--app",
message=f'Can\'t get app named "{app_name}"',
)


def get_app_connection(config, app) -> BaseDBAsyncClient:
Expand Down

0 comments on commit d2e0a68

Please sign in to comment.