Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
6339dc86a8 | ||
|
768747140a | ||
|
1fde3cd04e | ||
|
d0ce545ff5 | ||
|
09b89ed7d0 | ||
|
86c8382593 |
11
CHANGELOG.md
11
CHANGELOG.md
@@ -2,13 +2,22 @@
|
|||||||
|
|
||||||
## 0.3
|
## 0.3
|
||||||
|
|
||||||
|
### 0.3.2
|
||||||
|
|
||||||
|
- Fix migrate to new database error. (#62)
|
||||||
|
|
||||||
|
### 0.3.1
|
||||||
|
|
||||||
|
- Fix first version error.
|
||||||
|
- Fix init error. (#61)
|
||||||
|
|
||||||
### 0.3.0
|
### 0.3.0
|
||||||
|
|
||||||
- Refactoring migrate logic, and this version is not compatible with previous version.
|
- Refactoring migrate logic, and this version is not compatible with previous version.
|
||||||
- Now there don't need `old_models.py` and it store in database.
|
- Now there don't need `old_models.py` and it store in database.
|
||||||
- Upgrade steps:
|
- Upgrade steps:
|
||||||
1. Upgrade aerich version.
|
1. Upgrade aerich version.
|
||||||
2. Drop aerich model in db and recreate with new struct.
|
2. Drop aerich table in database.
|
||||||
3. Delete `migrations/{app}` folder and rerun `aerich init-db`.
|
3. Delete `migrations/{app}` folder and rerun `aerich init-db`.
|
||||||
4. Update model and `aerich migrate` normally.
|
4. Update model and `aerich migrate` normally.
|
||||||
|
|
||||||
|
@@ -10,6 +10,8 @@
|
|||||||
Aerich is a database migrations tool for Tortoise-ORM, which like alembic for SQLAlchemy, or Django ORM with it\'s
|
Aerich is a database migrations tool for Tortoise-ORM, which like alembic for SQLAlchemy, or Django ORM with it\'s
|
||||||
own migrations solution.
|
own migrations solution.
|
||||||
|
|
||||||
|
**If you upgrade aerich from <= 0.2.5 to >= 0.3.0, see [changelog](https://github.com/tortoise/aerich/blob/dev/CHANGELOG.md) for upgrade steps.**
|
||||||
|
|
||||||
## Install
|
## Install
|
||||||
|
|
||||||
Just install from pypi:
|
Just install from pypi:
|
||||||
@@ -33,7 +35,7 @@ Options:
|
|||||||
-h, --help Show this message and exit.
|
-h, --help Show this message and exit.
|
||||||
|
|
||||||
Commands:
|
Commands:
|
||||||
downgrade Downgrade to previous version.
|
downgrade Downgrade to specified version.
|
||||||
heads Show current available heads in migrate location.
|
heads Show current available heads in migrate location.
|
||||||
history List all migrate items.
|
history List all migrate items.
|
||||||
init Init config file and generate root migrate location.
|
init Init config file and generate root migrate location.
|
||||||
|
@@ -1 +1 @@
|
|||||||
__version__ = "0.3.0"
|
__version__ = "0.3.2"
|
||||||
|
@@ -28,7 +28,9 @@ def coro(f):
|
|||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
ctx = args[0]
|
ctx = args[0]
|
||||||
loop.run_until_complete(f(*args, **kwargs))
|
loop.run_until_complete(f(*args, **kwargs))
|
||||||
Migrate.remove_old_model_file(ctx.obj["app"], ctx.obj["location"])
|
app = ctx.obj.get("app")
|
||||||
|
if app:
|
||||||
|
Migrate.remove_old_model_file(app, ctx.obj["location"])
|
||||||
|
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
@@ -4,7 +4,7 @@ import re
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from importlib import import_module
|
from importlib import import_module
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
from typing import Dict, List, Tuple, Type
|
from typing import Dict, List, Optional, Tuple, Type
|
||||||
|
|
||||||
import click
|
import click
|
||||||
from tortoise import (
|
from tortoise import (
|
||||||
@@ -15,6 +15,7 @@ from tortoise import (
|
|||||||
Model,
|
Model,
|
||||||
Tortoise,
|
Tortoise,
|
||||||
)
|
)
|
||||||
|
from tortoise.exceptions import OperationalError
|
||||||
from tortoise.fields import Field
|
from tortoise.fields import Field
|
||||||
|
|
||||||
from aerich.ddl import BaseDDL
|
from aerich.ddl import BaseDDL
|
||||||
@@ -53,8 +54,11 @@ class Migrate:
|
|||||||
)
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
async def get_last_version(cls) -> Aerich:
|
async def get_last_version(cls) -> Optional[Aerich]:
|
||||||
|
try:
|
||||||
return await Aerich.filter(app=cls.app).first()
|
return await Aerich.filter(app=cls.app).first()
|
||||||
|
except OperationalError:
|
||||||
|
pass
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def remove_old_model_file(cls, app: str, location: str):
|
def remove_old_model_file(cls, app: str, location: str):
|
||||||
@@ -67,15 +71,15 @@ class Migrate:
|
|||||||
async def init_with_old_models(cls, config: dict, app: str, location: str):
|
async def init_with_old_models(cls, config: dict, app: str, location: str):
|
||||||
await Tortoise.init(config=config)
|
await Tortoise.init(config=config)
|
||||||
last_version = await cls.get_last_version()
|
last_version = await cls.get_last_version()
|
||||||
|
cls.app = app
|
||||||
|
cls.migrate_location = os.path.join(location, app)
|
||||||
|
if last_version:
|
||||||
content = last_version.content
|
content = last_version.content
|
||||||
with open(cls.get_old_model_file(app, location), "w") as f:
|
with open(cls.get_old_model_file(app, location), "w") as f:
|
||||||
f.write(content)
|
f.write(content)
|
||||||
|
|
||||||
migrate_config = cls._get_migrate_config(config, app, location)
|
migrate_config = cls._get_migrate_config(config, app, location)
|
||||||
cls.app = app
|
|
||||||
cls.migrate_config = migrate_config
|
cls.migrate_config = migrate_config
|
||||||
cls.migrate_location = os.path.join(location, app)
|
|
||||||
|
|
||||||
await Tortoise.init(config=migrate_config)
|
await Tortoise.init(config=migrate_config)
|
||||||
|
|
||||||
connection = get_app_connection(config, app)
|
connection = get_app_connection(config, app)
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "aerich"
|
name = "aerich"
|
||||||
version = "0.3.0"
|
version = "0.3.2"
|
||||||
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