<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class CreatePengunjung extends Migration
{
    public function up()
    {
        $this->forge->addField([
            'id' => [
                'type'           => 'INT',
                'constraint'     => 11,
                'unsigned'       => true,
                'auto_increment' => true,
            ],

            'anggota_id' => [
                'type'       => 'INT',
                'constraint' => 11,
                'unsigned'   => true,
            ],

            'tanggal' => [
                'type' => 'DATE',
            ],

            'jam_masuk' => [
                'type' => 'TIME',
            ],

            'created_at' => [
                'type' => 'DATETIME',
                'null' => true,
            ],

            'updated_at' => [
                'type' => 'DATETIME',
                'null' => true,
            ],
        ]);

        $this->forge->addKey('id', true);

        $this->forge->addForeignKey(
            'anggota_id',
            'anggota',
            'id',
            'CASCADE',
            'CASCADE'
        );

        $this->forge->createTable('pengunjung');
    }

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