sequelize-typescript icon indicating copy to clipboard operation
sequelize-typescript copied to clipboard

Feature Request: Allow setting constraints on table/field

Open msimon opened this issue 3 years ago • 1 comments

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!

msimon avatar May 20 '21 13:05 msimon

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?

Coinhexa avatar Oct 15 '22 06:10 Coinhexa