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

Unique decorator that incorporates deletedAt field #223

Open
goldcaddy77 opened this issue Oct 6, 2019 · 3 comments
Open

Unique decorator that incorporates deletedAt field #223

goldcaddy77 opened this issue Oct 6, 2019 · 3 comments
Milestone

Comments

@goldcaddy77
Copy link
Owner

goldcaddy77 commented Oct 6, 2019

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
Copy link
Owner Author

Note that soft deletes landed in TypeORM recently. Just need to upgrade: typeorm/typeorm#5034

@goldcaddy77 goldcaddy77 added this to the V3 milestone Mar 21, 2020
@ghaedi1993
Copy link

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
Copy link
Owner Author

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.

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

No branches or pull requests

2 participants