From 1c0f225afa1da58cfdeea3fbaeb753776f68b2c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Munsch?= Date: Wed, 9 Mar 2022 10:54:00 +0100 Subject: [PATCH] Create migrations + some Cleanup code --- app/Console/Commands/ImportMoba.php | 6 +- app/Console/Commands/MajEleveurs.php | 4 +- app/Http/Controllers/AjaxController.php | 6 +- .../Auth/ConfirmPasswordController.php | 10 -- .../Auth/ForgotPasswordController.php | 10 -- app/Http/Controllers/Auth/LoginController.php | 17 +- .../Controllers/Auth/RegisterController.php | 12 +- .../Auth/ResetPasswordController.php | 10 -- .../Auth/VerificationController.php | 10 -- app/Http/Controllers/EleveurController.php | 4 +- app/Http/Controllers/FrontController.php | 13 +- app/Models/MiseEnPlace.php | 7 +- app/Models/Moba.php | 17 -- app/Models/TracaOeuf.php | 28 +++ app/Models/TracaVolaille.php | 15 ++ app/Models/VisuelLibelle.php | 1 - .../2014_10_12_000000_create_users_table.php | 21 ++- ...12_100000_create_password_resets_table.php | 12 +- ..._08_19_000000_create_failed_jobs_table.php | 18 +- .../2022_03_08_094906_create_jobs_table.php | 38 +++++ ...022_03_08_094949_create_aliments_table.php | 52 ++++++ ...022_03_08_100744_create_eleveurs_table.php | 159 ++++++++++++++++++ ..._03_08_121533_create_traca_oeufs_table.php | 99 +++++++++++ ...08_121548_create_traca_volailles_table.php | 73 ++++++++ ...08_155517_create_visuel_libelles_table.php | 62 +++++++ ..._08_160855_create_mise_en_places_table.php | 82 +++++++++ 26 files changed, 662 insertions(+), 124 deletions(-) delete mode 100644 app/Models/Moba.php create mode 100644 app/Models/TracaOeuf.php create mode 100644 app/Models/TracaVolaille.php create mode 100644 database/migrations/2022_03_08_094906_create_jobs_table.php create mode 100644 database/migrations/2022_03_08_094949_create_aliments_table.php create mode 100644 database/migrations/2022_03_08_100744_create_eleveurs_table.php create mode 100644 database/migrations/2022_03_08_121533_create_traca_oeufs_table.php create mode 100644 database/migrations/2022_03_08_121548_create_traca_volailles_table.php create mode 100644 database/migrations/2022_03_08_155517_create_visuel_libelles_table.php create mode 100644 database/migrations/2022_03_08_160855_create_mise_en_places_table.php diff --git a/app/Console/Commands/ImportMoba.php b/app/Console/Commands/ImportMoba.php index d6b0638..a050c9a 100644 --- a/app/Console/Commands/ImportMoba.php +++ b/app/Console/Commands/ImportMoba.php @@ -66,7 +66,7 @@ class ImportMoba extends Command $code_boite = $data[0]; $code_ede = $data[1]; // format dans le fichier Y-m-d - $date_ponte = $data[2]; + $date_de_ponte = $data[2]; $code_produit = $data[3]; $libelle_produit = $data[4]; $lot_externe = $data[5]; @@ -77,13 +77,13 @@ class ImportMoba extends Command $moba = new Moba(); $moba->code_boite = $code_boite; $moba->code_ede = $code_ede; - $moba->date_ponte = $date_ponte; + $moba->date_de_ponte = $date_de_ponte; $moba->code_produit = $code_produit; $moba->libelle_produit = $libelle_produit; $moba->lot_externe = $lot_externe; $moba->dcr = $dcr; $moba->date_emballage = $date_emballage; - $moba->ean13 = $ean; + $moba->ean_13 = $ean; $moba->save(); $lines++; diff --git a/app/Console/Commands/MajEleveurs.php b/app/Console/Commands/MajEleveurs.php index 131828f..b70b633 100644 --- a/app/Console/Commands/MajEleveurs.php +++ b/app/Console/Commands/MajEleveurs.php @@ -53,8 +53,8 @@ class MajEleveurs extends Command } $line++; $code_boite = $data[0]; - $ean13 = $data[7]; - $mobas = Moba::where('code_boite', '=', $code_boite)->andWhere('ean13', '=', '')->update(['ean13' => $data[7]]); + $ean_13 = $data[7]; + $mobas = Moba::where('code_boite', '=', $code_boite)->andWhere('ean_13', '=', '')->update(['ean_13' => $data[7]]); echo $line . "\n\r"; } } diff --git a/app/Http/Controllers/AjaxController.php b/app/Http/Controllers/AjaxController.php index 9358605..84a3762 100644 --- a/app/Http/Controllers/AjaxController.php +++ b/app/Http/Controllers/AjaxController.php @@ -6,7 +6,7 @@ use Illuminate\Http\Request; use App\Models\MiseEnPlace; use App\Models\Aliment; use App\Models\Eleveur; -use App\Models\Moba; +use App\TracaOeuf; use Carbon\Carbon; class AjaxController extends Controller @@ -76,7 +76,7 @@ class AjaxController extends Controller } else { if (strpos($data[7], "/") !== false && strpos($data[8], "/") !== false) { $mep = new MiseEnPlace(); - $mep->eleveurId_pondeuse = $eleveur->id; + $mep->eleveur_id = $eleveur->id; $mep->code_lot_pondeuse = $data[6]; $mep->hectares_parcours_pondeuse = $data[20]; switch ($data[21]) { @@ -159,7 +159,7 @@ class AjaxController extends Controller $year = $dateCarbon['year']; $dcr = $year . '-' . $month . '-' . $day; - $moba = Moba::where(['code_ede' => $code, 'dcr' => $dcr])->orderBy('id', 'DESC')->first(); + $moba = TracaOeuf::where(['code_ede' => $code, 'dcr' => $dcr])->orderBy('id', 'DESC')->first(); if (!$moba) { return redirect()->route('erreur404'); diff --git a/app/Http/Controllers/Auth/ConfirmPasswordController.php b/app/Http/Controllers/Auth/ConfirmPasswordController.php index 7bed2bd..ef21052 100644 --- a/app/Http/Controllers/Auth/ConfirmPasswordController.php +++ b/app/Http/Controllers/Auth/ConfirmPasswordController.php @@ -7,16 +7,6 @@ use Illuminate\Foundation\Auth\ConfirmsPasswords; class ConfirmPasswordController extends Controller { - /* - |-------------------------------------------------------------------------- - | Confirm Password Controller - |-------------------------------------------------------------------------- - | - | This controller is responsible for handling password confirmations and - | uses a simple trait to include the behavior. You're free to explore - | this trait and override any functions that require customization. - | - */ use ConfirmsPasswords; /** diff --git a/app/Http/Controllers/Auth/ForgotPasswordController.php b/app/Http/Controllers/Auth/ForgotPasswordController.php index 75ef4e6..6f46b42 100644 --- a/app/Http/Controllers/Auth/ForgotPasswordController.php +++ b/app/Http/Controllers/Auth/ForgotPasswordController.php @@ -7,15 +7,5 @@ use Illuminate\Foundation\Auth\SendsPasswordResetEmails; class ForgotPasswordController extends Controller { - /* - |-------------------------------------------------------------------------- - | Password Reset Controller - |-------------------------------------------------------------------------- - | - | This controller is responsible for handling password reset emails and - | includes a trait which assists in sending these notifications from - | your application to your users. Feel free to explore this trait. - | - */ use SendsPasswordResetEmails; } diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index c917a7e..cbb62c7 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -7,16 +7,6 @@ use Illuminate\Foundation\Auth\AuthenticatesUsers; class LoginController extends Controller { - /* - |-------------------------------------------------------------------------- - | Login Controller - |-------------------------------------------------------------------------- - | - | This controller handles authenticating users for the application and - | redirecting them to your home screen. The controller uses a trait - | to conveniently provide its functionality to your applications. - | - */ use AuthenticatesUsers; /** @@ -36,7 +26,12 @@ class LoginController extends Controller $this->middleware('guest')->except('logout'); } - public function username() + /** + * Get user name column + * + * @return string + */ + public function username(): string { return 'username'; } diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php index 908fc35..e3b0151 100644 --- a/app/Http/Controllers/Auth/RegisterController.php +++ b/app/Http/Controllers/Auth/RegisterController.php @@ -3,23 +3,13 @@ namespace App\Http\Controllers\Auth; use App\Http\Controllers\Controller; -use App\User; +use App\Models\User; use Illuminate\Foundation\Auth\RegistersUsers; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Validator; class RegisterController extends Controller { - /* - |-------------------------------------------------------------------------- - | Register Controller - |-------------------------------------------------------------------------- - | - | This controller handles the registration of new users as well as their - | validation and creation. By default this controller uses a trait to - | provide this functionality without requiring any additional code. - | - */ use RegistersUsers; /** diff --git a/app/Http/Controllers/Auth/ResetPasswordController.php b/app/Http/Controllers/Auth/ResetPasswordController.php index f0df4df..8058d1b 100644 --- a/app/Http/Controllers/Auth/ResetPasswordController.php +++ b/app/Http/Controllers/Auth/ResetPasswordController.php @@ -7,16 +7,6 @@ use Illuminate\Foundation\Auth\ResetsPasswords; class ResetPasswordController extends Controller { - /* - |-------------------------------------------------------------------------- - | Password Reset Controller - |-------------------------------------------------------------------------- - | - | This controller is responsible for handling password reset requests - | and uses a simple trait to include this behavior. You're free to - | explore this trait and override any methods you wish to tweak. - | - */ use ResetsPasswords; /** diff --git a/app/Http/Controllers/Auth/VerificationController.php b/app/Http/Controllers/Auth/VerificationController.php index b3459cb..7b9c942 100644 --- a/app/Http/Controllers/Auth/VerificationController.php +++ b/app/Http/Controllers/Auth/VerificationController.php @@ -7,16 +7,6 @@ use Illuminate\Foundation\Auth\VerifiesEmails; class VerificationController extends Controller { - /* - |-------------------------------------------------------------------------- - | Email Verification Controller - |-------------------------------------------------------------------------- - | - | This controller is responsible for handling email verification for any - | user that recently registered with the application. Emails may also - | be re-sent if the user didn't receive the original email message. - | - */ use VerifiesEmails; /** diff --git a/app/Http/Controllers/EleveurController.php b/app/Http/Controllers/EleveurController.php index f1ffe2c..dc459ce 100644 --- a/app/Http/Controllers/EleveurController.php +++ b/app/Http/Controllers/EleveurController.php @@ -4,7 +4,7 @@ namespace App\Http\Controllers; use App\Models\Eleveur; use App\Http\Requests\MyRequest; -use Response; +use Illuminate\Support\Facades\Response; class EleveurController extends Controller { @@ -174,7 +174,7 @@ class EleveurController extends Controller $callback = function () use ($eleveurs, $columns) { $file = fopen('php://output', 'w'); fputs($file, "\xEF\xBB\xBF"); -// use BOM for Office + // * use BOM for Office fputcsv($file, $columns, ";"); foreach ($eleveurs as $eleveur) { diff --git a/app/Http/Controllers/FrontController.php b/app/Http/Controllers/FrontController.php index 2d8c531..ae0ffcb 100644 --- a/app/Http/Controllers/FrontController.php +++ b/app/Http/Controllers/FrontController.php @@ -6,6 +6,7 @@ use App\Models\Eleveur; use App\Models\Aliment; use App\Models\MiseEnPlace; use App\Models\Moba; +use App\TracaOeuf; use App\VisuelLibelle; use Carbon\Carbon; @@ -14,7 +15,7 @@ class FrontController extends Controller public function indexId($id) { $multiple = false; - $mobas = Moba::where('code_boite', $id)->orderBy('id', 'DESC')->first(); + $mobas = TracaOeuf::where('code_boite', $id)->orderBy('id', 'DESC')->first(); if (!$mobas) { return redirect('/search'); @@ -22,7 +23,7 @@ class FrontController extends Controller $edes = $mobas->code_edes; - // check if Bio or not + // * check if Bio or not $code_ede = $mobas->code_ede; $code_prod = substr($code_ede, 0, 1); @@ -32,10 +33,10 @@ class FrontController extends Controller session(['subColor' => 'blue']); } - $datePonte = $mobas->date_ponte; + $datePonte = $mobas->date_de_ponte; $dcr = $mobas->dcr; $date_emballage = $mobas->date_emballage; - // Compare DCR et Today + // * Compare DCR et Today $date_dcr = Carbon::createFromFormat('Y-m-d', $dcr); $date_today = Carbon::now(); $dcrGood = $date_today < $date_dcr; @@ -52,14 +53,14 @@ class FrontController extends Controller $elevId = $eleveurs->pluck('id'); - $mep = MiseEnPlace::whereIn('eleveurId_pondeuse', $elevId)->where('date_transfert_poulettes', '<', $datePonte)->orderBy('id', 'DESC')->first(); + $mep = MiseEnPlace::whereIn('eleveur_id', $elevId)->where('date_transfert_poulettes', '<', $datePonte)->orderBy('id', 'DESC')->first(); if ($mep) { $aliment = Aliment::where('code_lot', $mep->code_lot_pondeuse)->orderBy('id', 'DESC')->first(); } else { $mep = ''; $aliment = ""; } - $dataVisuel = VisuelLibelle::where('ean13', $mobas->ean13)->first(); + $dataVisuel = VisuelLibelle::where('ean_13', $mobas->ean_13)->first(); return view('themes.loue.index_id', [ 'id' => $id, diff --git a/app/Models/MiseEnPlace.php b/app/Models/MiseEnPlace.php index 5cd0022..b4a7488 100644 --- a/app/Models/MiseEnPlace.php +++ b/app/Models/MiseEnPlace.php @@ -13,18 +13,13 @@ class MiseEnPlace extends Model */ public $timestamps = false; - /** - * @var string - */ - protected $table = 'mise_en_place'; - /** * The attributes that are mass assignable. * * @var array */ protected $fillable = [ - 'eleveurId_pondeuse', + 'eleveur_id', 'code_lot_pondeuse', 'hectares_parcours_pondeuse', 'presence_ruche_pondeuse', diff --git a/app/Models/Moba.php b/app/Models/Moba.php deleted file mode 100644 index ab42ddf..0000000 --- a/app/Models/Moba.php +++ /dev/null @@ -1,17 +0,0 @@ -where('code_boite', $this->code_boite)->distinct()->get()->pluck('code_ede'); - } -} diff --git a/app/Models/TracaOeuf.php b/app/Models/TracaOeuf.php new file mode 100644 index 0000000..7a74415 --- /dev/null +++ b/app/Models/TracaOeuf.php @@ -0,0 +1,28 @@ +where('code_boite', $this->code_boite) + ->distinct()->get()->pluck('code_ede'); + } +} diff --git a/app/Models/TracaVolaille.php b/app/Models/TracaVolaille.php new file mode 100644 index 0000000..ab0ccb6 --- /dev/null +++ b/app/Models/TracaVolaille.php @@ -0,0 +1,15 @@ +bigIncrements('id'); - $table->string('name'); - $table->string('email')->unique(); - $table->timestamp('email_verified_at')->nullable(); - $table->string('password'); - $table->rememberToken(); - $table->timestamps(); - }); + if (!Schema::hasTable('users')) { + Schema::create('users', function (Blueprint $table) { + $table->bigIncrements('id'); + $table->string('name'); + $table->string('username')->unique(); + $table->string('email')->unique(); + $table->timestamp('email_verified_at')->nullable(); + $table->string('password'); + $table->rememberToken(); + $table->timestamps(); + }); + } } /** diff --git a/database/migrations/2014_10_12_100000_create_password_resets_table.php b/database/migrations/2014_10_12_100000_create_password_resets_table.php index 0ee0a36..ff6db56 100644 --- a/database/migrations/2014_10_12_100000_create_password_resets_table.php +++ b/database/migrations/2014_10_12_100000_create_password_resets_table.php @@ -13,11 +13,13 @@ class CreatePasswordResetsTable extends Migration */ public function up() { - Schema::create('password_resets', function (Blueprint $table) { - $table->string('email')->index(); - $table->string('token'); - $table->timestamp('created_at')->nullable(); - }); + if (!Schema::hasTable('users')) { + Schema::create('password_resets', function (Blueprint $table) { + $table->string('email')->index(); + $table->string('token'); + $table->timestamp('created_at')->nullable(); + }); + } } /** diff --git a/database/migrations/2019_08_19_000000_create_failed_jobs_table.php b/database/migrations/2019_08_19_000000_create_failed_jobs_table.php index 389bdf7..2ae259f 100644 --- a/database/migrations/2019_08_19_000000_create_failed_jobs_table.php +++ b/database/migrations/2019_08_19_000000_create_failed_jobs_table.php @@ -13,14 +13,16 @@ class CreateFailedJobsTable extends Migration */ public function up() { - Schema::create('failed_jobs', function (Blueprint $table) { - $table->bigIncrements('id'); - $table->text('connection'); - $table->text('queue'); - $table->longText('payload'); - $table->longText('exception'); - $table->timestamp('failed_at')->useCurrent(); - }); + if (!Schema::hasTable('users')) { + Schema::create('failed_jobs', function (Blueprint $table) { + $table->bigIncrements('id'); + $table->text('connection'); + $table->text('queue'); + $table->longText('payload'); + $table->longText('exception'); + $table->timestamp('failed_at')->useCurrent(); + }); + } } /** diff --git a/database/migrations/2022_03_08_094906_create_jobs_table.php b/database/migrations/2022_03_08_094906_create_jobs_table.php new file mode 100644 index 0000000..28f4b20 --- /dev/null +++ b/database/migrations/2022_03_08_094906_create_jobs_table.php @@ -0,0 +1,38 @@ +bigIncrements('id'); + $table->string('queue')->index(); + $table->longText('payload'); + $table->unsignedTinyInteger('attempts'); + $table->unsignedInteger('reserved_at')->nullable(); + $table->unsignedInteger('available_at'); + $table->unsignedInteger('created_at'); + }); + } + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('jobs'); + } +} diff --git a/database/migrations/2022_03_08_094949_create_aliments_table.php b/database/migrations/2022_03_08_094949_create_aliments_table.php new file mode 100644 index 0000000..dd1cc98 --- /dev/null +++ b/database/migrations/2022_03_08_094949_create_aliments_table.php @@ -0,0 +1,52 @@ +id(); + + $table->string('code_lot', 50)->nullable() + ->comment('Code du lot d\'aliment'); + $table->date('date_livraison')->nullable() + ->comment('Date de livraison de l\'aliment'); + $table->string('type_aliment', 50)->nullable() + ->comment('le type de l\'aliment'); + }); + } else { + Schema::table('aliments', function (Blueprint $table) { + $table->string('code_lot', 50)->nullable() + ->comment('Code du lot d\'aliment')->change(); + $table->date('date_livraison')->nullable() + ->comment('Date de livraison de l\'aliment')->change(); + $table->string('type_aliment', 50)->nullable() + ->comment('le type de l\'aliment')->change(); + }); + } //end if + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('aliments'); + } +} diff --git a/database/migrations/2022_03_08_100744_create_eleveurs_table.php b/database/migrations/2022_03_08_100744_create_eleveurs_table.php new file mode 100644 index 0000000..e6a15f9 --- /dev/null +++ b/database/migrations/2022_03_08_100744_create_eleveurs_table.php @@ -0,0 +1,159 @@ +id(); + + $table->string('code_cafel', 100)->nullable() + ->comment('Code CAFEL de l\'éleveur'); + $table->string('code_ede', 100) + ->comment('Code EDE de l\'éleveur'); + + // TODO: replace this with kwaadpepper/enum. + $table->unsignedTinyInteger('civilite')->default(0) + ->comment('Civilité de l\'éleveur, enum Civility'); + + $table->string('nom') + ->comment('Nom de l\'éleveur'); + $table->string('prenom') + ->comment('Prénom de l\'éleveur'); + $table->date('naissance') + ->comment('Date de naissance de l\'éleveur'); + $table->unsignedMediumInteger('cp') + ->comment('Code postal de l\'éleveur'); + $table->string('ville') + ->comment('Ville de l\'éleveur'); + + $table->date('elv_date_debut')->nullable() + ->comment('Date de début d\'activité de l\'éleveur'); + $table->string('code_inuav', 10) + ->comment('Code INUAV de l\'éleveur (élevage)'); + $table->text('exploitation')->nullable() + ->comment('Description de l\'exploitation de l\'éleveur'); + $table->text('aboutyou')->nullable() + ->comment('À propos de l\'éleveur'); + $table->text('vocation')->nullable() + ->comment('À propos de la vocation de l\'éleveur'); + $table->text('likeinjob')->nullable() + ->comment('L\'atrait de l\'éleveur pour son métier'); + $table->text('loue_means')->nullable() + ->comment('Description de la marque par l\'éleveur'); + + $table->string('path_photo1')->nullable() + ->comment('Photo 1 de l\'éleveur'); + $table->string('path_photo2')->nullable() + ->comment('Photo 2 de l\'éleveur'); + + $table->string('marquage_oeuf', 12)->nullable() + ->comment('Marquage sur l\'oeuf de l\'éleveur'); + $table->string('marquage_b1', 14)->nullable() + ->comment('Marquage sur l\'oeuf de l\'éleveur'); + $table->string('marquage_b2', 14)->nullable() + ->comment('Marquage sur l\'oeuf de l\'éleveur'); + + // * Deleted_at column. + $table->softDeletes(); + }); + } else { + Schema::table('mise_en_place', function (Blueprint $table) { + $table->dropForeign('FK_mise_en_place_eleveurs'); + }); + DB::statement( + 'ALTER TABLE `eleveurs` CHANGE COLUMN `id` `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT FIRST;' + ); + $eleveurs = Eleveur::all(['id', 'civilite', 'cp', 'elv_date_debut', 'naissance']); + Schema::table('eleveurs', function (Blueprint $table) { + $table->string('code_cafel', 100)->nullable() + ->comment('Code CAFEL de l\'éleveur')->change(); + $table->string('code_ede', 100) + ->comment('Code EDE de l\'éleveur')->change(); + + $table->string('nom') + ->comment('Nom de l\'éleveur')->change(); + $table->string('prenom') + ->comment('Prénom de l\'éleveur')->change(); + $table->string('ville') + ->comment('Ville de l\'éleveur')->change(); + + $table->string('code_inuav', 10) + ->comment('Code INUAV de l\'éleveur (élevage)')->change(); + $table->text('exploitation')->nullable() + ->comment('Description de l\'exploitation de l\'éleveur')->change(); + $table->text('aboutyou')->nullable() + ->comment('À propos de l\'éleveur')->change(); + $table->text('vocation')->nullable() + ->comment('À propos de la vocation de l\'éleveur')->change(); + $table->text('likeinjob')->nullable() + ->comment('L\'atrait de l\'éleveur pour son métier')->change(); + $table->text('loue_means')->nullable() + ->comment('Description de la marque par l\'éleveur')->change(); + + $table->string('path_photo1')->nullable() + ->comment('Photo 1 de l\'éleveur')->change(); + $table->string('path_photo2')->nullable() + ->comment('Photo 2 de l\'éleveur')->change(); + + $table->string('marquage_oeuf', 12)->nullable() + ->comment('Marquage sur l\'oeuf de l\'éleveur')->change(); + $table->string('marquage_b1', 14)->nullable() + ->comment('Marquage sur l\'oeuf de l\'éleveur')->change(); + $table->string('marquage_b2', 14)->nullable() + ->comment('Marquage sur l\'oeuf de l\'éleveur')->change(); + }); + Schema::table('eleveurs', function (Blueprint $table) { + $table->dropColumn(['naissance']); + $table->dropColumn(['civilite']); + $table->dropColumn(['cp']); + $table->dropColumn(['elv_date_debut']); + }); + Schema::table('eleveurs', function (Blueprint $table) { + $table->unsignedTinyInteger('civilite')->default(0) + ->comment('Civilité de l\'éleveur, enum Civility') + ->after('code_ede'); + $table->date('naissance')->default('2000/01/01') + ->comment('Date de naissance de l\'éleveur') + ->after('prenom'); + $table->unsignedMediumInteger('cp')->default(0) + ->comment('Code postal de l\'éleveur') + ->after('naissance'); + $table->date('elv_date_debut')->nullable() + ->comment('Date de début d\'activité de l\'éleveur') + ->after('ville'); + }); + $eleveurs->map(function (Eleveur $eleveur) { + $eleveur->naissance = Carbon::createFromFormat('d/m/Y', $eleveur->naissance); + $eleveur->elv_date_debut = Carbon::createFromFormat('d/m/Y', strlen($eleveur->elv_date_debut) ? + $eleveur->elv_date_debut : '01/01/2000'); + $eleveur->civilite = intval($eleveur->civilite); + $eleveur->cp = intval($eleveur->cp); + $eleveur->saveOrFail(); + }); + } //end if + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('eleveurs'); + } +} diff --git a/database/migrations/2022_03_08_121533_create_traca_oeufs_table.php b/database/migrations/2022_03_08_121533_create_traca_oeufs_table.php new file mode 100644 index 0000000..d7de4c4 --- /dev/null +++ b/database/migrations/2022_03_08_121533_create_traca_oeufs_table.php @@ -0,0 +1,99 @@ +id(); + $table->unsignedBigInteger('code_boite') + ->index() + ->comment('Le code de la boite d\'oeufs xs:integer [0-9]{9}|[0-9]{10}'); + $table->string('code_ede', 10) + ->index() + ->comment('Le code EDE xs:string length 8'); + $table->string('code_produit', 14) + ->comment('Le code produit xs:string [0-9]{8}.[0-9]{3}'); + $table->string('libelle_produit', 38) + ->comment('Le libellé du produit xs:string length 35'); + $table->unsignedBigInteger('lot_externe') + ->index() + ->comment('Pas de description xs:integer [0-9]{6}|[0-9]{12}'); + $table->unsignedBigInteger('ean_13') + ->index() + ->comment('Pas de description xs:integer [0-9]{6}|[0-9]{12}'); + $table->date('date_de_ponte') + ->comment('Le date de ponte xs:date'); + $table->date('dcr') + ->comment('Date dcr ? xs:date'); + }); + } else { + DB::statement( + 'ALTER TABLE `traca_oeufs` CHANGE COLUMN `id` `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT FIRST;' + ); + // ! Sanitize column data code boite + DB::table('traca_oeufs') + ->where('code_boite', 'not regexp', '^[0-9]+$')->get() + ->map(function (object $line) { + DB::table('traca_oeufs') + ->where('id', '=', $line->id) + ->update(['code_boite' => intval($line->code_boite)]); + }); + Schema::table('traca_oeufs', function (Blueprint $table) { + $table->renameColumn('ean13', 'ean_13'); + $table->renameColumn('date_ponte', 'date_de_ponte'); + }); + Schema::table('traca_oeufs', function (Blueprint $table) { + $table->dropColumn(['date_emballage']); + $table->unsignedBigInteger('code_boite') + ->index() + ->comment('Le code de la boite d\'oeufs xs:integer [0-9]{9}|[0-9]{10}') + ->change(); + $table->string('code_ede', 10) + ->comment('Le code EDE xs:string length 8') + ->change(); + $table->string('code_produit', 14) + ->comment('Le code produit xs:string [0-9]{8}.[0-9]{3}') + ->change(); + $table->string('libelle_produit', 38) + ->comment('Le libellé du produit xs:string length 35') + ->change(); + $table->unsignedBigInteger('lot_externe') + ->index() + ->comment('Pas de description xs:integer [0-9]{6}|[0-9]{12}') + ->change(); + $table->unsignedBigInteger('ean_13') + ->index() + ->comment('Code ean 13 xs:integer [0-9]{13}') + ->change(); + $table->date('dcr') + ->comment('Date dcr ? xs:date') + ->change(); + }); + } //end if + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('traca_oeufs'); + } +} diff --git a/database/migrations/2022_03_08_121548_create_traca_volailles_table.php b/database/migrations/2022_03_08_121548_create_traca_volailles_table.php new file mode 100644 index 0000000..55ce3c4 --- /dev/null +++ b/database/migrations/2022_03_08_121548_create_traca_volailles_table.php @@ -0,0 +1,73 @@ +id(); + + $table->string('code_art', 14) + ->comment('Code article xs:string [0-9]{8}(\.[0-9]{3})?'); + $table->string('article', 38) + ->comment('Libellé article xs:string length 35'); + $table->string('lot_code_externe', 12) + ->comment('Lot de provenance xs:string length 10'); + $table->string('code_eleveur', 13) + ->comment('Code éleveur xs:string length 11'); + + $table->unsignedSmallInteger('num_commande') + ->index() + ->comment('Numéro de commande xs:int [0-9]{6}'); + + $table->unsignedMediumInteger('lot_opa')->nullable() + ->index() + ->comment('Lot OPA xs:string [*]{0}|[0-9][0-9]{5} (soit chaine vide, soit integer)'); + + $table->unsignedInteger('gencod_prix')->nullable() + ->index() + ->comment('Gencode prix xs:string [*]{0}|[0-9]{7} (soit chaine vide, soit integer)'); + $table->unsignedInteger('gencod_poids')->nullable() + ->index() + ->comment('Gencode poids xs:string [*]{0}|[0-9]{7} (soit chaine vide, soit integer)'); + + $table->unsignedBigInteger('lot_abattoir') + ->index() + ->comment('Numéro de lot de l\'abattoir xs:int [0-9]{9}'); + $table->unsignedBigInteger('client_commande') + ->index() + ->comment('Client numéro de commande'); + + $table->string('enseigne', 34) + ->comment('Nom enseigne'); + $table->string('marque', 34) + ->comment('Nom marque'); + $table->string('famille', 34) + ->comment('Nom famille'); + + $table->date('date_expe') + ->comment('Date d\'expédition xs:date'); + $table->date('date_de_prep') + ->comment('Date de préparation xs:date'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('traca_volailles'); + } +} diff --git a/database/migrations/2022_03_08_155517_create_visuel_libelles_table.php b/database/migrations/2022_03_08_155517_create_visuel_libelles_table.php new file mode 100644 index 0000000..aeb171d --- /dev/null +++ b/database/migrations/2022_03_08_155517_create_visuel_libelles_table.php @@ -0,0 +1,62 @@ +id(); + $table->unsignedBigInteger('ean_13') + ->index() + ->comment('Code ean 13'); + $table->string('libelle') + ->comment('Libellé'); + $table->string('path') + ->comment('Chemin relatif vers l\'image.'); + }); + } else { + DB::statement( + 'ALTER TABLE `visuel_libelles` CHANGE COLUMN `id` `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT FIRST;' + ); + Schema::table('visuel_libelles', function (Blueprint $table) { + $table->renameColumn('ean13', 'ean_13'); + }); + Schema::table('visuel_libelles', function (Blueprint $table) { + $table->unsignedBigInteger('ean_13') + ->index() + ->comment('Code ean 13') + ->change(); + $table->string('libelle') + ->comment('Libellé') + ->change(); + $table->string('path') + ->comment('Chemin relatif vers l\'image.') + ->change(); + }); + } //end if + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('visuel_libelles'); + } +} diff --git a/database/migrations/2022_03_08_160855_create_mise_en_places_table.php b/database/migrations/2022_03_08_160855_create_mise_en_places_table.php new file mode 100644 index 0000000..aea13eb --- /dev/null +++ b/database/migrations/2022_03_08_160855_create_mise_en_places_table.php @@ -0,0 +1,82 @@ +id(); + + $table->string('code_lot_pondeuse', 50) + ->nullable(); + $table->unsignedTinyInteger('hectares_parcours_pondeuse') + ->nullable(); + $table->unsignedTinyInteger('presence_ruche_pondeuse') + ->nullable(); + $table->unsignedTinyInteger('zone_mellifere_pondeuse') + ->nullable(); + + $table->string('nom_couvoir')->nullable(); + $table->string('ville_couvoir')->nullable(); + $table->string('cp_couvoir')->nullable(); + $table->string('raison_sociale_eleveur_poulettes')->nullable(); + $table->string('code_inuav_poulettes')->nullable(); + $table->string('nom_eleveur_poulettes')->nullable(); + $table->string('prenom_eleveur_poulettes')->nullable(); + $table->string('ville_eleveur_poulettes')->nullable(); + $table->string('cp_eleveur_poulettes')->nullable(); + + $table->date('date_naissance_poulettes')->nullable(); + $table->date('date_transfert_poulettes')->nullable(); + + $table->foreignIdFor(Eleveur::class) + ->comment('Clé étrangère éleveur id'); + }); + } else { + Schema::rename('mise_en_place', 'mise_en_places'); + DB::statement( + 'ALTER TABLE `mise_en_places` CHANGE COLUMN `eleveurId_pondeuse` `eleveur_id` BIGINT(20);' + ); + DB::statement( + // phpcs:ignore Generic.Files.LineLength.TooLong + 'ALTER TABLE `mise_en_places` CHANGE COLUMN `id` `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT FIRST;' + ); + Schema::table('mise_en_places', function (Blueprint $table) { + $table->unsignedBigInteger('id')->unsigned()->change(); + }); + Schema::table('mise_en_places', function (Blueprint $table) { + $table->foreignId('eleveur_id') + ->comment('Clé étrangère éleveur id')->change(); + }); + Schema::table('mise_en_places', function (Blueprint $table) { + $table->foreign('eleveur_id') + ->references('id') + ->on('eleveurs'); + }); + } //end if + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('mise_en_places'); + } +}