-
-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support migration for specified index. (#203)
- Loading branch information
Showing
10 changed files
with
113 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import base64 | ||
import json | ||
import pickle # nosec: B301 | ||
|
||
from tortoise.indexes import Index | ||
|
||
|
||
class JsonEncoder(json.JSONEncoder): | ||
def default(self, obj): | ||
if isinstance(obj, Index): | ||
return { | ||
"type": "index", | ||
"val": base64.b64encode(pickle.dumps(obj)).decode(), | ||
} # nosec: B301 | ||
else: | ||
return super().default(obj) | ||
|
||
|
||
def object_hook(obj): | ||
_type = obj.get("type") | ||
if not _type: | ||
return obj | ||
return pickle.loads(base64.b64decode(obj["val"])) # nosec: B301 | ||
|
||
|
||
def encoder(obj: dict): | ||
return json.dumps(obj, cls=JsonEncoder) | ||
|
||
|
||
def decoder(obj: str): | ||
return json.loads(obj, object_hook=object_hook) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
from tortoise import Model, fields | ||
|
||
from aerich.coder import decoder, encoder | ||
|
||
MAX_VERSION_LENGTH = 255 | ||
|
||
|
||
class Aerich(Model): | ||
version = fields.CharField(max_length=MAX_VERSION_LENGTH) | ||
app = fields.CharField(max_length=20) | ||
content = fields.JSONField() | ||
content = fields.JSONField(encoder=encoder, decoder=decoder) | ||
|
||
class Meta: | ||
ordering = ["-id"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = "0.6.1" | ||
__version__ = "0.6.2" |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "aerich" | ||
version = "0.6.1" | ||
version = "0.6.2" | ||
description = "A database migrations tool for Tortoise ORM." | ||
authors = ["long2ice <[email protected]>"] | ||
license = "Apache-2.0" | ||
|
@@ -16,7 +16,7 @@ include = ["CHANGELOG.md", "LICENSE", "README.md"] | |
|
||
[tool.poetry.dependencies] | ||
python = "^3.7" | ||
tortoise-orm = "*" | ||
tortoise-orm = { git = "https://github.com/tortoise/tortoise-orm.git", branch = "develop" } | ||
click = "*" | ||
asyncpg = { version = "*", optional = true } | ||
asyncmy = { version = "*", optional = true } | ||
|