fix(core): support PostgreSQL with deterministic ordering#2518
Open
alecgarcia wants to merge 1 commit into
Open
fix(core): support PostgreSQL with deterministic ordering#2518alecgarcia wants to merge 1 commit into
alecgarcia wants to merge 1 commit into
Conversation
Several relationships had no explicit ORDER BY, so row order depended on the database engine. MySQL/InnoDB returns rows in clustered primary-key order by coincidence, but PostgreSQL — which is officially supported — returns heap order, which changes after an UPDATE. This surfaced as user-visible instability once running on PostgreSQL. - Cart::lines() and Order::lines() now order by id. Lunar relies on a stable line sequence: GenerateFingerprint reduces $cart->lines in iteration order, so an unstable order can change a cart's fingerprint after an unrelated update, not just shift the displayed order. - ProductVariant::values() now orders by position, with the pivot id as a deterministic tie-break across options. getOption() joins these values into the variant option label, which is snapshotted onto order lines, so the persisted value must be deterministic across engines. This follows the relationship-level ordering convention already used by Order::transactions(), ProductOption::values(), and AttributeGroup::attributes().
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
Several core relationships had no explicit
ORDER BY, so row order depended on the database engine. MySQL/InnoDB returns clustered primary-key order by coincidence, but PostgreSQL — which is officially supported — returns heap order, which changes after anUPDATE. Running on PostgreSQL surfaces this as user-visible instability.Changes
Cart::lines()andOrder::lines()now order byid. Lunar relies on a stable line sequence:GenerateFingerprintreduces$cart->linesin iteration order, so an unstable order can change a cart's fingerprint after an unrelated update, not just shift the displayed order. OrderingOrder::lines()also stabilizes the derivedphysicalLines/digitalLines/shippingLines/productLines.ProductVariant::values()now orders byposition, with the pivotidas a deterministic tie-break across options.getOption()joins these values into the variant option label, which is snapshotted onto order lines inCreateOrderLines, so the persisted value must be deterministic across engines.This follows the relationship-level ordering convention already used by
Order::transactions(),ProductOption::values(), andAttributeGroup::attributes().Tests
New coverage in
CartTest,OrderTest, andProductVariantTest. Each ordering test fails on the current code and passes with the fix. The fulltests/coresuite passes (561 passed, 1 skipped); Pint is clean.Fixes #2517