Fix packaging error. (#92)
This commit is contained in:
		| @@ -6,6 +6,7 @@ | |||||||
|  |  | ||||||
| - Use `pathlib` for path resolving. (#89) | - Use `pathlib` for path resolving. (#89) | ||||||
| - Fix upgrade in new db. (#96) | - Fix upgrade in new db. (#96) | ||||||
|  | - Fix packaging error. (#92) | ||||||
|  |  | ||||||
| ### 0.4.1 | ### 0.4.1 | ||||||
|  |  | ||||||
|   | |||||||
| @@ -5,11 +5,9 @@ from datetime import datetime | |||||||
| from importlib import import_module | from importlib import import_module | ||||||
| from io import StringIO | from io import StringIO | ||||||
| from pathlib import Path | from pathlib import Path | ||||||
| from typing import Dict, List, Optional, Tuple, Type, Union | from typing import Dict, List, Optional, Tuple, Type | ||||||
|  |  | ||||||
| import click | import click | ||||||
| from packaging import version |  | ||||||
| from packaging.version import LegacyVersion, Version |  | ||||||
| from tortoise import ( | from tortoise import ( | ||||||
|     BackwardFKRelation, |     BackwardFKRelation, | ||||||
|     BackwardOneToOneRelation, |     BackwardOneToOneRelation, | ||||||
| @@ -45,7 +43,7 @@ class Migrate: | |||||||
|     app: str |     app: str | ||||||
|     migrate_location: str |     migrate_location: str | ||||||
|     dialect: str |     dialect: str | ||||||
|     _db_version: Union[LegacyVersion, Version] = None |     _db_version: Optional[str] = None | ||||||
|  |  | ||||||
|     @classmethod |     @classmethod | ||||||
|     def get_old_model_file(cls, app: str, location: str): |     def get_old_model_file(cls, app: str, location: str): | ||||||
| @@ -77,7 +75,7 @@ class Migrate: | |||||||
|         if cls.dialect == "mysql": |         if cls.dialect == "mysql": | ||||||
|             sql = "select version() as version" |             sql = "select version() as version" | ||||||
|             ret = await connection.execute_query(sql) |             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 |     @classmethod | ||||||
|     async def init_with_old_models(cls, config: dict, app: str, location: str): |     async def init_with_old_models(cls, config: dict, app: str, location: str): | ||||||
| @@ -315,7 +313,7 @@ class Migrate: | |||||||
|                             if ( |                             if ( | ||||||
|                                 cls.dialect == "mysql" |                                 cls.dialect == "mysql" | ||||||
|                                 and cls._db_version |                                 and cls._db_version | ||||||
|                                 and cls._db_version.major == 5 |                                 and cls._db_version.startswith("5.") | ||||||
|                             ): |                             ): | ||||||
|                                 cls._add_operator( |                                 cls._add_operator( | ||||||
|                                     cls._change_field(new_model, old_field, new_field), |                                     cls._change_field(new_model, old_field, new_field), | ||||||
|   | |||||||
| @@ -5,14 +5,20 @@ from click import BadOptionUsage, Context | |||||||
| from tortoise import BaseDBAsyncClient, Tortoise | 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 |     get connection name | ||||||
|     :param config: |     :param config: | ||||||
|     :param app: |     :param app_name: | ||||||
|     :return: |     :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: | def get_app_connection(config, app) -> BaseDBAsyncClient: | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user