<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
class CreateDepartmentsTable extends Migration
{
public function up() {
//departments
$this->forge->addField([
'id' => ['type' => 'INT','constraint' => 5,'unsigned' => true,'auto_increment' => true,],
'name' => ['type' => 'VARCHAR','constraint' => '100',]
]);
$this->forge->addKey('id', true);
$this->forge->createTable('departments');
//employees
$this->forge->addField([
'id' => ['type' => 'INT','constraint' => 5, 'unsigned' => true, 'auto_increment' => true,],
'depart_id' => [ 'type' => 'INT', 'constraint' => 5,'unsigned' => true,],
'name' => ['type' => 'VARCHAR','constraint' => '100',]
]);
$this->forge->addKey('id', true);
$this->forge->addForeignKey('depart_id', 'departments', 'id', 'CASCADE', 'CASCADE');
$this->forge->createTable('employees');
}
public function down() {
$this->forge->dropTable('departments');
$this->forge->dropTable('employees');
}
}