sequelize-typescript
sequelize-typescript copied to clipboard
Feature Request: Allow setting constraints on table/field
Would it be possible to allow settings contrains on table and field the same way we set index.
E.g: Defining a table this way:
@Table({
constraints: [
{
name: "unique_user_post",
unique: true,
fields: ['userId', 'postId']
},
]
})
class UserPost extends Model {
@ForeignKey(() => User)
@Column
userId: string;
@ForeignKey(() => Post)
@Column
postId: string;
}
Using indexes
does not create the constraints in postgres, which can be needed.
Thanks!
I double this, if I add a @Unique decorator to userId, postId currently, it will create a unique constraint (userId, postId) but what if I want to create (postId, userId) without changing anything in the model?