Merged in afiqhamzah/chore/transaction_table_optimization_migration (pull request #90)
Optimize transaction table with index
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Doctrine\DBAL;
|
||||
|
||||
class AddIndexToTransactionTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::connection('mysql7')->table('transaction', static function (Blueprint $table) {
|
||||
$schemaManager = Schema::getConnection()->getDoctrineSchemaManager();
|
||||
$indexesFound = $schemaManager->listTableIndexes('transaction');
|
||||
|
||||
if (! array_key_exists('idx_search_norujukan', $indexesFound)) {
|
||||
$table->index(['created_at', 'trans_type', 'kodcaw'], 'idx_search_norujukan');
|
||||
}
|
||||
});
|
||||
|
||||
Schema::connection('mysql7')->table('transaksi_keuntungan', static function (Blueprint $table) {
|
||||
$schemaManager = Schema::getConnection()->getDoctrineSchemaManager();
|
||||
$indexesFound = $schemaManager->listTableIndexes('transaksi_keuntungan');
|
||||
|
||||
if (! array_key_exists('idx_tarikh_bayaran', $indexesFound)) {
|
||||
$table->index('tarikh_bayaran', 'idx_tarikh_bayaran');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::connection('mysql7')->table('transaction', static function (Blueprint $table) {
|
||||
$schemaManager = Schema::getConnection()->getDoctrineSchemaManager();
|
||||
$indexesFound = $schemaManager->listTableIndexes('transaction');
|
||||
|
||||
if (array_key_exists('idx_seach_norujukan', $indexesFound)) {
|
||||
$table->dropIndex('idx_search_norujukan');
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Schema::connection('mysql7')->table('transaksi_keuntungan', static function (Blueprint $table) {
|
||||
$schemaManager = Schema::getConnection()->getDoctrineSchemaManager();
|
||||
$indexesFound = $schemaManager->listTableIndexes('transaksi_keuntungan');
|
||||
|
||||
if (array_key_exists('idx_tarikh_bayaran', $indexesFound)) {
|
||||
$table->dropIndex('idx_tarikh_bayaran');
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user