import { AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, Model, Table } from 'sequelize-typescript'
import { VideoModel } from './video'
import * as Sequelize from 'sequelize'

@Table({
  tableName: 'videoView',
  indexes: [
    {
      fields: [ 'videoId' ]
    },
    {
      fields: [ 'startDate' ]
    }
  ]
})
export class VideoViewModel extends Model<VideoViewModel> {
  @CreatedAt
  createdAt: Date

  @AllowNull(false)
  @Column(Sequelize.DATE)
  startDate: Date

  @AllowNull(false)
  @Column(Sequelize.DATE)
  endDate: Date

  @AllowNull(false)
  @Column
  views: number

  @ForeignKey(() => VideoModel)
  @Column
  videoId: number

  @BelongsTo(() => VideoModel, {
    foreignKey: {
      allowNull: false
    },
    onDelete: 'CASCADE'
  })
  Video: VideoModel

}

import { AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, Model, Table } from 'sequelize-typescript'
import { VideoModel } from './video'
import * as Sequelize from 'sequelize'

@Table({
  tableName: 'videoView',
  indexes: [
    {
      fields: [ 'videoId' ]
    }
  ]
})
export class VideoViewModel extends Model<VideoViewModel> {
  @CreatedAt
  createdAt: Date

  @AllowNull(false)
  @Column(Sequelize.DATE)
  startDate: Date

  @AllowNull(false)
  @Column(Sequelize.DATE)
  endDate: Date

  @AllowNull(false)
  @Column
  views: number

  @ForeignKey(() => VideoModel)
  @Column
  videoId: number

  @BelongsTo(() => VideoModel, {
    foreignKey: {
      allowNull: false
    },
    onDelete: 'CASCADE'
  })
  Video: VideoModel

}

--- 
+++ 
@@ -7,6 +7,9 @@
   indexes: [
     {
       fields: [ 'videoId' ]
+    },
+    {
+      fields: [ 'startDate' ]
     }
   ]
 })
Add index to startDate in video view table
