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: Polyfill for UNIQUE constraints #76

Open
amotl opened this issue Sep 14, 2023 · 1 comment
Open

SQLAlchemy: Polyfill for UNIQUE constraints #76

amotl opened this issue Sep 14, 2023 · 1 comment
Labels
question Further information is requested

Comments

@amotl
Copy link
Member

amotl commented Sep 14, 2023

About

CrateDB does not support the notion of UNIQUE constraints, because it is a distributed database. For supporting certain applications, specific workarounds have been showing a successful outcome. Hereby, we would like to evaluate how a corresponding patch could be generalized, to be optionally enabled on the CrateDB SQLAlchemy dialect.

Reference

Details

While working on mlflow-cratedb, we had the need to support for UNIQUE constraints, as defined by the application ORM model, so we added a corresponding monkeypatch, which also has a remark:

TODO: Submit patch to crate-python, to be enabled by a dialect parameter crate_polyfill_unique or such.

Currently, the check_uniqueness_factory function is invoked on a single model which needed to be patched. That is still a bit tied to application logic, and would need to be generalized.

from mlflow.store.tracking.dbmodels.models import SqlExperiment

listen(SqlExperiment, "before_insert", check_uniqueness_factory(SqlExperiment, "name"))

Proposal

So, the idea here is to add a dialect parameter crate_polyfill_unique, which will, under the hood, transparently augment the SQLAlchemy model setup process to establish an event listener on the before_insert event, to check for uniqueness by querying the database table.

Surely, this causes overhead, and needs to be strongly emphasized in the documentation. But in general, the kinds of applications we are building this for do not need that much throughput on this end.

@amotl amotl added the question Further information is requested label Oct 6, 2023
@amotl amotl transferred this issue from crate/crate-python Jun 16, 2024
@amotl
Copy link
Member Author

amotl commented Jun 22, 2024

There is a patch now, which includes the corresponding improvement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant