clqms-be/app/Database/Migrations/2026-01-01-000002_CreateOrganization.php
root 2bcdf09b55 chore: repo-wide normalization + rules test coverage
Normalize formatting/line endings across configs, controllers, models, tests, and OpenAPI specs.

Update rule expression/rule engine implementation and remove obsolete RuleAction controller/model.

Add unit tests for rule expression syntax and multi-action behavior, and include docs updates.
2026-03-16 07:24:50 +07:00

130 lines
6.7 KiB
PHP

<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
class CreateOrganization extends Migration {
public function up() {
$this->forge->addField([
'AccountID' => ['type' => 'INT', 'unsigned' => true, 'auto_increment' => true],
'Parent' => ['type' => 'INT', 'null' => true],
'AccountName' => ['type' => 'VARCHAR', 'constraint' => 100, 'null' => false],
'Initial' => ['type' => 'VARCHAR', 'constraint' => 10, 'null' => false],
'Street_1' => ['type' => 'VARCHAR', 'constraint' => 150, 'null' => true],
'Street_2' => ['type' => 'VARCHAR', 'constraint' => 150, 'null' => true],
'Street_3' => ['type' => 'VARCHAR', 'constraint' => 150, 'null' => true],
'City' => ['type' => 'varchar', 'constraint' => 150, 'null' => true],
'Province' => ['type' => 'varchar', 'constraint' => 150, 'null' => true],
'ZIP' => ['type' => 'VARCHAR', 'constraint' => 10, 'null' => true],
'Country' => ['type' => 'VARCHAR', 'constraint' => 10, 'null' => true],
'AreaCode' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => true],
'EmailAddress1' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => true],
'EmailAddress2' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => true],
'Phone' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => true],
'Fax' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => true],
'CreateDate' => ['type' => 'datetime', 'null'=> true],
'EndDate' => ['type' => 'datetime', 'null'=> true]
]);
$this->forge->addKey('AccountID', true);
$this->forge->createTable('account');
$this->forge->addField([
'SiteID' => ['type' => 'INT', 'unsigned' => true, 'auto_increment' => true],
'ExtSiteID' => ['type' => 'int', 'null' => true],
'SiteCode' => ['type' => 'VARCHAR', 'constraint' => 2, 'null' => false],
'SiteName' => ['type' => 'VARCHAR', 'constraint' => 100, 'null' => false],
'AccountID' => ['type' => 'int', 'null' => true],
'SiteType' => ['type' => 'VARCHAR', 'constraint' => 10, 'null' => true],
'Parent' => ['type' => 'int', 'null' => true],
'SiteClass' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => true],
'ME' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => true],
'CreateDate' => ['type' => 'datetime', 'null'=> true],
'EndDate' => ['type' => 'datetime', 'null'=> true]
]);
$this->forge->addKey('SiteID', true);
$this->forge->createTable('site');
$this->forge->addField([
'LocationID' => ['type' => 'INT', 'auto_increment' => true, 'unsigned' => true],
'SiteID' => ['type' => 'INT', 'null' => true],
'LocCode' => ['type' => 'VARCHAR', 'constraint' => 6, 'null' => false],
'Parent' => ['type' => 'INT', 'null' => true],
'LocFull' => ['type' => 'varchar', 'constraint' => 255, 'null' => true],
'Description' => ['type' => 'varchar', 'constraint' => 255, 'null' => true],
'LocType' => ['type' => 'VARCHAR', 'constraint' => 10, 'null' => true],
'CreateDate' => ['type' => 'DATETIME', 'null' => true],
'EndDate' => ['type' => 'DATETIME', 'null' => true]
]);
$this->forge->addKey('LocationID', true);
$this->forge->createTable('location');
$this->forge->addField([
'LocationID' => ['type' => 'INT', 'unsigned' => true],
'Street1' => ['type' => 'Varchar', 'constraint' => 255, 'null' => true],
'Street2' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true],
'City' => ['type' => 'int', 'null' => true],
'Province' => ['type' => 'int', 'null' => true],
'PostCode' => ['type' => 'varchar', 'constraint' => 255, 'null' => true],
'GeoLocationSystem' => ['type' => 'varchar', 'constraint' => 255, 'null' => true],
'GeoLocationData' => ['type' => 'varchar', 'constraint' => 255, 'null' => true],
'Phone' => ['type' => 'varchar', 'constraint' => 100, 'null' => true],
'Email' => ['type' => 'varchar', 'constraint' => 150, 'null' => true],
'CreateDate' => ['type' => 'DATETIME', 'null' => true],
'EndDate' => ['type' => 'DATETIME', 'null' => true]
]);
$this->forge->addKey('LocationID', true);
$this->forge->createTable('locationaddress');
$this->forge->addField([
'DisciplineID' => ['type' => 'int', 'unsigned' => true, 'auto_increment'=> true],
'SiteID' => ['type' => 'int', 'null'=> false],
'DisciplineCode' => ['type' => 'varchar', 'constraint'=> 10, 'null'=> false],
'DisciplineName' => ['type' => 'varchar', 'constraint'=> 150, 'null'=> true],
'Parent' => ['type' => 'int', 'null'=> true],
'SeqScr' => ['type' => 'int', 'null' => true],
'SeqRpt' => ['type' => 'int', 'null' => true],
'CreateDate' => ['type'=>'DATETIME', 'null' => true],
'EndDate' => ['type'=>'DATETIME', 'null' => true]
]);
$this->forge->addKey('DisciplineID', true);
$this->forge->createTable('discipline');
$this->forge->addField([
'DepartmentID' => ['type' => 'int', 'unsigned' => true, 'auto_increment'=> true],
'DisciplineID' => ['type' => 'int', 'null'=> false],
'SiteID' => ['type' => 'int', 'null'=> false],
'DepartmentCode' => ['type' => 'varchar', 'constraint'=>10, 'null'=> false],
'DepartmentName' => ['type' => 'varchar', 'constraint'=> 150, 'null'=> true],
'CreateDate' => ['type'=>'DATETIME', 'null' => true],
'EndDate' => ['type'=>'DATETIME', 'null' => true]
]);
$this->forge->addKey('DepartmentID', true);
$this->forge->createTable('department');
$this->forge->addField([
'WorkstationID' => ['type' => 'int', 'unsigned' => true, 'auto_increment'=> true],
'DepartmentID' => ['type' => 'int', 'null'=> false],
'WorkstationCode' => ['type' => 'varchar', 'constraint'=>10, 'null'=> false],
'WorkstationName' => ['type' => 'varchar', 'constraint'=> 150, 'null'=> true],
'Type' => ['type' => 'VARCHAR', 'constraint' => 10, 'null'=> true],
'LinkTo' => ['type' => 'int', 'null'=> true],
'Enable' => ['type' => 'VARCHAR', 'constraint' => 10, 'null'=> true],
'CreateDate' => ['type'=>'DATETIME', 'null' => true],
'EndDate' => ['type'=>'DATETIME', 'null' => true]
]);
$this->forge->addKey('WorkstationID', true);
$this->forge->createTable('workstation');
}
public function down() {
$this->forge->dropTable('workstation');
$this->forge->dropTable('department');
$this->forge->dropTable('discipline');
$this->forge->dropTable('locationaddress');
$this->forge->dropTable('location');
$this->forge->dropTable('site');
$this->forge->dropTable('account');
}
}