Skip to content

Commit

Permalink
SQLAlchemy: Trim implementation for "autoincrement" columns
Browse files Browse the repository at this point in the history
Now uses server-side `now()` function.
  • Loading branch information
amotl committed Sep 18, 2023
1 parent 80f9d6f commit e251ef8
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 11 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

## in progress
- Update to MLflow 2.7.1
- SQLAlchemy: Trim implementation for "autoincrement" columns, using
server-side `now()` function

## 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

0 comments on commit e251ef8

Please sign in to comment.