// src/db/migrations/20260110_alter_chargers_numeric_fields.js

exports.up = async function (knex) {
    // charging_current: estava INTEGER, mas o firmware manda amps com decimal (ex: 14.2)
    await knex.raw(`
      ALTER TABLE chargers
      ALTER COLUMN charging_current
      TYPE numeric(8,2)
      USING charging_current::numeric
    `);
  
    // charging_time: também estava INTEGER; em alguns firmwares pode vir com decimal (ex: 12.5)
    // Se tens a certeza que é sempre inteiro, podes remover este bloco.
    await knex.raw(`
      ALTER TABLE chargers
      ALTER COLUMN charging_time
      TYPE numeric(10,1)
      USING charging_time::numeric
    `);
  };
  
  exports.down = async function (knex) {
    // volta para INTEGER arredondando
    await knex.raw(`
      ALTER TABLE chargers
      ALTER COLUMN charging_current
      TYPE integer
      USING ROUND(charging_current)::integer
    `);
  
    await knex.raw(`
      ALTER TABLE chargers
      ALTER COLUMN charging_time
      TYPE integer
      USING ROUND(charging_time)::integer
    `);
  };
  