diff --git a/app/Console/Commands/OneOff/PopulateTreeSpeciesResearch.php b/app/Console/Commands/OneOff/PopulateTreeSpeciesResearch.php index 81c7b18c..a05253fb 100644 --- a/app/Console/Commands/OneOff/PopulateTreeSpeciesResearch.php +++ b/app/Console/Commands/OneOff/PopulateTreeSpeciesResearch.php @@ -63,14 +63,15 @@ public function handle() $bulkInsert = []; while ($csvRow = fgetcsv($fileHandle)) { $data = []; - $now = Carbon::now(); foreach ($this->columns as $column => $index) { - $data[$column] = $csvRow[$index]; - // These don't get set automatically with bulk insert - $data['created_at'] = $now; - $data['updated_at'] = $now; + $data[$column] = $csvRow[$index] == 'NA' ? null : $csvRow[$index]; } + // These don't get set automatically with bulk insert + $now = Carbon::now(); + $data['created_at'] = $now; + $data['updated_at'] = $now; + try { $existing = TreeSpeciesResearch::where('scientific_name', $data['scientific_name'])->first(); $this->assert( diff --git a/database/migrations/2024_12_16_200032_allow_null_infraspecific_epithet.php b/database/migrations/2024_12_16_200032_allow_null_infraspecific_epithet.php new file mode 100644 index 00000000..162d74f2 --- /dev/null +++ b/database/migrations/2024_12_16_200032_allow_null_infraspecific_epithet.php @@ -0,0 +1,27 @@ +string('infraspecific_epithet')->nullable()->change(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('tree_species_research', function (Blueprint $table) { + $table->string('infraspecific_epithet')->nullable(false)->change(); + }); + } +};