36 lines
1.8 KiB
PHP
36 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit\EcommerceFinance;
|
|
|
|
use Illuminate\Database\Schema\Blueprint;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Schema;
|
|
use Tests\TestCase;
|
|
|
|
class WorkOrderLookupMigrationTest extends TestCase
|
|
{
|
|
public function test_lookup_indexes_preserve_values_and_are_reversible(): void
|
|
{
|
|
config(['database.connections.work_order_index_fixture' => ['driver' => 'sqlite', 'database' => ':memory:', 'prefix' => ''],
|
|
'upstream_mirrors.connection' => 'work_order_index_fixture', 'system_database.mode' => 'shared']);
|
|
$schema = Schema::connection('work_order_index_fixture');
|
|
$db = DB::connection('work_order_index_fixture');
|
|
foreach (['ops_work_order_sub', 'ops_work_order_form_value'] as $table) {
|
|
$schema->create($table, static function (Blueprint $t): void {
|
|
$t->integer('id'); $t->longText('main_order_no')->nullable(); $t->integer('sort')->nullable();
|
|
});
|
|
$db->table($table)->insert(['id' => 1, 'main_order_no' => str_repeat('1', 100), 'sort' => 0]);
|
|
}
|
|
$migration = require base_path('database/migrations/2026_09_09_140000_index_after_sales_work_order_lookups.php');
|
|
$migration->up();
|
|
$migration->up();
|
|
$this->assertTrue($schema->hasIndex('ops_work_order_sub', 'idx_work_order_sub_parent'));
|
|
$this->assertTrue($schema->hasIndex('ops_work_order_form_value', 'idx_work_order_value_parent'));
|
|
$this->assertSame(str_repeat('1', 100), $db->table('ops_work_order_form_value')->value('main_order_no'));
|
|
$migration->down();
|
|
$this->assertFalse($schema->hasIndex('ops_work_order_sub', 'idx_work_order_sub_parent'));
|
|
$this->assertSame(1, $db->table('ops_work_order_sub')->count());
|
|
DB::purge('work_order_index_fixture');
|
|
}
|
|
}
|