Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
6be6d55e5b
@ -96,7 +96,7 @@ async def upgrade(ctx: Context):
|
|||||||
if not exists:
|
if not exists:
|
||||||
async with in_transaction(get_app_connection_name(config, app)) as conn:
|
async with in_transaction(get_app_connection_name(config, app)) as conn:
|
||||||
file_path = os.path.join(Migrate.migrate_location, version)
|
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)
|
content = json.load(f)
|
||||||
upgrade_query_list = content.get("upgrade")
|
upgrade_query_list = content.get("upgrade")
|
||||||
for upgrade_query in upgrade_query_list:
|
for upgrade_query in upgrade_query_list:
|
||||||
@ -119,7 +119,7 @@ async def downgrade(ctx: Context):
|
|||||||
file = last_version.version
|
file = last_version.version
|
||||||
async with in_transaction(get_app_connection_name(config, app)) as conn:
|
async with in_transaction(get_app_connection_name(config, app)) as conn:
|
||||||
file_path = os.path.join(Migrate.migrate_location, file)
|
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)
|
content = json.load(f)
|
||||||
downgrade_query_list = content.get("downgrade")
|
downgrade_query_list = content.get("downgrade")
|
||||||
if not downgrade_query_list:
|
if not downgrade_query_list:
|
||||||
@ -177,7 +177,7 @@ async def init(
|
|||||||
parser.set(name, "tortoise_orm", tortoise_orm)
|
parser.set(name, "tortoise_orm", tortoise_orm)
|
||||||
parser.set(name, "location", location)
|
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)
|
parser.write(f)
|
||||||
|
|
||||||
if not os.path.isdir(location):
|
if not os.path.isdir(location):
|
||||||
@ -218,7 +218,7 @@ async def init_db(ctx: Context, safe):
|
|||||||
|
|
||||||
version = await Migrate.generate_version()
|
version = await Migrate.generate_version()
|
||||||
await Aerich.create(version=version, app=app)
|
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 = {
|
content = {
|
||||||
"upgrade": [schema],
|
"upgrade": [schema],
|
||||||
}
|
}
|
||||||
|
@ -96,7 +96,7 @@ class Migrate:
|
|||||||
"upgrade": cls.upgrade_operators,
|
"upgrade": cls.upgrade_operators,
|
||||||
"downgrade": cls.downgrade_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)
|
json.dump(content, f, indent=2, ensure_ascii=False)
|
||||||
return version
|
return version
|
||||||
|
|
||||||
@ -154,11 +154,11 @@ class Migrate:
|
|||||||
"""
|
"""
|
||||||
pattern = rf"(\n)?('|\")({app})(.\w+)('|\")"
|
pattern = rf"(\n)?('|\")({app})(.\w+)('|\")"
|
||||||
for i, model_file in enumerate(model_files):
|
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()
|
content = f.read()
|
||||||
ret = re.sub(pattern, rf"\2{cls.diff_app}\4\5", content)
|
ret = re.sub(pattern, rf"\2{cls.diff_app}\4\5", content)
|
||||||
mode = "w" if i == 0 else "a"
|
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)
|
f.write(ret)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
Loading…
x
Reference in New Issue
Block a user