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

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

    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('series_id')
                .unsigned()
                .references('id')
                .inTable('series')
                .onDelete('CASCADE')
                .notNullable()
            table.string('title')
            table.integer('episode_num').notNullable()
            table.string('description')
            table.string('cover')
            table.string('video')
            table.integer('play_count').defaultTo(0)
            table.decimal('price', 19, 6).defaultTo(0)
        })
    }

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