From 82f3ef39c988021593206101a9a257d7523069eb Mon Sep 17 00:00:00 2001 From: Ondrej Vlach Date: Wed, 7 Aug 2024 12:45:56 +0200 Subject: [PATCH] feat(models): add Country and NonWorkingDays models --- app/Models/Country.php | 12 +++++++ app/Models/NonWorkingDays.php | 12 +++++++ .../2024_08_04_172406_create_countries.php | 29 +++++++++++++++++ ...4_08_04_172521_create_non_working_days.php | 31 +++++++++++++++++++ database/seeders/CountrySeeder.php | 29 +++++++++++++++++ 5 files changed, 113 insertions(+) create mode 100644 app/Models/Country.php create mode 100644 app/Models/NonWorkingDays.php create mode 100644 database/migrations/2024_08_04_172406_create_countries.php create mode 100644 database/migrations/2024_08_04_172521_create_non_working_days.php create mode 100755 database/seeders/CountrySeeder.php 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 + } + } + // + } +}