From 5de96bb498fd6a63c8c68dfac68b1fa5b311d502 Mon Sep 17 00:00:00 2001 From: Thombrix Date: Sun, 29 Oct 2023 02:02:45 +0100 Subject: [PATCH] seeders for test data --- ..._28_233754_create_langues_villes_table.php | 8 +-- ...d_ville_fk_langue_fk_to_langues_villes.php | 4 +- .../database/seeders/CantonSeeder.php | 53 +++++++++++++++++++ .../database/seeders/DatabaseSeeder.php | 5 ++ .../database/seeders/LangueSeeder.php | 30 +++++++++++ .../database/seeders/LangueVilleSeeder.php | 33 ++++++++++++ .../database/seeders/VilleSeeder.php | 35 ++++++++++++ 7 files changed, 162 insertions(+), 6 deletions(-) create mode 100644 backend-laravel/database/seeders/CantonSeeder.php create mode 100644 backend-laravel/database/seeders/LangueSeeder.php create mode 100644 backend-laravel/database/seeders/LangueVilleSeeder.php create mode 100644 backend-laravel/database/seeders/VilleSeeder.php diff --git a/backend-laravel/database/migrations/2023_10_28_233754_create_langues_villes_table.php b/backend-laravel/database/migrations/2023_10_28_233754_create_langues_villes_table.php index 0b4df7e..5f72b16 100644 --- a/backend-laravel/database/migrations/2023_10_28_233754_create_langues_villes_table.php +++ b/backend-laravel/database/migrations/2023_10_28_233754_create_langues_villes_table.php @@ -13,10 +13,10 @@ public function up(): void { Schema::create('langues_villes', function (Blueprint $table) { - $table->unsignedBigInteger('author_id'); - $table->unsignedBigInteger('book_id'); - - $table->primary(['author_id', 'book_id']); + $table->unsignedBigInteger('langue_id'); + $table->unsignedBigInteger('ville_id'); + + $table->primary(['langue_id', 'ville_id']); $table->timestamps(); }); diff --git a/backend-laravel/database/migrations/2023_10_28_235532_add_ville_fk_langue_fk_to_langues_villes.php b/backend-laravel/database/migrations/2023_10_28_235532_add_ville_fk_langue_fk_to_langues_villes.php index f0d5c39..ca47419 100644 --- a/backend-laravel/database/migrations/2023_10_28_235532_add_ville_fk_langue_fk_to_langues_villes.php +++ b/backend-laravel/database/migrations/2023_10_28_235532_add_ville_fk_langue_fk_to_langues_villes.php @@ -13,8 +13,8 @@ public function up(): void { Schema::table('langues_villes', function (Blueprint $table) { - $table->foreignId('langue_id')->constrained()->cascadeOnDelete(); - $table->foreignId('ville_id')->constrained()->cascadeOnDelete(); + $table->foreign('langue_id')->references('id')->on('langues')->cascadeOnDelete(); + $table->foreign('ville_id')->references('id')->on('villes')->cascadeOnDelete(); }); } diff --git a/backend-laravel/database/seeders/CantonSeeder.php b/backend-laravel/database/seeders/CantonSeeder.php new file mode 100644 index 0000000..0bd0353 --- /dev/null +++ b/backend-laravel/database/seeders/CantonSeeder.php @@ -0,0 +1,53 @@ + 'Jura', 'img' => 'jura.png'], + ['name' => 'Zurich', 'img' => 'zurich.png'], + ['name' => 'Bern', 'img' => 'bern.png'], + ['name' => 'Lucerne', 'img' => 'lucerne.png'], + ['name' => 'Uri', 'img' => 'uri.png'], + ['name' => 'Schwyz', 'img' => 'schwyz.png'], + ['name' => 'Obwalden', 'img' => 'obwalden.png'], + ['name' => 'Nidwalden', 'img' => 'nidwalden.png'], + ['name' => 'Glarus', 'img' => 'glarus.png'], + ['name' => 'Zug', 'img' => 'zug.png'], + ['name' => 'Fribourg', 'img' => 'fribourg.png'], + ['name' => 'Solothurn', 'img' => 'solothurn.png'], + ['name' => 'Basel-Landschaft', 'img' => 'basel-landschaft.png'], + ['name' => 'Basel-Stadt', 'img' => 'basel-stadt.png'], + ['name' => 'Schaffhausen', 'img' => 'schaffhausen.png'], + ['name' => 'Appenzell Ausserrhoden', 'img' => 'appenzell-ausserrhoden.png'], + ['name' => 'Appenzell Innerrhoden', 'img' => 'appenzell-innerrhoden.png'], + ['name' => 'St. Gallen', 'img' => 'st-gallen.png'], + ['name' => 'Grisons', 'img' => 'grisons.png'], + ['name' => 'Aargau', 'img' => 'aargau.png'], + ['name' => 'Thurgau', 'img' => 'thurgau.png'], + ['name' => 'Ticino', 'img' => 'ticino.png'], + ['name' => 'Vaud', 'img' => 'vaud.png'], + ['name' => 'Valais', 'img' => 'valais.png'], + ['name' => 'Neuchâtel', 'img' => 'neuchatel.png'], + ['name' => 'Geneva', 'img' => 'geneva.png'] + ]; + + foreach ($cantons as $canton) + { + \App\Models\Canton::create(array( + 'name' => $canton["name"], + 'img' => $canton["img"] + )); + } + } +} diff --git a/backend-laravel/database/seeders/DatabaseSeeder.php b/backend-laravel/database/seeders/DatabaseSeeder.php index a9f4519..86b9a75 100644 --- a/backend-laravel/database/seeders/DatabaseSeeder.php +++ b/backend-laravel/database/seeders/DatabaseSeeder.php @@ -18,5 +18,10 @@ public function run(): void // 'name' => 'Test User', // 'email' => 'test@example.com', // ]); + + $this->call(LangueSeeder::class); + $this->call(CantonSeeder::class); + $this->call(VilleSeeder::class); + $this->call(LangueVilleSeeder::class); } } diff --git a/backend-laravel/database/seeders/LangueSeeder.php b/backend-laravel/database/seeders/LangueSeeder.php new file mode 100644 index 0000000..b65c3ee --- /dev/null +++ b/backend-laravel/database/seeders/LangueSeeder.php @@ -0,0 +1,30 @@ + 'Français'], + ['name' => 'Suisse-Allemand'], + ['name' => 'Italien'], + ['name' => 'Romanche'] + ]; + + foreach ($langues as $langue) + { + \App\Models\Langue::create(array( + 'name' => $langue["name"] + )); + } + } +} diff --git a/backend-laravel/database/seeders/LangueVilleSeeder.php b/backend-laravel/database/seeders/LangueVilleSeeder.php new file mode 100644 index 0000000..3046366 --- /dev/null +++ b/backend-laravel/database/seeders/LangueVilleSeeder.php @@ -0,0 +1,33 @@ + 1, 'langue_id' => 1], + ['ville_id' => 2, 'langue_id' => 2], + ['ville_id' => 3, 'langue_id' => 1], + ['ville_id' => 3, 'langue_id' => 2], + ['ville_id' => 4, 'langue_id' => 2] + + ]; + + foreach ($langues_villes as $langue_ville) + { + DB::table('langues_villes')->insert([ + 'ville_id' => $langue_ville['ville_id'], + 'langue_id' => $langue_ville['langue_id'] + ]); + } + } +} diff --git a/backend-laravel/database/seeders/VilleSeeder.php b/backend-laravel/database/seeders/VilleSeeder.php new file mode 100644 index 0000000..1784ae8 --- /dev/null +++ b/backend-laravel/database/seeders/VilleSeeder.php @@ -0,0 +1,35 @@ + 'Lausanne', 'img' => 'lausanne.png', 'ecusson' => 'lausanne-ecu.png', 'population' => 140000, 'coord' => '46.519961, 6.633597', 'canton_id' => 23], + ['name' => 'Zurich', 'img' => 'zurich.png', 'ecusson' => 'zurich-ecu.png', 'population' => 400000, 'coord' => '47.376886, 8.541694', 'canton_id' => 2], + ['name' => 'Bern', 'img' => 'bern.png', 'ecusson' => 'bern-ecu.png', 'population' => 130000, 'coord' => '46.948020, 7.447433', 'canton_id' => 3], + ['name' => 'Lucerne', 'img' => 'lucerne.png', 'ecusson' => 'lucerne-ecu.png', 'population' => 82000, 'coord' => '47.050168, 8.309307', 'canton_id' => 4] + ]; + + foreach ($cities as $city) + { + \App\Models\Ville::create(array( + 'name' => $city["name"], + 'img' => $city["img"], + 'ecusson' => $city["ecusson"], + 'population' => $city["population"], + 'coord' => $city["coord"], + 'canton_id' => $city["canton_id"] + )); + } + + } +}