db2 driver updates

This commit is contained in:
Mark Gregory
2026-11-11 11:11:30 +00:00
parent 984b52f39e
commit 84844311a5
8 changed files with 1051 additions and 4 deletions
@@ -0,0 +1,70 @@
<?php
namespace Tests\Feature\Db2;
use Illuminate\Database\Schema\Blueprint;
class SchemaTypesAndIndexesTest extends Db2TestCase
{
public function test_extended_column_types_round_trip(): void
{
$db = $this->db();
$schema = $db->getSchemaBuilder();
$table = 'stage7_'.bin2hex(random_bytes(6));
try {
$schema->create($table, function (Blueprint $table) {
$table->char('code', 4);
$table->uuid('reference');
$table->time('opens_at');
$table->timestamp('recorded_at', 3);
$table->decimal('amount', 10, 2);
});
$uuid = '42dcb8f9-073a-4359-983f-ab0491c01dc7';
$db->table($table)->insert([
'code' => 'ABCD',
'reference' => $uuid,
'opens_at' => '08:12:30',
'recorded_at' => '2026-11-11 08:12:30.123',
'amount' => '12345678.90',
]);
$columns = array_column($schema->getColumns($table), null, 'name');
$this->assertSame('CHAR(4)', $columns['code']['type']);
$this->assertSame('CHAR(36)', $columns['reference']['type']);
$this->assertSame('TIME', $columns['opens_at']['type_name']);
$this->assertSame('TIMESTAMP(3)', $columns['recorded_at']['type']);
$this->assertSame('DECIMAL(10,2)', $columns['amount']['type']);
$this->assertSame($uuid, $db->table($table)->value('reference'));
$this->assertSame('12345678.90', (string) $db->table($table)->value('amount'));
} finally {
$schema->dropIfExists($table);
}
}
public function test_rename_preserves_a_composite_unique_index(): void
{
$db = $this->db();
$schema = $db->getSchemaBuilder();
$name = 'stage7_'.bin2hex(random_bytes(6));
$table = $db->getConfig('schema').'.'.$name;
try {
$schema->create($table, function (Blueprint $table) use ($name) {
$table->integer('region');
$table->integer('code');
$table->unique(['region', 'code'], $name.'_old');
});
$schema->table($table, fn (Blueprint $table) => $table->renameIndex($name.'_old', $name.'_new'));
$indexes = array_column($schema->getIndexes($table), null, 'name');
$this->assertArrayNotHasKey($name.'_old', $indexes);
$this->assertTrue($indexes[$name.'_new']['unique']);
$this->assertSame(['region', 'code'], $indexes[$name.'_new']['columns']);
$schema->table($table, fn (Blueprint $table) => $table->dropUnique($name.'_new'));
$this->assertFalse($schema->hasIndex($table, $name.'_new'));
} finally {
$schema->dropIfExists($table);
}
}
}