diff --git a/database/migrations/2026_05_03_100100_create_labels_table.php b/database/migrations/2026_05_03_100100_create_labels_table.php new file mode 100644 index 0000000..1eccceb --- /dev/null +++ b/database/migrations/2026_05_03_100100_create_labels_table.php @@ -0,0 +1,24 @@ +id(); + $table->string('name')->unique(); + $table->string('color', 7)->nullable(); + $table->timestamp('hidden_at')->nullable(); + $table->timestamp('last_imported_at')->nullable(); + $table->timestamps(); + }); + } + + public function down(): void + { + Schema::dropIfExists('labels'); + } +}; diff --git a/tests/Feature/Migrations/LabelsTableTest.php b/tests/Feature/Migrations/LabelsTableTest.php new file mode 100644 index 0000000..d106a9e --- /dev/null +++ b/tests/Feature/Migrations/LabelsTableTest.php @@ -0,0 +1,22 @@ +toBeTrue(); + expect(Schema::hasColumns('labels', ['id', 'name', 'color', 'hidden_at', 'last_imported_at', 'created_at', 'updated_at']))->toBeTrue(); +}); + +test('labels table enforces unique name', function () { + DB::table('labels')->insert(['name' => 'Vers 1', 'color' => '#FF0080', 'created_at' => now(), 'updated_at' => now()]); + + expect(fn () => DB::table('labels')->insert(['name' => 'Vers 1', 'color' => '#000000', 'created_at' => now(), 'updated_at' => now()])) + ->toThrow(\Exception::class); +}); + +test('labels table allows nullable color', function () { + DB::table('labels')->insert(['name' => 'TestLabel', 'color' => null, 'created_at' => now(), 'updated_at' => now()]); + + expect(DB::table('labels')->where('name', 'TestLabel')->value('color'))->toBeNull(); +});