clqms-be/app/Database/Migrations/2025-09-12-011643_Contact.php
2025-12-22 13:09:49 +07:00

85 lines
4.6 KiB
PHP

<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
class CreateContactTable extends Migration {
public function up() {
// Contact
$this->forge->addField([
'ContactID' => [ 'type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'auto_increment' => true ],
'NameFirst' => [ 'type' => 'VARCHAR', 'constraint' => 100, 'null' => true ],
'NameLast' => [ 'type' => 'VARCHAR', 'constraint' => 100, 'null' => true ],
'Title' => [ 'type' => 'VARCHAR', 'constraint' => 50, 'null' => true ],
'Initial' => [ 'type' => 'VARCHAR', 'constraint' => 10, 'null' => true ],
'Birthdate' => [ 'type' => 'DATE', 'null' => true ],
'EmailAddress1' => [ 'type' => 'VARCHAR', 'constraint' => 150, 'null' => true ],
'EmailAddress2' => [ 'type' => 'VARCHAR', 'constraint' => 150, 'null' => true ],
'Phone' => [ 'type' => 'VARCHAR', 'constraint' => 50, 'null' => true ],
'MobilePhone1' => [ 'type' => 'VARCHAR', 'constraint' => 50, 'null' => true ],
'MobilePhone2' => [ 'type' => 'VARCHAR', 'constraint' => 50, 'null' => true ],
'Specialty' => [ 'type' => 'VARCHAR', 'constraint' => 100, 'null' => true ],
'SubSpecialty' => [ 'type' => 'VARCHAR', 'constraint' => 100, 'null' => true ],
'Password' => [ 'type' => 'VARCHAR', 'constraint' => 255, 'null' => true ],
// Untuk Auth
'LockedAt' => [ 'type' => 'DATETIME', 'null' => true ],
'LockReason' => [ 'type' => 'VARCHAR', 'constraint' => 150, 'null' => true ],
'Role' => [ 'type' => "ENUM('admin','staff','user')", 'default' => 'user', 'null' => false ],
'CreateDate' => ['type' => 'DATETIME', 'null' => true],
'EndDate' => [ 'type' => 'DATETIME', 'null' => true ],
]);
$this->forge->addKey('ContactID', true);
$this->forge->addUniqueKey('EmailAddress1');
$this->forge->createTable('contact');
// ContactDetail
$this->forge->addField([
'ContactDetID' => [ 'type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'auto_increment' => true ],
'ContactID' => [ 'type' => 'INT', 'constraint' => 11 ],
'SiteID' => [ 'type' => 'INT', 'constraint' => 11, 'null' => true ],
'ContactCode' => [ 'type' => 'varchar', 'constraint' => 11, 'null' => false ],
'ContactEmail' => [ 'type' => 'VARCHAR', 'constraint' => 150, 'null' => true ],
'OccupationID' => [ 'type' => 'VARCHAR', 'constraint' => 50, 'null' => true ],
'JobTitle' => [ 'type' => 'VARCHAR', 'constraint' => 100, 'null' => true ],
'Department' => [ 'type' => 'VARCHAR', 'constraint' => 100, 'null' => true ],
'ContactStartDate' => [ 'type' => 'DATETIME', 'null' => true ],
'ContactEndDate' => [ 'type' => 'DATETIME ', 'null' => true ],
]);
$this->forge->addKey('ContactDetID', true);
$this->forge->addUniqueKey(['SiteID','ContactID']);
$this->forge->createTable('contactdetail');
// Occupation
$this->forge->addField([
'OccupationID' => [ 'type' => 'INT', 'constraint' => 11, 'auto_increment' => true],
'OccCode' => [ 'type' => 'VARCHAR', 'constraint' => 5, 'null' => true ],
'OccText' => [ 'type' => 'VARCHAR', 'constraint' => 255, 'null' => true ],
'Description' => [ 'type' => 'TEXT', 'null' => true ],
'CreateDate' => ['type' => 'DATETIME', 'null' => true],
]);
$this->forge->addKey('OccupationID', true);
$this->forge->createTable('occupation');
$this->forge->addField([
'SpecialtyID' => ['type' => 'INT', 'unsigned' => true, 'auto_increment' => true],
'SpecialtyText' => ['type' => 'varchar', 'constraint' => 255, 'null' => true],
'Parent' => ['type' => 'int', 'null' => true],
'Title' => ['type' => 'VARCHAR', 'constraint' => 100, 'null' => false],
'CreateDate' => ['type' => 'datetime', 'null' => true],
'EndDate' => ['type' => 'datetime', 'null' => true],
]);
$this->forge->addKey('SpecialtyID', true);
$this->forge->createTable('medicalspecialty');
}
public function down() {
$this->forge->dropTable('contact');
$this->forge->dropTable('contactdetail');
$this->forge->dropTable('occupation');
$this->forge->dropTable('medicalspecialty');
}
}