Make workflow migrations idempotent for partial deploys.
Deploy Ladill Care / deploy (push) Successful in 2m41s

Production already had care_facility_workflows from a prior attempt, so recreate checks let migrate finish and record the batch.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
isaacclad
2026-07-17 21:19:59 +00:00
co-authored by Cursor
parent 3ee59a0956
commit e172d3c5d1
2 changed files with 124 additions and 91 deletions
@@ -11,11 +11,15 @@ use Illuminate\Support\Facades\Schema;
* VisitStageAdvance a visit's position + history through those stages.
* FinancialObligation charge intent created before/after a stage; a stage's
* queue stays gated until its obligation clears (paid / authorized / waived).
*
* Creation is idempotent so a prior partial deploy (tables present, migration
* row missing) can finish cleanly.
*/
return new class extends Migration
{
public function up(): void
{
if (! Schema::hasTable('care_facility_workflows')) {
Schema::create('care_facility_workflows', function (Blueprint $table) {
$table->id();
$table->uuid('uuid')->unique();
@@ -32,7 +36,9 @@ return new class extends Migration
$table->index(['organization_id', 'branch_id', 'is_active']);
});
}
if (! Schema::hasTable('care_workflow_stages')) {
Schema::create('care_workflow_stages', function (Blueprint $table) {
$table->id();
$table->uuid('uuid')->unique();
@@ -69,7 +75,9 @@ return new class extends Migration
$table->unique(['workflow_id', 'code']);
$table->index(['workflow_id', 'sort_order']);
});
}
if (! Schema::hasTable('care_visit_stage_advances')) {
Schema::create('care_visit_stage_advances', function (Blueprint $table) {
$table->id();
$table->string('owner_ref')->index();
@@ -88,7 +96,9 @@ return new class extends Migration
$table->index(['visit_id', 'status']);
$table->index(['visit_id', 'stage_code']);
});
}
if (! Schema::hasTable('care_financial_obligations')) {
Schema::create('care_financial_obligations', function (Blueprint $table) {
$table->id();
$table->uuid('uuid')->unique();
@@ -118,6 +128,7 @@ return new class extends Migration
$table->index(['stage_code', 'status']);
});
}
}
public function down(): void
{
@@ -8,6 +8,17 @@ return new class extends Migration
{
public function up(): void
{
if (! Schema::hasTable('care_financial_obligations')) {
return;
}
$hasUnique = collect(Schema::getIndexes('care_financial_obligations'))
->contains(fn (array $index) => ($index['name'] ?? '') === 'care_obligations_visit_stage_unique');
if ($hasUnique) {
return;
}
Schema::table('care_financial_obligations', function (Blueprint $table) {
$table->unique(
['visit_id', 'workflow_stage_id'],
@@ -18,6 +29,17 @@ return new class extends Migration
public function down(): void
{
if (! Schema::hasTable('care_financial_obligations')) {
return;
}
$hasUnique = collect(Schema::getIndexes('care_financial_obligations'))
->contains(fn (array $index) => ($index['name'] ?? '') === 'care_obligations_visit_stage_unique');
if (! $hasUnique) {
return;
}
Schema::table('care_financial_obligations', function (Blueprint $table) {
$table->dropUnique('care_obligations_visit_stage_unique');
});