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

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

  async up() {
    this.schema.createTable(this.tableName, (table) => {
      table.increments('id')
      table.string('codigo').notNullable().unique()
      table.string('nome').notNullable()
      table.integer('talhao_id').unsigned().references('id').inTable('talhoes').onDelete('CASCADE')
      table.string('tipo').nullable()
      table.decimal('vazao', 10, 2).nullable()
      table.decimal('raio_alcance', 10, 2).nullable()
      table.boolean('is_ativo').defaultTo(true)
      table.timestamp('created_at')
      table.timestamp('updated_at').nullable()
    })
  }

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