updata:File operations use utf8 encoding
This commit is contained in:
parent
6fd0f8a42f
commit
f5775049dd
@ -96,7 +96,7 @@ async def upgrade(ctx: Context):
|
||||
if not exists:
|
||||
async with in_transaction(get_app_connection_name(config, app)) as conn:
|
||||
file_path = os.path.join(Migrate.migrate_location, version)
|
||||
with open(file_path, "r") as f:
|
||||
with open(file_path, "r", encoding="utf-8") as f:
|
||||
content = json.load(f)
|
||||
upgrade_query_list = content.get("upgrade")
|
||||
for upgrade_query in upgrade_query_list:
|
||||
@ -119,7 +119,7 @@ async def downgrade(ctx: Context):
|
||||
file = last_version.version
|
||||
async with in_transaction(get_app_connection_name(config, app)) as conn:
|
||||
file_path = os.path.join(Migrate.migrate_location, file)
|
||||
with open(file_path, "r") as f:
|
||||
with open(file_path, "r", encoding="utf-8") as f:
|
||||
content = json.load(f)
|
||||
downgrade_query_list = content.get("downgrade")
|
||||
if not downgrade_query_list:
|
||||
@ -177,7 +177,7 @@ async def init(
|
||||
parser.set(name, "tortoise_orm", tortoise_orm)
|
||||
parser.set(name, "location", location)
|
||||
|
||||
with open(config_file, "w") as f:
|
||||
with open(config_file, "w", encoding="utf-8") as f:
|
||||
parser.write(f)
|
||||
|
||||
if not os.path.isdir(location):
|
||||
@ -218,7 +218,7 @@ async def init_db(ctx: Context, safe):
|
||||
|
||||
version = await Migrate.generate_version()
|
||||
await Aerich.create(version=version, app=app)
|
||||
with open(os.path.join(dirname, version), "w") as f:
|
||||
with open(os.path.join(dirname, version), "w", encoding="utf-8") as f:
|
||||
content = {
|
||||
"upgrade": [schema],
|
||||
}
|
||||
|
@ -96,7 +96,7 @@ class Migrate:
|
||||
"upgrade": cls.upgrade_operators,
|
||||
"downgrade": cls.downgrade_operators,
|
||||
}
|
||||
with open(os.path.join(cls.migrate_location, version), "w") as f:
|
||||
with open(os.path.join(cls.migrate_location, version), "w", encoding="utf-8") as f:
|
||||
json.dump(content, f, indent=2, ensure_ascii=False)
|
||||
return version
|
||||
|
||||
@ -154,11 +154,11 @@ class Migrate:
|
||||
"""
|
||||
pattern = rf"(\n)?('|\")({app})(.\w+)('|\")"
|
||||
for i, model_file in enumerate(model_files):
|
||||
with open(model_file, "r") as f:
|
||||
with open(model_file, "r", encoding="utf-8") as f:
|
||||
content = f.read()
|
||||
ret = re.sub(pattern, rf"\2{cls.diff_app}\4\5", content)
|
||||
mode = "w" if i == 0 else "a"
|
||||
with open(old_model_file, mode) as f:
|
||||
with open(old_model_file, mode, encoding="utf-8") as f:
|
||||
f.write(ret)
|
||||
|
||||
@classmethod
|
||||
|
Loading…
x
Reference in New Issue
Block a user