tortoise / tortoise-orm

Familiar asyncio ORM for python, built with relations in mind
https://tortoise.github.io
Apache License 2.0
4.37k stars 355 forks source link

create unqiue index in indexes and related children in contrib.postgres/sqlite.indexes #1642

Open omidekz opened 3 weeks ago

omidekz commented 3 weeks ago

create a postgresql unique index and consider the nulls not distinct

Description

enhancement was started from this issue

this PR provide a manual solution for postgres driver. but i think the orm has to provide a base/shared solution. the solution is a way to consider nulls equal in unique indexes on that drivers that consider nulls not equal.

postgres can done that by : nulls not distinct sqlite and sqlserver too by : index expressions on mysql i don't know yet.

omidekz commented 2 weeks ago

jun 8/related changes:

abondar commented 2 weeks ago

Why you decided to make it as separate class? I am concerned that it complicated class hierarchy - and now, for example, it is not clear how to make unique index of non-default type for postgres, as there are now separately HashIndex for example, and Unique index, and it is not clear how to make unique HashIndex

Also CI seems to be failing due to lint, you can run make style and make lint to fix it

omidekz commented 2 weeks ago

Hi i got your point. i'll remove shared unique index and go further with driver specific implementation but i have a challenge with partialindex. at the tortoise.indexes file line of 75 where you are using the ValueWrapper, force the k = wrapped_value. but we need k is [not] null if i check the wrapped_value is startswith(is) and then set the operator. its mean im producing some other issues.