@futurelastic/colab-handbook 1.12.0-rc.63 → 1.12.0-rc.64

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -32,5 +32,5 @@
32
32
  "engines": {
33
33
  "node": ">=18"
34
34
  },
35
- "version": "1.12.0-rc.63"
35
+ "version": "1.12.0-rc.64"
36
36
  }
@@ -45,8 +45,8 @@
45
45
  # The last two bullets fire ONLY when rows exist — on an empty table every one of
46
46
  # them passes on both engines. Set ROUNDTRIP_SEEDER below, or they go unchecked.
47
47
  #
48
- # Not gated on RUN_TESTS: a bad migration is cheapest to fix on the branch that adds
49
- # it, so this runs on every push, not only on main.
48
+ # Not gated on RUN_TESTS: a bad migration is cheapest to fix on the branch that adds or
49
+ # modifies it, so this runs on every push, not only on main.
50
50
 
51
51
  name: CI
52
52
 
@@ -461,14 +461,19 @@ jobs:
461
461
  # Migration round-trip — see the header for what each engine catches.
462
462
  #
463
463
  # 1. migrate from zero (schema snapshot A)
464
- # 2. migrate:rollback the migrations THIS change adds — every down() among them
465
- # runs (all migrations when the change adds none)
464
+ # 2. migrate:rollback back to the OLDEST migration this change adds OR modifies —
465
+ # every down() it touched runs, plus the untouched ones after
466
+ # it (all migrations when the change touches none)
466
467
  # 3. seed only if ROUNDTRIP_SEEDER is set, and only when the change
467
- # adds migrations: rows land at the PRE-change schema
468
- # 4. migrate again — the new migrations land on those rows (snapshot B)
468
+ # touches migrations: rows land at the PRE-change schema
469
+ # 4. migrate again — the touched migrations land on those rows (snapshot B)
469
470
  # 5. compare B must equal A — a down() that does not exactly undo its
470
471
  # up() leaves a schema that differs on the second pass
471
472
  #
473
+ # MODIFIED counts as touched, not only added (#507): a branch that only repairs an
474
+ # existing down() must see that down() run, and a branch that adds one migration and
475
+ # repairs an older one must roll back past the older one, not just the newest step.
476
+ #
472
477
  # Steps 2-4 are the shape of a real deploy: new migrations landing on tables that
473
478
  # already hold rows written before they existed. That is why the seed sits BETWEEN
474
479
  # the rollback and the second migrate — rows seeded after the new migrations would
@@ -533,7 +538,7 @@ jobs:
533
538
  steps:
534
539
  - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
535
540
  with:
536
- # Full history: step 3 counts the migrations this change adds against trunk.
541
+ # Full history: the count step diffs the migrations this change touches against trunk.
537
542
  fetch-depth: 0
538
543
  persist-credentials: false
539
544
 
@@ -580,7 +585,7 @@ jobs:
580
585
  - name: Discover packages
581
586
  run: php artisan package:discover --ansi
582
587
 
583
- - name: Count the migrations this change adds
588
+ - name: Find the migrations this change adds or modifies
584
589
  env:
585
590
  DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
586
591
  run: |
@@ -597,15 +602,24 @@ jobs:
597
602
  base="$(git rev-parse -q --verify 'HEAD^' || true)"
598
603
  fi
599
604
  fi
600
- steps=0
605
+ # Added, Modified, and Renamed (a rename is a new name to the migrator) — not
606
+ # added only (#507): a branch that only repairs an existing down() got a green
607
+ # round-trip that never ran it.
608
+ touched=""
601
609
  if [ -n "$base" ]; then
602
- steps="$(git diff --name-only --diff-filter=A "$base" HEAD -- "$MIGRATIONS_PATH" | grep -c '\.php$' || true)"
610
+ touched="$(git diff --name-status --diff-filter=AMR "$base" HEAD -- "$MIGRATIONS_PATH" | awk -F'\t' '$NF ~ /\.php$/ { print substr($1,1,1) "\t" $NF }')"
603
611
  fi
