Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQLAlchemy: Use server-side now() function for "autoincrement" columns #24

Merged
merged 1 commit into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
## in progress
- Update to MLflow 2.7.1
- Improve `table_exists()` in `example_merlion.py`
- SQLAlchemy: Use server-side `now()` function for "autoincrement" columns

## 2023-09-12 0.1.1
- Documentation: Improve "Container Usage" page
Expand Down
12 changes: 2 additions & 10 deletions mlflow_cratedb/patch/crate_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ def patch_models():
dialect parameter `crate_polyfill_autoincrement` or such.
"""
import sqlalchemy.sql.schema as schema
from sqlalchemy import func

init_dist = schema.Column.__init__

def __init__(self, *args, **kwargs):
if "autoincrement" in kwargs:
del kwargs["autoincrement"]
if "default" not in kwargs:
kwargs["default"] = generate_unique_integer
kwargs["default"] = func.now()
init_dist(self, *args, **kwargs)

schema.Column.__init__ = __init__ # type: ignore[method-assign]
Expand Down Expand Up @@ -104,12 +105,3 @@ def check_uniqueness(mapper, connection, target):
)

return check_uniqueness


def generate_unique_integer() -> int:
"""
Produce a short, unique, non-sequential identifier based on Hashids.
"""
from vasuki import generate_nagamani19_int

return generate_nagamani19_int()
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ dependencies = [
"crate[sqlalchemy]",
"mlflow==2.7.1",
"sqlparse<0.5",
"vasuki<1,>=0.4",
]

[project.optional-dependencies]
Expand Down