<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class AddUserIdToParentsTable extends Migration
{
    public function up()
    {
        $this->forge->addColumn('parents', [
            'user_id' => [
                'type'       => 'INT',
                'constraint' => 11,
                'unsigned'   => true,
                'null'       => true,
                'after'      => 'id',
            ],
        ]);
        $this->forge->addForeignKey('user_id', 'users', 'id', 'SET NULL', 'CASCADE', 'parents_user_id_fk');
    }

    public function down()
    {
        $this->forge->dropForeignKey('parents', 'parents_user_id_fk');
        $this->forge->dropColumn('parents', 'user_id');
    }
}
