Files
opensourcepos/app/Database/Migrations/20250519000000_MigrationOptimizationIndices.php
Joe Williams bcddf482fe [Feature] Add logging to migrations (#4327)
* `execute_script()` now returns a boolean for error handling.

* Added transaction to `Migration_MissingConfigKeys.up()`.

* Added logging to various migrations.

* Added transaction to `Migration_MissingConfigKeys.up()`.

* Added logging to various migrations.

* Formatting and function call fixes

Fixed a minor formatting issue in the migration helper.
Replaced a few remaining error_log() calls.
Updated executeScriptWithTransaction() to use log_message()

* Function call fix

Replaced the last error_log() calls with log_message().

---------

Co-authored-by: Joe Williams <hey-there-joe@outlook.com>
2025-10-19 22:10:28 -07:00

45 lines
1.1 KiB
PHP

<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
use Config\Database;
class MigrationOptimizationIndices extends Migration
{
/**
* Perform a migration step.
*/
public function up(): void
{
log_message('info', 'Migrating Optimization Indices');
helper('migration');
$forge = Database::forge();
if (!indexExists('attribute_links', 'attribute_links_uq2')) {
$columns = [
'item_id',
'receiving_id',
'sale_id',
'definition_id',
'attribute_id'
];
$forge->addKey($columns, false, true, 'attribute_links_uq2');
$forge->processIndexes('attribute_links');
}
if (!indexExists('inventory', 'trans_items_trans_date')) {
$forge->addKey(['trans_items', 'trans_date'], false, false, 'trans_items_trans_date');
$forge->processIndexes('inventory');
}
}
/**
* Revert a migration step.
*/
public function down(): void
{
}
}