Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
20aebc4413 | ||
|
|
f8e1f9ff44 | ||
|
|
ab31445fb2 | ||
|
|
28d19a4b7b | ||
|
|
9da99824fe |
10
CHANGELOG.md
10
CHANGELOG.md
@@ -2,6 +2,16 @@
|
|||||||
|
|
||||||
## 0.7
|
## 0.7
|
||||||
|
|
||||||
|
### 0.7.1
|
||||||
|
|
||||||
|
- Fix syntax error with python3.8.10. (#265)
|
||||||
|
- Fix sql generate error. (#263)
|
||||||
|
- Fix initialize an empty database. (#267)
|
||||||
|
|
||||||
|
### 0.7.1rc1
|
||||||
|
|
||||||
|
- Fix postgres sql error (#263)
|
||||||
|
|
||||||
### 0.7.0
|
### 0.7.0
|
||||||
|
|
||||||
**Now aerich use `.py` file to record versions.**
|
**Now aerich use `.py` file to record versions.**
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ class Command:
|
|||||||
file_path = Path(Migrate.migrate_location, version_file)
|
file_path = Path(Migrate.migrate_location, version_file)
|
||||||
m = import_py_file(file_path)
|
m = import_py_file(file_path)
|
||||||
upgrade = getattr(m, "upgrade")
|
upgrade = getattr(m, "upgrade")
|
||||||
await upgrade(conn)
|
await conn.execute_script(await upgrade(conn))
|
||||||
await Aerich.create(
|
await Aerich.create(
|
||||||
version=version_file,
|
version=version_file,
|
||||||
app=self.app,
|
app=self.app,
|
||||||
@@ -80,10 +80,11 @@ class Command:
|
|||||||
) as conn:
|
) as conn:
|
||||||
file_path = Path(Migrate.migrate_location, file)
|
file_path = Path(Migrate.migrate_location, file)
|
||||||
m = import_py_file(file_path)
|
m = import_py_file(file_path)
|
||||||
downgrade = getattr(m, "downgrade", None)
|
downgrade = getattr(m, "downgrade")
|
||||||
if not downgrade:
|
downgrade_sql = await downgrade(conn)
|
||||||
|
if not downgrade_sql.strip():
|
||||||
raise DowngradeError("No downgrade items found")
|
raise DowngradeError("No downgrade items found")
|
||||||
await downgrade(conn)
|
await conn.execute_script(downgrade_sql)
|
||||||
await version.delete()
|
await version.delete()
|
||||||
if delete:
|
if delete:
|
||||||
os.unlink(file_path)
|
os.unlink(file_path)
|
||||||
@@ -138,6 +139,6 @@ class Command:
|
|||||||
content=get_models_describe(app),
|
content=get_models_describe(app),
|
||||||
)
|
)
|
||||||
version_file = Path(dirname, version)
|
version_file = Path(dirname, version)
|
||||||
content = MIGRATE_TEMPLATE.format(upgrade_sql=f'"""{schema}"""', downgrade_sql="")
|
content = MIGRATE_TEMPLATE.format(upgrade_sql=schema, downgrade_sql="")
|
||||||
with open(version_file, "w", encoding="utf-8") as f:
|
with open(version_file, "w", encoding="utf-8") as f:
|
||||||
f.write(content)
|
f.write(content)
|
||||||
|
|||||||
@@ -15,21 +15,17 @@ from aerich.ddl import BaseDDL
|
|||||||
from aerich.models import MAX_VERSION_LENGTH, Aerich
|
from aerich.models import MAX_VERSION_LENGTH, Aerich
|
||||||
from aerich.utils import get_app_connection, get_models_describe, is_default_function
|
from aerich.utils import get_app_connection, get_models_describe, is_default_function
|
||||||
|
|
||||||
MIGRATE_TEMPLATE = """from typing import List
|
MIGRATE_TEMPLATE = """from tortoise import BaseDBAsyncClient
|
||||||
|
|
||||||
from tortoise import BaseDBAsyncClient
|
|
||||||
|
|
||||||
|
|
||||||
async def upgrade(db: BaseDBAsyncClient) -> List[str]:
|
async def upgrade(db: BaseDBAsyncClient) -> str:
|
||||||
return [
|
return \"\"\"
|
||||||
{upgrade_sql}
|
{upgrade_sql}\"\"\"
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
async def downgrade(db: BaseDBAsyncClient) -> List[str]:
|
async def downgrade(db: BaseDBAsyncClient) -> str:
|
||||||
return [
|
return \"\"\"
|
||||||
{downgrade_sql}
|
{downgrade_sql}\"\"\"
|
||||||
]
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
@@ -52,7 +48,7 @@ class Migrate:
|
|||||||
_db_version: Optional[str] = None
|
_db_version: Optional[str] = None
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_all_version_files(cls) -> list[str]:
|
def get_all_version_files(cls) -> List[str]:
|
||||||
return sorted(
|
return sorted(
|
||||||
filter(lambda x: x.endswith("py"), os.listdir(cls.migrate_location)),
|
filter(lambda x: x.endswith("py"), os.listdir(cls.migrate_location)),
|
||||||
key=lambda x: int(x.split("_")[0]),
|
key=lambda x: int(x.split("_")[0]),
|
||||||
@@ -125,9 +121,10 @@ class Migrate:
|
|||||||
|
|
||||||
version_file = Path(cls.migrate_location, version)
|
version_file = Path(cls.migrate_location, version)
|
||||||
content = MIGRATE_TEMPLATE.format(
|
content = MIGRATE_TEMPLATE.format(
|
||||||
upgrade_sql=",\n ".join(map(lambda x: f'"""{x}"""', cls.upgrade_operators)),
|
upgrade_sql=";\n ".join(cls.upgrade_operators) + ";",
|
||||||
downgrade_sql=",\n ".join(map(lambda x: f'"""{x}"""', cls.downgrade_operators)),
|
downgrade_sql=";\n ".join(cls.downgrade_operators) + ";",
|
||||||
)
|
)
|
||||||
|
|
||||||
with open(version_file, "w", encoding="utf-8") as f:
|
with open(version_file, "w", encoding="utf-8") as f:
|
||||||
f.write(content)
|
f.write(content)
|
||||||
return version
|
return version
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
__version__ = "0.6.4"
|
__version__ = "0.7.1"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "aerich"
|
name = "aerich"
|
||||||
version = "0.7.0"
|
version = "0.7.1"
|
||||||
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"
|
||||||
|
|||||||
Reference in New Issue
Block a user