<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class AddImagesToRewarderEntities extends Migration
{
    public function up()
    {
        $tables = [
            'rewarder_shops',
            'rewarder_product_categories',
            'rewarder_products',
            'rewarder_service_categories',
            'rewarder_services',
        ];

        foreach ($tables as $table) {
            if (!$this->db->fieldExists('img_type', $table)) {
                $this->forge->addColumn($table, [
                    'img_type' => [
                        'type' => 'VARCHAR',
                        'constraint' => 10,
                        'null' => true,
                    ],
                ]);
            }
        }
    }

    public function down()
    {
        $tables = [
            'rewarder_services',
            'rewarder_service_categories',
            'rewarder_products',
            'rewarder_product_categories',
            'rewarder_shops',
        ];

        foreach ($tables as $table) {
            if ($this->db->fieldExists('img_type', $table)) {
                $this->forge->dropColumn($table, 'img_type');
            }
        }
    }
}

