<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class AddAccessTokenToInvoices extends Migration
{
    public function up()
    {
        $this->forge->addColumn('invoices', [
            'access_token' => [
                'type'       => 'VARCHAR',
                'constraint' => 64,
                'null'       => true,
                'after'      => 'nomor_invoice',
            ],
        ]);

        $this->db->query("
            ALTER TABLE `invoices`
            ADD UNIQUE INDEX `invoices_access_token_unique` (`access_token`)
        ");
    }

    public function down()
    {
        $this->db->query("
            ALTER TABLE `invoices`
            DROP INDEX `invoices_access_token_unique`
        ");

        $this->forge->dropColumn('invoices', 'access_token');
    }
}