sequelize-typescript
sequelize-typescript copied to clipboard
unique index with paranoid mode
Issue
I'm having a unique index of three fields but i'm using paranoid mode which leads to not being able to reuse the same values after deletion in those three fields.
There is a where condition in the createIndexDecorator but that does not seem to do anything.
How can i combine the three field index with the paranoid mode?
Versions
- sequelize:"6.6.5"
- sequelize-typescript:"^2.1.0"
- typescript:"4.4.3"
Issue type
- [x] information/help request
- [ ] bug report
- [ ] feature request
Actual behavior
Currently after deletion of the entry the unique index prevents the values from beeing used again.
Expected behavior
Have some kind of index that respects that the entries have been deleted.
Steps to reproduce
Related code
const TranslationIndex = createIndexDecorator({
name: 'translation_appId_txtKey_langIso',
using: 'BTREE',
unique: true,
where: { deletedAt: null },
});
export interface TranslationAttributes {
id?: string;
appId: string;
txtKey: string;
langIso: string;
value: string;
createdAt?: Date;
updatedAt?: Date;
deletedAt?: Date;
}
@Table({ tableName: 'translations' })
export class Translation
extends Model<TranslationAttributes, TranslationAttributes>
implements TranslationAttributes
{
@Column({ primaryKey: true, defaultValue: uuidv4, type: DataType.STRING(36) })
@Index({ name: 'PRIMARY', using: 'BTREE', order: 'ASC', unique: true })
id!: string;
@Column({ primaryKey: true, type: DataType.STRING(36) })
@TranslationIndex
appId!: string;
@Column({ primaryKey: true, type: DataType.STRING(128) })
@TranslationIndex
txtKey!: string;
@Column({ primaryKey: true, type: DataType.STRING(5) })
@TranslationIndex
langIso!: string;
@Column({ allowNull: false, type: DataType.TEXT() })
value!: string;
@Column({ type: DataType.DATE })
@CreatedAt
createdAt!: Date;
@Column({ allowNull: true, type: DataType.DATE })
@UpdatedAt
updatedAt?: Date;
@Column({ allowNull: true, type: DataType.DATE })
@DeletedAt
deletedAt?: Date;
}
Has noone any info's on this?