Skip to content

Commit 3415990

Browse files
jbrooksukclaude
andauthored
Fix component_id column type in component_checks migration (#388)
Co-authored-by: Claude <noreply@anthropic.com>
1 parent 9785f5d commit 3415990

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

database/migrations/2025_09_14_000000_create_component_checks_table.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ public function up(): void
1313
{
1414
Schema::create('component_checks', function (Blueprint $table) {
1515
$table->id();
16-
$table->foreignId('component_id')->constrained('components')->cascadeOnDelete();
16+
$table->unsignedInteger('component_id');
1717
$table->unsignedTinyInteger('status');
1818
$table->boolean('successful')->default(false);
1919
$table->unsignedSmallInteger('response_code')->nullable();
2020
$table->unsignedInteger('response_time')->nullable();
2121
$table->timestamp('checked_at');
2222
$table->timestamps();
23+
24+
$table->foreign('component_id')->references('id')->on('components')->cascadeOnDelete();
2325
});
2426
}
2527

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\Schema;
4+
5+
it('creates component_id with the same column type as components.id', function () {
6+
$componentsId = collect(Schema::getColumns('components'))->firstWhere('name', 'id');
7+
$componentId = collect(Schema::getColumns('component_checks'))->firstWhere('name', 'component_id');
8+
9+
expect($componentId['type'])->toBe($componentsId['type']);
10+
});
11+
12+
it('constrains component_id to components.id with cascading deletes', function () {
13+
$foreignKey = collect(Schema::getForeignKeys('component_checks'))
14+
->first(fn (array $key) => $key['columns'] === ['component_id']);
15+
16+
expect($foreignKey)->not->toBeNull()
17+
->and($foreignKey['foreign_table'])->toBe('components')
18+
->and($foreignKey['foreign_columns'])->toBe(['id'])
19+
->and(strtolower($foreignKey['on_delete']))->toBe('cascade');
20+
});

0 commit comments

Comments
 (0)