clqms-be/app/Database/Migrations/2025-09-10-141522_Location.php
mahdahar a47db49f81 feat: improve Location API error handling
- Add Phone/Email fields to LocationAddressModel allowedFields
- Fix saveLocation() to throw exceptions instead of returning error arrays
- Update controller to properly handle model responses
- Include actual database error message in transaction failures
2026-01-06 17:00:33 +07:00

46 lines
2.0 KiB
PHP

<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
class CreateLocationTable extends Migration {
public function up() {
$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' => 'int', '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');
}
public function down() {
$this->forge->dropTable('location');
$this->forge->dropTable('locationaddress');
}
}