This commit introduces a complete documentation suite, refactors the API layer for
better consistency, and updates the database schema and seeding logic.
Key Changes:
- Documentation:
- Added `CLAUDE.md` with development guidelines and architecture overview.
- Created `docs/` directory with detailed guides for architecture, development,
and source tree analysis.
- Database & Migrations:
- Implemented `RenameMasterColumns` migration to standardize column naming
(e.g., `name` -> `dept_name`, `name` -> `control_name`).
- Added `CmodQcSeeder` to populate the system with realistic sample data
for depts, controls, tests, and results.
- Backend API:
- Created `DashboardApiController` with `getRecent()` for dashboard stats.
- Created `ReportApiController` for managed reporting access.
- Updated `app/Config/Routes.php` with new API groupings and documentation routes.
- Frontend & Views:
- Refactored master data views (`dept`, `test`, `control`) to use Alpine.js
and the updated API structure.
- Modernized `dashboard.php` and `main_layout.php` with improved UI/UX.
- Infrastructure:
- Updated `.gitignore` to exclude development-specific artifacts (`_bmad/`, `.claude/`).
117 lines
6.2 KiB
PHP
117 lines
6.2 KiB
PHP
<?php
|
|
|
|
namespace App\Database\Migrations;
|
|
|
|
use CodeIgniter\Database\Migration;
|
|
|
|
class QualityControlSystem extends Migration
|
|
{
|
|
public function up()
|
|
{
|
|
// master_depts - No dependencies
|
|
$this->forge->addField([
|
|
'dept_id' => ['type' => 'INT', 'unsigned' => true, 'auto_increment' => true],
|
|
'name' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => true],
|
|
'created_at' => ['type' => 'DATETIME', 'null' => true],
|
|
'updated_at' => ['type' => 'DATETIME', 'null' => true],
|
|
'deleted_at' => ['type' => 'DATETIME', 'null' => true],
|
|
]);
|
|
$this->forge->addKey('dept_id', true);
|
|
$this->forge->createTable('master_depts');
|
|
|
|
// master_controls - FK to master_depts
|
|
$this->forge->addField([
|
|
'control_id' => ['type' => 'INT', 'unsigned' => true, 'auto_increment' => true],
|
|
'dept_id' => ['type' => 'INT', 'unsigned' => true, 'null' => true],
|
|
'name' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => true],
|
|
'lot' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => true],
|
|
'producer' => ['type' => 'TEXT', 'null' => true],
|
|
'exp_date' => ['type' => 'DATE', 'null' => true],
|
|
'created_at' => ['type' => 'DATETIME', 'null' => true],
|
|
'updated_at' => ['type' => 'DATETIME', 'null' => true],
|
|
'deleted_at' => ['type' => 'DATETIME', 'null' => true],
|
|
]);
|
|
$this->forge->addKey('control_id', true);
|
|
$this->forge->addForeignKey('dept_id', 'master_depts', 'dept_id', 'SET NULL', 'CASCADE');
|
|
$this->forge->createTable('master_controls');
|
|
|
|
// master_tests - FK to master_depts
|
|
$this->forge->addField([
|
|
'test_id' => ['type' => 'INT', 'unsigned' => true, 'auto_increment' => true],
|
|
'dept_id' => ['type' => 'INT', 'unsigned' => true, 'null' => true],
|
|
'name' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => true],
|
|
'unit' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => true],
|
|
'method' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => true],
|
|
'cva' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => true],
|
|
'ba' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => true],
|
|
'tea' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => true],
|
|
'created_at' => ['type' => 'DATETIME', 'null' => true],
|
|
'updated_at' => ['type' => 'DATETIME', 'null' => true],
|
|
'deleted_at' => ['type' => 'DATETIME', 'null' => true],
|
|
]);
|
|
$this->forge->addKey('test_id', true);
|
|
$this->forge->addForeignKey('dept_id', 'master_depts', 'dept_id', 'SET NULL', 'CASCADE');
|
|
$this->forge->createTable('master_tests');
|
|
|
|
// control_tests - FK to master_controls, master_tests
|
|
$this->forge->addField([
|
|
'control_test_id' => ['type' => 'INT', 'unsigned' => true, 'auto_increment' => true],
|
|
'control_id' => ['type' => 'INT', 'unsigned' => true, 'null' => true],
|
|
'test_id' => ['type' => 'INT', 'unsigned' => true, 'null' => true],
|
|
'mean' => ['type' => 'FLOAT', 'null' => true],
|
|
'sd' => ['type' => 'FLOAT', 'null' => true],
|
|
'created_at' => ['type' => 'DATETIME', 'null' => true],
|
|
'updated_at' => ['type' => 'DATETIME', 'null' => true],
|
|
'deleted_at' => ['type' => 'DATETIME', 'null' => true],
|
|
]);
|
|
$this->forge->addKey('control_test_id', true);
|
|
$this->forge->addForeignKey('control_id', 'master_controls', 'control_id', 'SET NULL', 'CASCADE');
|
|
$this->forge->addForeignKey('test_id', 'master_tests', 'test_id', 'SET NULL', 'CASCADE');
|
|
$this->forge->createTable('control_tests');
|
|
|
|
// results - FK to master_controls, master_tests
|
|
$this->forge->addField([
|
|
'result_id' => ['type' => 'INT', 'unsigned' => true, 'auto_increment' => true],
|
|
'control_id' => ['type' => 'INT', 'unsigned' => true, 'null' => true],
|
|
'test_id' => ['type' => 'INT', 'unsigned' => true, 'null' => true],
|
|
'res_date' => ['type' => 'DATETIME', 'null' => true],
|
|
'res_value' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => true],
|
|
'res_comment' => ['type' => 'TEXT', 'null' => true],
|
|
'created_at' => ['type' => 'DATETIME', 'null' => true],
|
|
'updated_at' => ['type' => 'DATETIME', 'null' => true],
|
|
'deleted_at' => ['type' => 'DATETIME', 'null' => true],
|
|
]);
|
|
$this->forge->addKey('result_id', true);
|
|
$this->forge->addForeignKey('control_id', 'master_controls', 'control_id', 'SET NULL', 'CASCADE');
|
|
$this->forge->addForeignKey('test_id', 'master_tests', 'test_id', 'SET NULL', 'CASCADE');
|
|
$this->forge->createTable('results');
|
|
|
|
// result_comments - FK to master_controls, master_tests (composite unique key)
|
|
$this->forge->addField([
|
|
'result_comment_id' => ['type' => 'INT', 'unsigned' => true, 'auto_increment' => true],
|
|
'control_id' => ['type' => 'INT', 'unsigned' => true],
|
|
'test_id' => ['type' => 'INT', 'unsigned' => true],
|
|
'comment_month' => ['type' => 'VARCHAR', 'constraint' => 7],
|
|
'com_text' => ['type' => 'TEXT', 'null' => true],
|
|
'created_at' => ['type' => 'DATETIME', 'null' => true],
|
|
'updated_at' => ['type' => 'DATETIME', 'null' => true],
|
|
'deleted_at' => ['type' => 'DATETIME', 'null' => true],
|
|
]);
|
|
$this->forge->addKey('result_comment_id', true);
|
|
$this->forge->addUniqueKey(['control_id', 'test_id', 'comment_month']);
|
|
$this->forge->addForeignKey('control_id', 'master_controls', 'control_id', 'CASCADE', 'CASCADE');
|
|
$this->forge->addForeignKey('test_id', 'master_tests', 'test_id', 'CASCADE', 'CASCADE');
|
|
$this->forge->createTable('result_comments');
|
|
}
|
|
|
|
public function down()
|
|
{
|
|
$this->forge->dropTable('result_comments', true);
|
|
$this->forge->dropTable('results', true);
|
|
$this->forge->dropTable('control_tests', true);
|
|
$this->forge->dropTable('master_tests', true);
|
|
$this->forge->dropTable('master_controls', true);
|
|
$this->forge->dropTable('master_depts', true);
|
|
}
|
|
}
|