604
- echo "ROLLBACK_STEPS=$steps" >> "$GITHUB_ENV"
605
- if [ "$steps" -gt 0 ]; then
606
- echo "This change adds $steps migration(s) (vs ${base_ref}); step 3 rolls back exactly those."
612
+ # The migrator orders by file name, so the oldest touched one is the smallest
613
+ # base name; step 2 rolls back to it and everything after it.
614
+ from="$(printf '%s\n' "$touched" | awk -F'\t' 'NF { n=$2; sub(/.*\//, "", n); sub(/\.php$/, "", n); print n }' | LC_ALL=C sort | head -1)"
615
+ echo "ROUNDTRIP_FROM=$from" >> "$GITHUB_ENV"
616
+ if [ -n "$from" ]; then
617
+ added="$(printf '%s\n' "$touched" | grep -c '^A' || true)"
618
+ modified="$(printf '%s\n' "$touched" | grep -c '^[MR]' || true)"
619
+ echo "This change touches migrations (vs ${base_ref}): $added added, $modified modified. Step 2 rolls back to the oldest, $from, so every down() listed below runs:"
620
+ printf '%s\n' "$touched" | sed 's/^A\t/ added /; s/^[MR]\t/ modified /'
607
621
  else
608
- echo "This change adds no migrations (vs ${base_ref:-nothing}); step 3 rolls back all of them."
622
+ echo "This change adds or modifies no migrations (vs ${base_ref:-nothing}); step 2 rolls back all of them."
609
623
  fi
610
624
 
611
625
  - name: Write the schema snapshot script
@@ -637,6 +651,18 @@ jobs:
637
651
  ksort($out);
638
652
  echo json_encode($out, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES), "\n";
639
653
  PHP
654
+ # How many migrations step 2 must roll back to reach ROUNDTRIP_FROM: the rows of
655
+ # the migrations table at or after it. Read from the table, not by counting
656
+ # files, so migrations a package registers from another path are counted too.
657
+ cat > "$RUNNER_TEMP/rollback-steps.php" <<'PHP'
658
+ <?php
659
+ require getcwd() . '/vendor/autoload.php';
660
+ $app = require getcwd() . '/bootstrap/app.php';
661
+ $app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
662
+ $m = config('database.migrations');
663
+ $table = is_array($m) ? ($m['table'] ?? 'migrations') : ($m ?: 'migrations');
664
+ echo Illuminate\Support\Facades\DB::table($table)->where('migration', '>=', getenv('ROUNDTRIP_FROM'))->count(), "\n";
665
+ PHP
640
666
 
641
667
  - name: 1. migrate from zero
642
668
  run: |
@@ -645,16 +671,22 @@ jobs:
645
671
 
646
672
  - name: 2. roll back
647
673
  run: |
648
- if [ "$ROLLBACK_STEPS" -gt 0 ]; then
649
- php artisan migrate:rollback --step="$ROLLBACK_STEPS" --force
674
+ set -euo pipefail
675
+ steps=0
676
+ if [ -n "$ROUNDTRIP_FROM" ]; then
677
+ steps="$(php "$RUNNER_TEMP/rollback-steps.php")"
678
+ fi
679
+ if [ "$steps" -gt 0 ]; then
680
+ echo "Rolling back $steps migration(s), down to $ROUNDTRIP_FROM."
681
+ php artisan migrate:rollback --step="$steps" --force
650
682
  else
651
683
  # Everything ran in one batch at step 1, so this rolls all of it back.
652
684
  php artisan migrate:rollback --force
653
685
  fi
654
686
 
655
687
  - name: 3. seed rows at the pre-change schema
656
- # No new migrations = nothing lands on the rows, and the schema is empty anyway.
657
- if: env.ROUNDTRIP_SEEDER != '' && env.ROLLBACK_STEPS != '0'
688
+ # No touched migrations = nothing lands on the rows, and the schema is empty anyway.
689
+ if: env.ROUNDTRIP_SEEDER != '' && env.ROUNDTRIP_FROM != ''
658
690
  run: php artisan db:seed --class="$ROUNDTRIP_SEEDER" --force
659
691
 
660
692
  - name: 4. migrate again