import BaseSchema from '@ioc:Adonis/Lucid/Schema'

export default class extends BaseSchema {
    protected tableName = 'play_histories'

    public async up() {
        this.schema.createTable(this.tableName, (table) => {
            table.increments('id')
            table.datetime('created_at', { useTz: true })
            table.datetime('updated_at', { useTz: true })
            table.integer('user_id').unsigned().references('users.id').onDelete('CASCADE')
            table.integer('series_id').unsigned().references('series.id').onDelete('CASCADE')
            table.integer('episode_id').unsigned().references('episodes.id').onDelete('CASCADE')
            table.integer('duration').unsigned()
            table.unique(['user_id', 'series_id'])
        })
    }

    public async down() {
        this.schema.dropTable(this.tableName)
    }
}
