<?php
declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class Task2209051424 extends AbstractMigration
{
    public function up(): void
    {
        $row = $this->fetchRow('SELECT id FROM seguro.propostas WHERE id = 798862');
        if ($row['id']) {
            $table = $this->table('seguro.propostas_parcelas');
            $singleRow = [
                'id_usuario_criacao'    => 2068
                , 'dt_criacao'            => 'NOW()'
                , 'id_proposta'           => 798862
                , 'nr_parcela'            => 2
                , 'vl_total'              => 13911.98
                , 'vl_segurado'           => 0.00
                , 'vl_subvencao_federal'  => 13911.98
                , 'vl_subvencao_estadual' => 0.00
                , 'dt_vencimento'         => '2022-09-15'
                , 'fl_pago'               => 'FALSE'
                , 'id_endosso'            => 617121
            ];
            $table->insert($singleRow)
                ->saveData();
        }
    }

    public function down(): void
    {
        $row = $this->fetchRow('SELECT id FROM seguro.propostas WHERE id = 798862');
        if ($row['id']) {
            $delete = $this->getQueryBuilder();
            $delete->delete('seguro.propostas_parcelas')
                ->where([ 'id_proposta' => 798862
                    , 'nr_parcela'  => 2
                ])
                ->execute();
        }
    }
}
