Skip to content

Commit

Permalink
[TM-1400] Allow null in infraspecific_epithet.
Browse files Browse the repository at this point in the history
  • Loading branch information
roguenet committed Dec 16, 2024
1 parent 62db653 commit 2f5acb6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
11 changes: 6 additions & 5 deletions app/Console/Commands/OneOff/PopulateTreeSpeciesResearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('tree_species_research', function (Blueprint $table) {
$table->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();
});
}
};

0 comments on commit 2f5acb6

Please sign in to comment.