How to define Table name using `sequelize-typescript`?

Viewed 2360

it used to be possible to define tableName parameter in the Table decorator from sequelize-typescript like the below:

@Table({
  tableName: 'my-custom-tablename'
})
export class Tenants extends Model<Tenants> {
  @IsUUID(4)
  @Default(uuid())
  @PrimaryKey
  @Column
  uuid!: string;

  @CreatedAt
  @Column
  created_at!: Date;

  @UpdatedAt
  @Column
  updated_at!: Date;
}

With the latest version it doesn't seem possible to do this, only two options remain available: modelName and version, so now, TableName is automatically mapped to the ModelName (className)

How to pass the real table name associated to the model?

1 Answers
@Table({
  tableName: 'user'
})
export class User extends Model<User> {
  @Column
  firstName!: string;

  @CreatedAt
  @Column
  createdAt!: Date;

  @UpdatedAt
  @Column
  updatedAt!: Date;

}

This is working for me on the latest npm versions for sequelize-typescript (1.1.0) and sequalize (5.21.11).

On default the table would be named Users but with this code it is set to user.

Related