sequelize-typescript
sequelize-typescript copied to clipboard
How to create check constraint?
Issue
No way to create a constraint rather than unique, index, or unique together Expected behaviour when running sync({force: true}}:
import {
BelongsTo,
Column,
DataType,
ForeignKey,
Model,
Table,
} from 'sequelize-typescript';
@Table({ tableName: 'room', howToAddCustomConstrainHere: '???'})
export class RoomModel extends Model<RoomModel> {
@Column({
type: DataType.INTEGER,
autoIncrement: true,
primaryKey: true,
})
public id: number;
@Column({
type: DataType.STRING(16)
})
public name: string;
@Column({
type: DataType.INTEGER
})
public channelId: number;
}
Should produce check constrain.
create or replace table room
(
id int auto_increment,
name varchar(16) null,
channel_id int null,
constraint channel_should_exist_for_public_room_and_not_exist_for_private
check (`channel_id` is null and `name` is null or `channel_id` is not n),
);
I searched thought documentation and there's no way
Issue type
- [ ] bug report
- [x] feature request
I would also like to know how to add a CHECK constraint to a table.
I triple this, on a side note it seems that only migrations let you do this
@akoidan @Rich43 I found it. This is the closest thing we have to check constraint it seems