Uh oh!
There was an error while loading. Please reload this page.
Add V97 migration: per-item markup_percentage override on phoenix_kit_cat_items - #493
Merged
Merged
Conversation
Replaces the old @show_maintenance assign approach with a dynamic layout swap via socket.private[:live_layout] — the underlying LiveView keeps running so form state and scroll position are preserved when maintenance toggles on or off. URL never changes. Core changes: - Layout override in on_mount hook instead of redirect. When maintenance turns on, put_in socket.private[:live_layout] swaps the layout live; when it ends, PubSub triggers restoration of the original layout - New PhoenixKitWeb.Layouts :maintenance template with countdown timer - HTTP plug renders inline 503 HTML (with Retry-After header) for controller routes, with proper Phoenix.HTML escaping to prevent XSS - Scheduled maintenance windows with start/end UTC datetimes, 1-year upper bound, and 60-second tolerance for datetime-local minute precision - cleanup_expired_schedule auto-disables stale state on every page access - Process.send_after timer unblocks users when scheduled end arrives (clamped to Erlang's 32-bit timeout limit) - PubSub broadcasts on every state change so all connected LiveViews react instantly; admin tabs stay put, user tabs swap layouts - Manual toggle clears expired schedule on enable to avoid stale locks - Activity logging for all admin actions (toggle, content, schedule) - All user-facing strings wrapped in gettext Schedule validation rejects: empty, past start/end, end before start, dates >1 year in the future. Datetime inputs use the system time_zone setting for display and convert to UTC for storage. Extracts timezone helpers (offset_to_seconds, shift_to_offset, parse_datetime_local, format_datetime_local) to PhoenixKit.Utils.Date so they can be tested in isolation. Adds 93 new tests: unit tests for validate_schedule and PubSub, integration tests for Maintenance context and the plug (including XSS regression test), and doctested timezone helpers. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Move phx-change from individual inputs to the form element so the live preview updates on every keystroke (input-level phx-change on text inputs only fires on blur, making the preview appear broken) - Remove the "Preview" link that navigated to /maintenance. The path went through locale-prefixed routes and got caught by the publishing module's /:language/:group catch-all. The settings page already has an inline Live Preview card rendering the same content, so the link was redundant Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
HIGH (merge blockers): - Register MaintenanceCountdown hook in priv/static/assets/phoenix_kit.js alongside the other phoenix_kit hooks. Parent apps already include this file, so the hook is now reliably available (was previously injected by a plug script that wasn't guaranteed to run before LiveSocket init). Remove the fragile inline injection from the Integration plug. - Plug's 503 HTML now uses inline CSS instead of linking to /assets/css/app.css (which wasn't actually served — the real digested path is /assets/app.css). The page is now self-contained with light + dark mode support via prefers-color-scheme, so it works on any route regardless of the parent app's asset pipeline. - Replace String.contains?/2 with String.starts_with?/2 in the plug's auth_route?/1 and static_asset?/1. A parent-app path like /blog/users/log-in-to-us would have bypassed maintenance mode. Add a regression test covering parent-app look-alike paths. MEDIUM: - disable_system/0 now clears maintenance_scheduled_end in addition to maintenance_scheduled_start so a stale end time doesn't surprise-disable the next re-enable. Update the test to assert both fields are cleared. - Track the Process.send_after timer ref in socket assigns and cancel it on reschedule (via new reschedule_maintenance_end_timer/1) so schedule changes don't leave a stale "auto-off" signal in flight. - Settings LiveView's PubSub handler now re-reads header and subtext so multi-admin editing stays in sync. The save handler broadcasts status change to trigger this sync. - schedule_error_message/1 catch-all now logs a warning with the unknown atom so future validation additions surface instead of being silently swallowed. - Document check_maintenance_mode/1's required call sites (all 6 on_mount hooks listed in the @doc) so new live_sessions don't forget it. - Add a HACK comment near put_in socket.private[:live_layout] noting it relies on Phoenix LiveView internals (same pattern as maybe_apply_plugin_layout) and should be revisited on major LV upgrades. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Addresses the final MEDIUM improvement from PR review: instead of each of the 6 on_mount hooks explicitly calling check_maintenance_mode/1, fold it into mount_phoenix_kit_current_scope/3 which all 6 already use. New live_sessions that use a scope-mounting on_mount hook now inherit maintenance mode enforcement automatically — no way to forget it. Removes 6 redundant call sites and updates the @doc comment. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…_cat_items Adds a nullable `markup_percentage DECIMAL(7, 2)` column on `phoenix_kit_cat_items`. When `NULL`, pricing falls back to the parent catalogue's `markup_percentage` (existing behavior); when set (including `0`), the item uses its own value. `NULL` vs. `0` is load-bearing: `0` means "explicitly sell at base price", `NULL` means "inherit whatever the catalogue currently uses". The column is nullable with no default, matching that distinction. Existing rows stay `NULL` and continue to inherit — no backfill is needed. The `up/1` operation is idempotent (`IF NOT EXISTS` guard inside a `DO $$` block), and the `down/1` rollback uses `DROP COLUMN IF EXISTS` so it's also idempotent. Lossy rollback note included in the down/1 docstring: any per-item overrides set after V97 are lost on rollback (items revert to the catalogue's markup). PG `ALTER TABLE ADD COLUMN` with no default and nullable = metadata- only operation, no full-table rewrite, AccessExclusive lock held briefly — safe for production-size tables. No new index — `markup_percentage` isn't queried as a filter, only SELECTed and computed in app code. Bumps `@current_version` to 97 and adds the `### V97` docblock entry above V96 (with the `⚡ LATEST` marker moved). Used by `phoenix_kit_catalogue` to support a per-item markup override field on the item form and import wizard. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
ddon pushed a commit
that referenced
this pull request
Apr 15, 2026
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
3 tasks
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 freeto 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.
Summary
Adds a nullable
markup_percentage DECIMAL(7, 2)column onphoenix_kit_cat_items. WhenNULL, pricing falls back to the parentcatalogue's
markup_percentage(existing behavior); when set(including
0), the item uses its own value.NULLvs.0is load-bearing:NULL= "inherit whatever the catalogue currently uses"0= "explicitly sell at base price, even if the catalogue has a markup"The column is nullable with no default, matching that distinction.
Existing rows stay
NULLand continue to inherit — no backfill needed.Migration safety
up/1is idempotent —IF NOT EXISTSguard inside aDO $$blockdown/1usesDROP COLUMN IF EXISTS, also idempotentdown/1docstring: any per-itemoverrides set after V97 are lost on rollback (items revert to the
catalogue's markup)
ALTER TABLE ADD COLUMNwith no default + nullable = metadata-onlyoperation, no full-table rewrite, AccessExclusive lock held briefly —
safe for production-size tables
markup_percentageisn't queried as a filter, onlySELECTed and computed in app code
Other changes
@current_versionto 97### V97docblock entry above V96 with the⚡ LATESTmarker movedUsed by
phoenix_kit_catalogueuses this column to back a per-item markup override field on the item
form and import wizard. See its companion PR.
Dependencies
windows + PubSub) first — this PR is branched off
devon top ofthat work. Once #491 is merged, this can be rebased onto the new
devcleanly (no overlapping files).