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

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

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

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