Open goldcaddy77 opened 5 years ago
Note that soft deletes landed in TypeORM recently. Just need to upgrade: https://github.com/typeorm/typeorm/pull/5034
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 ?
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.
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: