generated from BrianLusina/pymaze
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sql): new mixin and updates to base repository
Adds a new mixin plus additional updates to the repository. This additionally adds new types with Pydantic and utilities to handle those updates.
- Loading branch information
1 parent
58cc6bd
commit 240aa9c
Showing
11 changed files
with
930 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
python 3.12.0 | ||
python 3.12.3 | ||
pre-commit 3.4.0 |
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,36 @@ | ||
from typing import Any, Literal, Union | ||
|
||
from sanctumlabs_dbkit.sql.types import PydanticModel, PydanticModelList | ||
|
||
|
||
def render_item( | ||
type_: str, obj: Any, autogen_context: Any | ||
) -> Union[str, Literal[False]]: | ||
""" | ||
A custom renderer for the `alembic` migration framework which caters for our custom SQLAlchemy pydantic types. | ||
These types allow for pydantic models to be serialized and deserialized to/from json. Alembic doesn't generate the | ||
correct migrations for these cases so we need to do some hackery and override here. | ||
To leverage the custom renderer, you need to configure it on your migration context in your alembic `env.py` | ||
``python | ||
with connectable.connect() as connection: | ||
context.configure( | ||
connection=connection, | ||
target_metadata=target_metadata, | ||
compare_type=False, | ||
render_item=render_item, | ||
) | ||
``` | ||
See https://alembic.sqlalchemy.org/en/latest/autogenerate.html#affecting-the-rendering-of-types-themselves | ||
See https://gist.github.com/imankulov/4051b7805ad737ace7d8de3d3f934d6b | ||
""" | ||
|
||
if type_ == "type" and ( | ||
isinstance(obj, PydanticModelList) or isinstance(obj, PydanticModel) | ||
): | ||
return "sa.JSON()" | ||
|
||
return False |
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
Oops, something went wrong.