Fix upgrade error when migrate
This commit is contained in:
parent
ce75e55d60
commit
40c0008e6e
@ -4,6 +4,10 @@ ChangeLog
|
|||||||
|
|
||||||
0.1
|
0.1
|
||||||
===
|
===
|
||||||
|
0.1.8
|
||||||
|
_____
|
||||||
|
- Fix upgrade error when migrate.
|
||||||
|
|
||||||
0.1.7
|
0.1.7
|
||||||
-----
|
-----
|
||||||
- Exclude models.Aerich.
|
- Exclude models.Aerich.
|
||||||
|
@ -1 +1 @@
|
|||||||
__version__ = "0.1.7"
|
__version__ = "0.1.8"
|
||||||
|
@ -7,6 +7,7 @@ from enum import Enum
|
|||||||
import asyncclick as click
|
import asyncclick as click
|
||||||
from asyncclick import Context, UsageError
|
from asyncclick import Context, UsageError
|
||||||
from tortoise import Tortoise, generate_schema_for_client
|
from tortoise import Tortoise, generate_schema_for_client
|
||||||
|
from tortoise.exceptions import OperationalError
|
||||||
from tortoise.transactions import in_transaction
|
from tortoise.transactions import in_transaction
|
||||||
from tortoise.utils import get_schema_sql
|
from tortoise.utils import get_schema_sql
|
||||||
|
|
||||||
@ -86,7 +87,11 @@ async def upgrade(ctx: Context):
|
|||||||
app = ctx.obj["app"]
|
app = ctx.obj["app"]
|
||||||
migrated = False
|
migrated = False
|
||||||
for version in Migrate.get_all_version_files():
|
for version in Migrate.get_all_version_files():
|
||||||
if not await Aerich.exists(version=version, app=app):
|
try:
|
||||||
|
exists = await Aerich.exists(version=version, app=app)
|
||||||
|
except OperationalError:
|
||||||
|
exists = False
|
||||||
|
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") as f:
|
||||||
@ -159,7 +164,7 @@ def history(ctx):
|
|||||||
)
|
)
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
async def init(
|
async def init(
|
||||||
ctx: Context, tortoise_orm, location,
|
ctx: Context, tortoise_orm, location,
|
||||||
):
|
):
|
||||||
config_file = ctx.obj["config_file"]
|
config_file = ctx.obj["config_file"]
|
||||||
name = ctx.obj["name"]
|
name = ctx.obj["name"]
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "aerich"
|
name = "aerich"
|
||||||
version = "0.1.7"
|
version = "0.1.8"
|
||||||
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>"]
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user