7 Commits

Author SHA1 Message Date
long2ice
cd176c1fd6 Merge pull request #111 from lqmanh/bugfixes/fix-tortoise-orm-0.16.19
Fix Aerich b/c of a new feature in Tortoise ORM v0.16.19
2021-01-04 14:59:11 +08:00
long2ice
c2819fc8dc update CHANGELOG.md 2020-12-29 19:13:37 +08:00
long2ice
530e7cfce5 Fixed unnecessary import. (#113) 2020-12-29 19:12:36 +08:00
Lương Quang Mạnh
47824a100b Fix Aerich b/c of Tortoise ORM v0.16.19 2020-12-26 10:31:10 +07:00
long2ice
78a15f9f19 Merge pull request #108 from lqmanh/features/make-parent-dirs-as-needed
Make parent directories as needed
2020-12-25 22:10:56 +08:00
Lương Quang Mạnh
e0d52b1210 Fix make style 2020-12-21 15:36:29 +07:00
Lương Quang Mạnh
4dc45f723a Make parent directories as needed 2020-12-21 15:13:26 +07:00
6 changed files with 16 additions and 10 deletions

View File

@@ -2,6 +2,10 @@
## 0.4 ## 0.4
### 0.4.4
- Fix unnecessary import. (#113)
### 0.4.3 ### 0.4.3
- Replace migrations separator to sql standard comment. - Replace migrations separator to sql standard comment.

View File

@@ -1 +1 @@
__version__ = "0.4.3" __version__ = "0.4.4"

View File

@@ -240,8 +240,7 @@ async def init(
with open(config_file, "w", encoding="utf-8") as f: with open(config_file, "w", encoding="utf-8") as f:
parser.write(f) parser.write(f)
if not Path(location).is_dir(): Path(location).mkdir(parents=True, exist_ok=True)
os.mkdir(location)
click.secho(f"Success create migrate location {location}", fg=Color.green) click.secho(f"Success create migrate location {location}", fg=Color.green)
click.secho(f"Success generate config file {config_file}", fg=Color.green) click.secho(f"Success generate config file {config_file}", fg=Color.green)
@@ -263,10 +262,10 @@ async def init_db(ctx: Context, safe):
app = ctx.obj["app"] app = ctx.obj["app"]
dirname = Path(location, app) dirname = Path(location, app)
if not dirname.is_dir(): try:
os.mkdir(dirname) dirname.mkdir(parents=True)
click.secho(f"Success create app migrate location {dirname}", fg=Color.green) click.secho(f"Success create app migrate location {dirname}", fg=Color.green)
else: except FileExistsError:
return click.secho( return click.secho(
f"Inited {app} already, or delete {dirname} and try again.", fg=Color.yellow f"Inited {app} already, or delete {dirname} and try again.", fg=Color.yellow
) )

View File

@@ -3,7 +3,6 @@ from typing import List, Optional
from ddlparse import DdlParse from ddlparse import DdlParse
from tortoise import BaseDBAsyncClient from tortoise import BaseDBAsyncClient
from tortoise.backends.mysql.client import MySQLSchemaGenerator
class InspectDb: class InspectDb:
@@ -24,7 +23,7 @@ class InspectDb:
self.DIALECT = conn.schema_generator.DIALECT self.DIALECT = conn.schema_generator.DIALECT
async def show_create_tables(self): async def show_create_tables(self):
if self.DIALECT == MySQLSchemaGenerator.DIALECT: if self.DIALECT == "mysql":
if not self.tables: if not self.tables:
sql_tables = f"SELECT table_name FROM information_schema.tables WHERE table_schema = '{self.conn.database}';" # nosec: B608 sql_tables = f"SELECT table_name FROM information_schema.tables WHERE table_schema = '{self.conn.database}';" # nosec: B608
ret = await self.conn.execute_query(sql_tables) ret = await self.conn.execute_query(sql_tables)

View File

@@ -5,6 +5,7 @@ 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 types import ModuleType
from typing import Dict, List, Optional, Tuple, Type from typing import Dict, List, Optional, Tuple, Type
import click import click
@@ -210,7 +211,10 @@ class Migrate:
old_model_files = [] old_model_files = []
models = config.get("apps").get(app).get("models") models = config.get("apps").get(app).get("models")
for model in models: for model in models:
module = import_module(model) if isinstance(model, ModuleType):
module = model
else:
module = import_module(model)
possible_models = [getattr(module, attr_name) for attr_name in dir(module)] possible_models = [getattr(module, attr_name) for attr_name in dir(module)]
for attr in filter( for attr in filter(
lambda x: inspect.isclass(x) and issubclass(x, Model) and x is not Model, lambda x: inspect.isclass(x) and issubclass(x, Model) and x is not Model,

View File

@@ -1,6 +1,6 @@
[tool.poetry] [tool.poetry]
name = "aerich" name = "aerich"
version = "0.4.3" version = "0.4.4"
description = "A database migrations tool for Tortoise ORM." description = "A database migrations tool for Tortoise ORM."
authors = ["long2ice <long2ice@gmail.com>"] authors = ["long2ice <long2ice@gmail.com>"]
license = "Apache-2.0" license = "Apache-2.0"