Fixed two problems when using under windows (#286)

* fix: Fixed an issue where an error would occur when using aerich in windows if the profile contained Chinese characters

* fix: Automatically delete the empty migration directory of the app if the init-db operation fails

* feat: generate migration file in empty directory instead of abort with warning

* tests: fix test fail in ci

---------

Co-authored-by: Waket Zheng <waketzheng@gmail.com>
This commit is contained in:
Tuffy_
2024-12-10 23:02:49 +08:00
committed by GitHub
parent 9c81bc6036
commit accceef24f
3 changed files with 26 additions and 6 deletions

View File

@@ -133,7 +133,12 @@ class Command:
location = self.location
app = self.app
dirname = Path(location, app)
dirname.mkdir(parents=True)
if not dirname.exists():
dirname.mkdir(parents=True)
else:
# If directory is empty, go ahead, otherwise raise FileExistsError
for unexpected_file in dirname.glob("*"):
raise FileExistsError(str(unexpected_file))
await Tortoise.init(config=self.tortoise_config)
connection = get_app_connection(self.tortoise_config, app)

View File

@@ -40,7 +40,7 @@ async def cli(ctx: Context, config, app) -> None:
raise UsageError(
"You need to run `aerich init` first to create the config file.", ctx=ctx
)
content = config_path.read_text()
content = config_path.read_text("utf-8")
doc: dict = tomlkit.parse(content)
try:
tool = cast(Dict[str, str], doc["tool"]["aerich"])