Uh oh!
There was an error while loading. Please reload this page.
V143: consolidate manufacturing/warehouse module tables into core - #632
Conversation
Ports phoenix_kit_manufacturing's and phoenix_kit_warehouse's own migration_module/0 tables into core's numbered migration chain: phoenix_kit_machines, phoenix_kit_machine_type_assignments, phoenix_kit_machine_operations (soft-referenced, FK dropped on upgrade from published manufacturing 0.2.0), phoenix_kit_warehouse_transfers, and phoenix_kit_warehouse_min_stock (fresh-install only). Legacy directory tables (machine_types/operations/defect_reasons) are dropped when empty and left in place with a notice when they still hold rows.
Bumps @current_version from 142 to 143 in PhoenixKit.Migrations.Postgres so ensure_current/2 and the Module.concat dispatch pick up V143 (manufacturing/warehouse module tables consolidation, added in the prior commit) automatically — no separate version registry to update. Adds the matching V143 entry to the moduledoc's version list ahead of V142, moving the "LATEST" marker over.
Verifies DDL fidelity against the pre-consolidation manufacturing/ warehouse sources, the wave-C plan's mandatory review fixes (8 indexes, FK-drop ordering, down/1 upgrade-host caveat, rollback terminology), and checks two known bug classes (schema-qualified index names, unscoped constraint guards) fixed in prior PRs. No issues found.
Schema-qualifies the five uuid_generate_v7() DEFAULT calls
(phoenix_kit_machines, phoenix_kit_machine_type_assignments,
phoenix_kit_machine_operations, phoenix_kit_warehouse_transfers,
phoenix_kit_warehouse_min_stock) to #{p}uuid_generate_v7() — matching
the fix applied to V136/V138/V140/V141 by the low-privilege-install
hardening (0268450). Postgres.up/1 already re-ensures the function at
the target schema for any chain starting >= V40, so this is a
mechanical qualification with no behavior change on public installs.
Every other prefix-safety convention was already satisfied: index
names stay bare on CREATE, the information_schema.tables existence
check in maybe_drop_if_empty/1 is anchored on table_schema, and
fk_constraint_name/3 anchors its catalog lookup on tc.table_schema via
a parameterized query.bf58b40 to
4eaf491Comparetimujinne
commented
Jul 13, 2026
Code review — V143 consolidation (GLM-5.2 @ max thinking, full-source review)Reviewed the full text of both changed files ( Verdict: NEEDS-WORKThe migration is conceptually correct — idempotency, prefix-hardening, mirrored Findings[major] [minor] [minor] [suggestion] [suggestion] Verified clean (no findings)Idempotency ✓ (all Required testingThe development environment cannot host scratch databases, so these must be run from scratch before merge — please test carefully on a clean PostgreSQL:
|
timujinne
commented
Jul 13, 2026
Cross-repo package review — V143 consolidation + module PRs (GLM-5.2 @ max thinking)Holistic review of the four-PR package: this PR (core V143), BeamLabEU/phoenix_kit_locations#9, BeamLabEU/phoenix_kit_warehouse#3, BeamLabEU/phoenix_kit_manufacturing#3. Structural checks passed: V143 owns exactly 3 manufacturing + 2 warehouse tables; all 5 module schemas match the DDL column-for-column and index-for-index; the other 6 warehouse tables are owned by core V140 (verified — no orphan tables, no schema/DDL mismatch). V122's Verdict: NEEDS-WORKThe package is structurally sound (no blockers), but not merge-ready due to documentation/coordination defects — two majors genuinely break builds/onboarding if followed literally. Findings[major] [major] [major] [minor] [minor] [minor] Core PR body vs [minor] Warehouse PR body hides the V140 dependency. [suggestion] Package-wide — no release coordination artifact. [suggestion] Required testingTests were not executed in the dev environment (no scratch DB). Please test carefully from scratch on a real PostgreSQL before merging the package:
|
…source_refs, min_quantity CHECK
timujinne
commented
Jul 13, 2026
Review findings addressed in 8f39a50:
The PR body has been corrected per the package review: |
# Conflicts: # lib/phoenix_kit/migrations/postgres.ex # lib/phoenix_kit/migrations/postgres/v143.ex
ddon
commented
Jul 13, 2026
Renumbered V143 → V144This PR originally claimed V143. A separate same-day core change (new-login security alerts, Independent verification (second pass)Re-derived (not just re-read) the two claims in the existing review's "Known bug classes checked" that most benefit from independent eyes:
No new findings. Concur with the original review's "Clean, no bugs" verdict. Full write-up (including this note) is in Proceeding to merge. |
Summary
Adds
PhoenixKit.Migrations.Postgres.V143, consolidating five tables previously created by thephoenix_kit_manufacturingandphoenix_kit_warehousepackages' own module-ownedmigration_module/0migrations into core's numbered chain:phoenix_kit_machinesphoenix_kit_machine_type_assignmentsphoenix_kit_machine_operationsphoenix_kit_warehouse_transfers(+ itsnumbersequence)phoenix_kit_warehouse_min_stockThis PR only touches
phoenix_kitcore (lib/phoenix_kit/migrations/postgres.ex,lib/phoenix_kit/migrations/postgres/v143.ex) and has no dependency on any other open PR. Companion PRs inphoenix_kit_manufacturingandphoenix_kit_warehouseremove their now-redundantmigration_module/0and switch to depending on core owning these tables — see "Depends on / blocks" below.Why here, not in the module packages
Both packages previously shipped their own
migration_module/0, discovered and run bymix phoenix_kit.updateon the host app. That worked, but split "does this host's schema match this module's expectations" across independently-versioned migration chains instead of one. This moves both packages onto the pattern already used forphoenix_kit_locations(V90/V122) and the standalone-warehouse-table precedent already in core (V140, PR #624) — one chain, one@current_version, onemix phoenix_kit.update.Scope per table
phoenix_kit_machines—CREATE TABLE IF NOT EXISTSwith the V1 identity columns plus the V2 passport/soft-location columns added viaADD COLUMN IF NOT EXISTS— i.e. the module's current (V5-equivalent) shape in one step. Idempotent against a V1-V5 host and a fresh host alike.phoenix_kit_machine_type_assignments/phoenix_kit_machine_operations—machine_type_uuid/operation_uuidare soft references (no FK): those directories now live in the separate, optionalphoenix_kit_entitiespackage, which this core migration correctly has no dependency on. Upgrade path: a host on the publishedphoenix_kit_manufacturing0.2.0 (module schema V1) already hasmachine_type_assignmentswith a live FK onmachine_type_uuid; this migration drops that FK unconditionally via a catalog lookup by table+column (not a guessed constraint name — seefk_constraint_name/3, ported verbatim from the module's own already-shipped code).phoenix_kit_warehouse0.1.0 never published any migrations at all (verified against the published Hex tarball — nomigrations/directory exists in it), so warehouse's two tables are fresh-install-only DDL, no upgrade branch needed or written.phoenix_kit_machine_types,phoenix_kit_operations,phoenix_kit_defect_reasons— all pre-V5 module-owned) are not re-created; they aren't one of the five objects this migration owns. Each is dropped when it exists and is empty, and left in place (with aRAISE NOTICE) when it still holds rows, so no host's real directory data is silently destroyed. See "Non-empty legacy tables" below for hosts that hit that branch.What this PR does not do
phoenix_kit_entitiesrecords and rewrite the join-table columns to point at them. V143 does not reproduce that step: a core schema migration has no business depending on the optionalphoenix_kit_entitiespackage, and silently converting someone's business data as a side effect of a schema migration is the wrong default. See "Non-empty legacy tables" below for the manual path.CHANGELOG.md. Left untouched, as usual — release notes are the maintainer's call. Note:mix.exs@versionis already1.7.189(bumped upstream before this branch was rebased onto it), which is exactly the version the companion warehouse/manufacturing PRs pin (>= 1.7.189) — so only the CHANGELOG entry is pending, not a version bump. Suggested for the release notes: a warning thatdown(version: 142)on a host upgraded fromphoenix_kit_manufacturing0.2.0 drops the pre-existingphoenix_kit_machine_type_assignmentstable (documented caveat in the migration docstring).Non-empty legacy tables on upgrade hosts
Only relevant to a host that (a) installed
phoenix_kit_manufacturingfrom the published0.2.0(module schema V1) and (b) has real rows inphoenix_kit_machine_types/phoenix_kit_operations/phoenix_kit_defect_reasonswhen it upgradesphoenix_kitcore past V143. Fresh installs, and any host where those three tables are already empty or gone, need nothing further — V143 handles that case by itself.Quick check after upgrading:
If any of those come back
true, the conversion algorithm to finish by hand is:phoenix_kit_entitiesblueprint entities exist (machine_type,operation,defect_reason) viaget_entity_by_name/1→create_entity/2(+ translations).phoenix_kit_entity_datarecord (title/description into the primary-language block ofdata;machine_type'sfield_templateintometadata), stampingmetadata["legacy_uuid"]with the source row's uuid for idempotency.UPDATE phoenix_kit_machine_type_assignments SET machine_type_uuid = <new uuid> WHERE machine_type_uuid = <old uuid>(and thephoenix_kit_machine_operations.operation_uuidequivalent) for every mapped pair — the FK constraints on these columns are already gone by this point (V143 drops them unconditionally inup/1), so there's nothing to drop yourself first.DROP TABLEthe three legacy tables once every row is confirmed migrated.The exact, previously-shipped implementation of this algorithm (
migrate_legacy_directories_to_entities/2and its private helpers, including the blueprint entity definitions and multilang reshaping) is preserved verbatim inphoenix_kit_manufacturing's git history and walked step by step — with the exact commit to pull it from — in that repo'sdev_docs/LEGACY_DATA_MIGRATION.md(added by its own companion PR removingmigration_module/0).Rollback
down/1mirrors the five creates (drops in FK-safe order, restores thephoenix_kittable comment to'142'). One caveat, documented inV143.down/1's own moduledoc: on a host that started from the published manufacturing 0.2.0,phoenix_kit_machine_type_assignmentspre-dates V143 (created by that package's own oldmigration_module/0, not by this migration) —down/1can't distinguish the two provenances, so it drops that table unconditionally, which is a stricter rollback than "undo only what V143 did" on such a host.down/1never touches the three legacy directory tables in either direction — they're never owned by V143 regardless of whetherup/1dropped them or left them in place.Rolling back is
PhoenixKit.Migrations.down(prefix: "public", version: 142)— the target version is exclusive of the down range (only V143's owndown/1runs; V142 and below are untouched).Heads-up: unrelated dangling
v143.exonfeature/v143-crm-party-rolesThis fork also carries a stale, never-opened-as-a-PR branch
feature/v143-crm-party-roles(fb24bda0, branched from1.7.186) with its own, unrelatedv143.ex— a CRM party-roles migration (supplier/client roles on companies/contacts). It does not block this PR:upstream/mainnever merged it (@current_versionis still142there, and nov143.exexists onupstream/main, as of this PR), so there is no numbering collision today. If/when that CRM work is revived, it renumbers to V144+ — an intentional owner call, made so this consolidation didn't have to wait on an unopened, unrelated branch.Depends on / blocks
phoenix_kit_manufacturingandphoenix_kit_warehouseremove their now-redundantmigration_module/0and bump theirpk_dep(:phoenix_kit, ...)pin to whatever patch version ships this V143 (placeholder in bothmix.exsfiles until this is published — upstreamphoenix_kitis at1.7.189as of this PR).Testing
mix formatmix compile --warnings-as-errorsmix test test/phoenix_kit/migration_test.exs— module-shape tests, no DB needed, 6/6 passingmix test test/integration/prefix_migration_test.exs— runs the full versioned chain (now including V143) into a named schema; not run in this environment (no reachable PostgreSQL). This is exactly the test that exercises V143 end to end once a DB-backed environment picks up this branch.v143.exwas diffed by hand against its pre-consolidation source (phoenix_kit_manufacturing's modulemachines.exV1/V2 shape,phoenix_kit_warehouse'sv01.ex/v02.ex) — seeCLAUDE_REVIEW.mdin this PR's doc folder for the full verification pass.Related
lib/phoenix_kit/migrations/postgres/v143.exlib/phoenix_kit/migrations/postgres.exphoenix_kit_warehouse's first core-owned tables, PR Add V140 migration: phoenix_kit_warehouse tables #624), V138/V122/V90 (locations — same core-owns-the-tables pattern)dev_docs/pull_requests/2026/143-manufacturing-warehouse-tables-consolidation/CLAUDE_REVIEW.md