diff --git a/database/migrations/2024_01_15_114618_add_index_to_transaction_table.php b/database/migrations/2024_01_15_114618_add_index_to_transaction_table.php new file mode 100644 index 0000000..47041d7 --- /dev/null +++ b/database/migrations/2024_01_15_114618_add_index_to_transaction_table.php @@ -0,0 +1,62 @@ +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'); + } + }); + } +}