import { BaseSchema } from '@adonisjs/lucid/schema'

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

  async up() {
    this.schema.createTable(this.tableName, (table) => {
      table.increments('id')
      table
        .integer('intl_courier_rate_group_id')
        .unsigned()
        .notNullable()
        .references('id')
        .inTable('intl_courier_rate_groups')
        .onDelete('CASCADE')
      table.tinyint('courier').notNullable()
      table.decimal('weight_from', 8, 3).notNullable()
      table.decimal('weight_to', 8, 3).notNullable()
      table.tinyint('rate_type').notNullable()
      table.decimal('value', 9, 3).notNullable()

      table.timestamp('created_at').notNullable()
      table.timestamp('updated_at').nullable()
    })
  }

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