<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class CreateNotificationLogsTable extends Migration
{
    public function up()
    {
        $this->forge->addField([
            'id' => ['type' => 'BIGINT', 'unsigned' => true, 'auto_increment' => true],
            'company_id' => ['type' => 'BIGINT', 'unsigned' => true],
            'type' => ['type' => 'VARCHAR', 'constraint' => 255],
            'related_id' => ['type' => 'BIGINT', 'unsigned' => true],
            'channel' => ['type' => 'VARCHAR', 'constraint' => 255, 'default' => 'mail'],
            'sent_at' => ['type' => 'DATETIME'],
            'created_at' => ['type' => 'DATETIME', 'null' => true],
            'updated_at' => ['type' => 'DATETIME', 'null' => true],
        ]);
        $this->forge->addKey('id', true);
        $this->forge->addForeignKey('company_id', 'companies', 'id', 'CASCADE', 'CASCADE');
        $this->forge->createTable('notification_logs');
    }

    public function down()
    {
        $this->forge->dropTable('notification_logs');
    }
}
