<?php

namespace Tenant\Database\Migrations;

use CodeIgniter\Database\Migration;

/**
 * One event, at most one organizer login — mirrors the existing
 * guest_id/event_client_id nullable-FK-SET-NULL simplicity already on
 * this same table. One organizer can be tied to many events over time
 * (many-to-one), so no uniqueness constraint here.
 */
class AddOrganizerIdToEventsTable extends Migration
{
    public function up()
    {
        $this->forge->addColumn('events', [
            'organizer_id' => [
                'type'       => 'INT',
                'constraint' => 11,
                'unsigned'   => true,
                'null'       => true,
                'after'      => 'event_client_id',
            ],
        ]);
        $this->forge->addForeignKey('organizer_id', 'event_organizers', 'id', '', 'SET NULL');
        $this->forge->processIndexes('events');
    }

    public function down()
    {
        $this->forge->dropForeignKey('events', 'events_organizer_id_foreign');
        $this->forge->dropColumn('events', 'organizer_id');
    }
}
