diff --git a/app/Models/Country.php b/app/Models/Country.php new file mode 100644 index 0000000..99c24ff --- /dev/null +++ b/app/Models/Country.php @@ -0,0 +1,12 @@ +id(); + $table->string('name'); + $table->string('country_code', 2)->unique(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('countries'); + } +}; diff --git a/database/migrations/2024_08_04_172521_create_non_working_days.php b/database/migrations/2024_08_04_172521_create_non_working_days.php new file mode 100644 index 0000000..cedc35c --- /dev/null +++ b/database/migrations/2024_08_04_172521_create_non_working_days.php @@ -0,0 +1,31 @@ +id(); + $table->unsignedBigInteger('country_id'); + $table->foreign('country_id')->references('id')->on('countries')->onDelete('cascade'); + $table->date('non_working_date'); + $table->timestamps(); + $table->unique(['country_id', 'non_working_date']); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('non_working_days'); + } +}; diff --git a/database/seeders/CountrySeeder.php b/database/seeders/CountrySeeder.php new file mode 100755 index 0000000..2b12870 --- /dev/null +++ b/database/seeders/CountrySeeder.php @@ -0,0 +1,29 @@ + 'Czech Republic', + ]; + + /** + * Run the database seeds. + */ + public function run(): void + { + foreach (static::COUNTRIES as $countryCode => $countryName) { + try { + Country::create(['country_code' => $countryCode, 'name' => $countryName]); + } catch (UniqueConstraintViolationException $e) { + // safe to ignore duplicate entries + } + } + // + } +}