Files
presensi/app/Database/Migrations/2026-02-20-110534_CreateStudentsTable.php
2026-03-05 14:37:36 +07:00

53 lines
1.4 KiB
PHP

<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
class CreateStudentsTable extends Migration
{
public function up()
{
$this->forge->addField([
'id' => [
'type' => 'INT',
'constraint' => 11,
'unsigned' => true,
'auto_increment' => true,
],
'nis' => [
'type' => 'VARCHAR',
'constraint' => '50',
'unique' => true,
],
'name' => [
'type' => 'VARCHAR',
'constraint' => '255',
],
'class_id' => [
'type' => 'INT',
'constraint' => 11,
'unsigned' => true,
],
'created_at' => [
'type' => 'DATETIME',
'null' => true,
],
'updated_at' => [
'type' => 'DATETIME',
'null' => true,
],
]);
$this->forge->addKey('id', true);
$this->forge->addKey('class_id');
$this->forge->addForeignKey('class_id', 'classes', 'id', 'CASCADE', 'CASCADE');
$this->forge->createTable('students');
}
public function down()
{
$this->forge->dropTable('students');
}
}