diff --git a/database/migrations/2025_09_14_000000_create_component_checks_table.php b/database/migrations/2025_09_14_000000_create_component_checks_table.php index ec78651f..4f3d92d4 100644 --- a/database/migrations/2025_09_14_000000_create_component_checks_table.php +++ b/database/migrations/2025_09_14_000000_create_component_checks_table.php @@ -13,13 +13,15 @@ public function up(): void { Schema::create('component_checks', function (Blueprint $table) { $table->id(); - $table->foreignId('component_id')->constrained('components')->cascadeOnDelete(); + $table->unsignedInteger('component_id'); $table->unsignedTinyInteger('status'); $table->boolean('successful')->default(false); $table->unsignedSmallInteger('response_code')->nullable(); $table->unsignedInteger('response_time')->nullable(); $table->timestamp('checked_at'); $table->timestamps(); + + $table->foreign('component_id')->references('id')->on('components')->cascadeOnDelete(); }); } diff --git a/tests/Unit/Migrations/CreateComponentChecksTableTest.php b/tests/Unit/Migrations/CreateComponentChecksTableTest.php new file mode 100644 index 00000000..cd7b34dc --- /dev/null +++ b/tests/Unit/Migrations/CreateComponentChecksTableTest.php @@ -0,0 +1,34 @@ +once() + ->with('component_checks', \Mockery::on(function (callable $callback) use (&$sql): bool { + $connection = new MySqlConnection(new \PDO('sqlite::memory:'), 'testing'); + $grammar = new MySqlGrammar($connection); + $blueprint = new Blueprint('component_checks'); + + $blueprint->create(); + $callback($blueprint); + + $sql = $blueprint->toSql($connection, $grammar); + + return true; + })); + + $migration->up(); + + $compiledSql = implode("\n", $sql); + + expect($compiledSql) + ->toContain('`component_id` int unsigned not null') + ->not->toContain('`component_id` bigint unsigned not null'); +});