Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Record that converted-away columns outlive their conversion release

Łukasz Adamczyk76baba1aaefe
diff --git a/docs/plans/6.0-tax-provider.md b/docs/plans/6.0-tax-provider.md
index 99b1250c9a..345f4c2de8 100644
--- a/docs/plans/6.0-tax-provider.md
+++ b/docs/plans/6.0-tax-provider.md
@@ -482,7 +482,9 @@ scope :for_address, ->(address) {
}
```
-State-level rates override country-level (more specific wins). **Tax stops using Zone; the Zone model itself survives 6.0** — a data migration converts Zone records used by TaxRate into direct country/state FKs, `zone_id` comes off TaxRate, and the generic `Spree::Zone` stays for the request-context surface (`Spree::Current.zone`, `Market#tax_zone`, factories). Full Zone removal gets its own future plan with a complete consumer inventory.
+State-level rates override country-level (more specific wins). **Tax stops using Zone; the Zone model itself survives 6.0** — a data migration converts Zone records used by TaxRate into direct country/state FKs, no code reads `zone_id` on TaxRate any more, and the generic `Spree::Zone` stays for the request-context surface (`Spree::Current.zone`, `Market#tax_zone`, factories). Full Zone removal gets its own future plan with a complete consumer inventory.
+
+**`spree_tax_rates.zone_id` is dropped in 6.1, not 6.0.** The column is what `spree:migrate_tax_zones` converts *from*, and the manifest runs after `db:migrate` — so a migration dropping it in the same release would destroy the conversion's own input, and leave no rollback source if a merchant needs to re-run it. 6.0 therefore severs every reader (the `belongs_to :zone`, the zone scopes, and `Zone#has_many :tax_rates`, whose `dependent: :destroy` would otherwise delete live rates when a shipping zone is destroyed) and leaves the column in place, unread. This matches how `spree_adjustments` is handled by `migrate_adjustments_to_typed_rows`. The 6.1 cleanup drops the column alongside the other converted-away schema.
## Design Details
@@ -1029,11 +1031,14 @@ Tax-side only — shipping keeps Zone untouched; full Zone removal is deferred t
# (Zone with multiple countries = one TaxRate per country)
```
-- Add `country_id`/`state_id` to `spree_tax_rates`; run the data task; remove `zone_id`.
+- Add `country_id`/`state_id` to `spree_tax_rates`; run the data task; sever every `zone_id` reader.
+ The column itself stays until 6.1 — see "Drop TaxZone" above for why the conversion cannot
+ drop its own input.
- Update the `/admin/tax_rates` serializer, permitted params and Ransack allowlist from `zone_id` to `country_id`/`state_id` — the only rework those endpoints take, and the reason they are worth building in Phase 3 rather than waiting.
- Rewrite the tax-side zone readers against `TaxRate.for_address`: `Order#tax_zone`, `Spree::Current.zone`/`default_tax_zone`, `Market#tax_zone` — these feed pre-address tax display and Estimator VAT options, so they move to the provider/`for_address` path rather than being deleted.
- **Re-point whatever populates `DeliveryRate#tax_rate`.** The Estimator matches that rate through the Zone path this phase removes, so it must move to `for_address` to keep working. Mechanical only — preserving current behavior here does not require answering Open Question 1, though this is the natural moment to.
-- `spree_zones`/`spree_zone_members` are **not** dropped in 6.0.
+- `spree_zones`/`spree_zone_members` are **not** dropped in 6.0, and neither is
+ `spree_tax_rates.zone_id`.
### Phase 6: Avalara reference gem (`spree_tax_avalara`)
diff --git a/docs/plans/decisions.md b/docs/plans/decisions.md
index 82ba218f17..4c2ef27193 100644
--- a/docs/plans/decisions.md
+++ b/docs/plans/decisions.md
@@ -1614,3 +1614,18 @@ and `Spree::CalculatedAdjustments` resolves an equivalent registry
separately. Extract a `Spree::RegisteredSubclasses` concern when a family
needs the registry without preferences — that second consumer is the
trigger, and it would absorb CalculatedAdjustments too.
+## 2026-08-06 — Converted-away columns outlive the release that converts them
+
+`spree_tax_rates.zone_id` stays in the schema through 6.0 even though
+nothing reads it, and is dropped in 6.1. The reason is ordering, and it
+generalizes: a data task named in the upgrade manifest runs *after*
+`db:migrate`, so a migration that removes the task's input column in the
+same release destroys the data the task exists to convert — and leaves a
+merchant no source to re-run from if the conversion needs repeating.
+Tax rates therefore gain `country_id`/`state_id`, every `zone_id` reader
+is severed (the association, the zone scopes, and `Zone#has_many
+:tax_rates`, whose `dependent: :destroy` would otherwise delete live
+rates when a shipping zone is destroyed), and the column is left in
+place, unread. `spree_adjustments` already worked this way under
+`migrate_adjustments_to_typed_rows`, which keeps the legacy table as its
+rollback source; treat that as the pattern rather than the exception.