Skip to content

V185: currency-freeze columns on carts, cart items and orders (stacked on #785) - #787

Merged
ddon merged 1 commit into
BeamLabEU:mainfrom
timujinne:feature/currency-e1-core
Sep 6, 2026
Merged

V185: currency-freeze columns on carts, cart items and orders (stacked on #785)#787
ddon merged 1 commit into
BeamLabEU:mainfrom
timujinne:feature/currency-e1-core

Conversation

@timujinne

Copy link
Copy Markdown
Contributor

V185: currency-freeze columns on carts, cart items and orders

Stacked on #785 (V184). Companions: BeamLabEU/phoenix_kit_billing#32 and the ecommerce stage-Э1 PR, which read these columns through their schemas (Order, Cart, CartItem).

What V185 does

  • phoenix_kit_shop_carts: base_currency varchar(3), exchange_rate numeric(15,6); phoenix_kit_shop_cart_items: base_unit_price numeric(15,2); phoenix_kit_orders: base_currency varchar(3), exchange_rate numeric(15,6), base_total numeric(15,2). All nullable, no default — ADD COLUMN IF NOT EXISTS, no table rewrite.
  • A DO block raises unless phoenix_kit_currencies has exactly one is_default row (the billing chain's V2 partial unique index guarantees it; the guard makes the failure visible before any backfill).
  • Backfill without literals: base_currency from the is_default row; exchange_rate = 1.0 when the record's currency is the base, else that currency's table rate (NULL when unknown — honest "unknown rate"); base_unit_price/base_total only for records already in the base currency, NULL otherwise (a conversion nobody performed is not fabricated).
  • down/1 drops the six columns and stamps 184 — irreversible in meaning (orders forget the rate they were priced at), said in the comment.
  • expected_schema.ex: the six columns are declared by hand (V171 "DECLARED POST-GENERATION" precedent; positions/types from the live ordinal_position), then chain_hash restamped — the full generator aborts on this environment (see V184: remove the dead shop_currency setting #785 for the sync_shop_*_slugs mode-shape mismatch).

Tests

test/phoenix_kit/migrations/v185_test.exs (backfill from the default row; refusal with two defaults). Migrations dir + release_check tests: 16 doctests, 450 tests, 0 failures; expected_schema/ tests 67/0; mix phoenix_kit.release_check Migration Version Sync passes (V135..V185 contiguous, chain hash over 51 files). Applied on a live host: 94/94 carts backfilled USD/1.000000, 11/11 items base_unit_price = unit_price, the one order base_total = total, marker 185. Version bump and CHANGELOG left to the maintainer.

@timujinnetimujinne left a comment

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent review (read-only reviewer, separate from the author), range 2fe7f3a5..6668c93f. Verdict: PASS, no findings against V185.

Verified directly

  • Six ADD COLUMN IF NOT EXISTS statements match the spec (types, nullability, no defaults); the three backfills derive every value from the is_default row (1.0 for base-currency records, the table rate otherwise, NULL when unknown; base_unit_price/base_total only for base-currency records), all gated WHERE … IS NULL for idempotency; the DO block raises before any column is touched unless exactly one default exists; down/1 drops the six and stamps 184.
  • Manifest entries hand-declared under the existing "DECLARED POST-GENERATION" lane (V165/V168/V171/V175 precedent); positions and types cross-checked against the live information_schema.columns — exact match; backfill: nil is the right analogue of V183's target_uuid (no column default). chain_hash restamped (7aef0122…), release_check Migration Version Sync passes (V135..V185 contiguous, 51 files).
  • Tests rerun: migrations dir + release_check tests 16 doctests / 450 tests / 0 failures; expected_schema/ 67/0; format --check-formatted and credo --strict clean. The "two defaults" test drops billing's partial index inside its sandboxed transaction so V185's own guard is what fires — legitimate.
  • Live host after phoenix_kit_update_v184_to_v185: 94/94 carts USD/1.000000, 11/11 items base_unit_price = unit_price, the one order base_total = total, marker 185, all domains 200.
  • Commit by the author only; no version/CHANGELOG changes.

Note, not a blocker: the merge that carried this onto the host's stand branch also pulled four unrelated upstream commits (2.15.0 release, B2B registration setting, admin naming); the two behaviour changes 2.15.0 flags (user_dashboard_enabled default, admin_path wording) do not affect that host.

@timujinne
timujinne marked this pull request as ready for review September 6, 2026 09:02
@ddon

ddon commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

@timujinne and another conflict is here

@ddon

ddon commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

@timujinne still conflict here

Adds base_currency/exchange_rate to phoenix_kit_shop_carts and
phoenix_kit_orders, and base_unit_price to
phoenix_kit_shop_cart_items - all nullable, no default.
Renumbered V185 -> V186 on rebase: BeamLabEU#786 landed its own V185 first
(permanent activities and the settings history), so this migration
moves up one. postgres.ex's @current_version was 185 on BOTH sides, so
git merged that line clean and the chain would have stopped one short
of this migration; bumped to 186 by hand. expected_schema.ex's object
lists merged cleanly and carry both sets; @chain_hash recomputed over
the merged 52-file chain and verified with release_check.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XETjfiAv8Vom2tWhKnKQGC
@ddon
ddonforce-pushed the feature/currency-e1-core branch from 6668c93 to a42ffb9CompareSeptember 6, 2026 19:23
@ddon
ddon merged commit fd619ec into BeamLabEU:mainSep 6, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@timujinne@ddon