<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class AddPageSelectionToPrintRequests extends Migration
{
    public function up()
    {
        if (! $this->db->tableExists('print_requests')) {
            return;
        }

        if (! $this->db->fieldExists('page_selection', 'print_requests')) {
            $this->forge->addColumn('print_requests', [
                'page_selection' => [
                    'type' => 'VARCHAR',
                    'constraint' => 255,
                    'null' => true,
                    'after' => 'num_copies',
                ],
            ]);
        }
    }

    public function down()
    {
        if (! $this->db->tableExists('print_requests')) {
            return;
        }

        if ($this->db->fieldExists('page_selection', 'print_requests')) {
            $this->forge->dropColumn('print_requests', 'page_selection');
        }
    }
}
