goldcaddy77 / warthog

GraphQL API Framework with strong conventions and auto-generated schema
https://warthog.dev/
MIT License
359 stars 38 forks source link

Unique decorator that incorporates `deletedAt` field #223

Open goldcaddy77 opened 5 years ago

goldcaddy77 commented 5 years ago

Note that this should work elegantly with the fact that Postgres considers all NULLs unique in createdAt field, so we might need to use a partial unique index:

goldcaddy77 commented 4 years ago

Note that soft deletes landed in TypeORM recently. Just need to upgrade: https://github.com/typeorm/typeorm/pull/5034

ghaedi1993 commented 3 years ago

i make it work ,manually by adding partial index from inside postgresql as follows


CREATE UNIQUE INDEX index_name on users (name)
WHERE ("deletedAt" IS null)
@Column()
    @Index(["name"],{unique:true,where:"\"createdAt\" IS null"})
    name: string

is not resulting the same, makes an index in database but not imposing any unique policy . feature's still not implemented or im getting it wronge ?

goldcaddy77 commented 3 years ago

You're right - the feature is still not implemented. Your solution is interesting. There is no reason that I couldn't create my own Unique decorator that adds this type of index. I'm going to look into whether TypeORM has come up with an elegant solution for this as it seems like a pretty common problem.