<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class CreateReportPhotosTable extends Migration
{
    public function up()
    {
        $this->forge->addField([
            'id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'auto_increment' => true],
            'report_id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true],
            'section' => ['type' => 'VARCHAR', 'constraint' => 40, 'default' => 'general'],
            'caption' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true],
            'file_path' => ['type' => 'VARCHAR', 'constraint' => 255],
            'mime' => ['type' => 'VARCHAR', 'constraint' => 120, 'null' => true],
            'size' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'null' => true],
            'orden' => ['type' => 'INT', 'constraint' => 5, 'default' => 0],
            'created_at' => ['type' => 'DATETIME', 'null' => true],
        ]);
        $this->forge->addKey('id', true);
        $this->forge->addKey('report_id');
        $this->forge->addKey('section');
        $this->forge->addForeignKey('report_id', 'reports', 'id', 'CASCADE', 'CASCADE');
        $this->forge->createTable('report_photos');
    }

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