<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class CreateHargaMarketplace extends Migration
{
    public function up(): void
    {
        $this->forge->addField([
            'id_harga_marketplace' => [
                'type'           => 'INT',
                'constraint'     => 11,
                'auto_increment' => true
            ],
            'id_marketplace' => [
                'type'       => 'INT',
                'constraint' => 11
            ],
            'id_produk' => [
                'type'       => 'INT',
                'constraint' => 11
            ],
            'harga_marketplace' => [
                'type'       => 'DECIMAL',
                'constraint' => '15,2',
                'default'    => 0
            ],
            'created_at' => [
                'type' => 'DATETIME',
                'null' => true
            ],
            'updated_at' => [
                'type' => 'DATETIME',
                'null' => true
            ]
        ]);

        $this->forge->addKey('id_harga_marketplace', true);
        $this->forge->addUniqueKey(['id_marketplace', 'id_produk']);
        $this->forge->createTable('tb_harga_marketplace', true);
    }

    public function down(): void
    {
        $this->forge->dropTable('tb_harga_marketplace', true);
    }
}