Skip to content

Add V140 migration: phoenix_kit_warehouse tables - #624

Merged
ddon merged 1 commit into
BeamLabEU:mainfrom
timujinne:feat/warehouse-v140-tables
Jul 9, 2026
Merged

Add V140 migration: phoenix_kit_warehouse tables#624
ddon merged 1 commit into
BeamLabEU:mainfrom
timujinne:feat/warehouse-v140-tables

Conversation

@timujinne

Copy link
Copy Markdown
Contributor

Adds versioned migration V140 creating the six tables that back the new standalone phoenix_kit_warehouse module (companion PR: BeamLabEU/phoenix_kit_warehouse#1):

  • phoenix_kit_warehouse_stock — per item/location balance, unique (item_uuid, location_uuid), named CHECK (quantity >= 0).
  • phoenix_kit_warehouse_inventory_documents, _internal_orders, _supplier_orders, _goods_receipts, _goods_issues — sequence-numbered documents with draft/posted lifecycle columns, soft-delete columns, lines JSONB.

Design notes:

  • internal_orders and goods_issues deliberately have no FK to any order table — the relationship lives in a generic source_refs JSONB column resolved by host-registered callbacks in the warehouse module, keeping core agnostic of any host "order" concept.
  • Intra-module FKs preserved: supplier_orders.internal_order_uuidinternal_orders, goods_receipts.supplier_order_uuidsupplier_orders, goods_issues.internal_order_uuidinternal_orders. performed_by_uuidphoenix_kit_users(uuid) ON DELETE SET NULL on all five document tables.
  • uuid_generate_v7() PKs, TIMESTAMPTZ timestamps, all DDL idempotent, prefix-aware — follows the V135+ file conventions exactly.
  • @current_version bumped 139 → 140; moduledoc changelog entry added with the ⚡ LATEST marker moved.

Not included (maintainer-owned per repo conventions): mix.exs version bump and CHANGELOG entry — needed before the release that ships this.

Verified: full local test suite boots clean through PhoenixKit.Migration.ensure_current/2 with V140 applied; mix compile --warnings-as-errors clean; constraint/index shape verified against a live database (NOT NULL columns, 9 named constraints, 36 indexes).

Creates six tables for the standalone phoenix_kit_warehouse module:
phoenix_kit_warehouse_stock, phoenix_kit_warehouse_inventory_documents,
phoenix_kit_warehouse_internal_orders, phoenix_kit_warehouse_supplier_orders,
phoenix_kit_warehouse_goods_receipts, phoenix_kit_warehouse_goods_issues.
internal_orders and goods_issues carry a generic source_refs JSONB column
instead of any FK to a host order table — the warehouse module resolves
those refs through host-registered callbacks, so core stays agnostic of
any particular order concept. Intra-module FKs preserved
(supplier_orders -> internal_orders, goods_receipts -> supplier_orders,
goods_issues -> internal_orders); performed_by_uuid FKs to
phoenix_kit_users ON DELETE SET NULL on all five document tables.
All DDL idempotent; sequences back per-document number columns.
@ddon
ddon merged commit ef62360 into BeamLabEU:mainJul 9, 2026
ddon pushed a commit that referenced this pull request Jul 9, 2026
Post-merge review of #624 (V140 warehouse tables). V140 was unpublished
(hex latest == local 1.7.179), so the migration is amended in place rather
than patched by a V141.
- Fix: the quantity >= 0 CHECK guard matched pg_constraint.conname alone.
Constraint names are unique per (schema, table), not globally, so a second
install into another schema in the same database found the first schema's
constraint and silently skipped ADD CONSTRAINT. Scoped with conrelid, as
V41/V72/V78 already do.
- Fix: source_refs shipped unindexed, so replacing the indexed sub_order_uuid
FK with JSONB removed the index behind reverse lookups. Added GIN indexes on
internal_orders, supplier_orders, goods_receipts, goods_issues.
- Fix: phoenix_kit_warehouse_stock had no standalone location_uuid index; the
composite UNIQUE (item_uuid, location_uuid) cannot serve WHERE location_uuid.
- Update: V140 moduledoc justified four FK-less columns as "cross-package"
references, but all four targets are created by this same core migration set
and V122 already FKs location_uuid -> phoenix_kit_locations. Doc now states
that an FK is possible, is omitted pending a delete-semantics decision, and
that referential integrity for those columns is not enforced. Also removed a
private downstream app's table names, which were rendering on hexdocs.
The missing FKs are recorded in CLAUDE_REVIEW.md as BUG - MEDIUM rather than
fixed: adding them requires choosing ON DELETE RESTRICT vs CASCADE, which is
the warehouse package owner's decision.
Also bumps ecto 3.14.1, postgrex 0.22.3, plug 1.20.3, mdex_native 0.2.5.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@timujinne
timujinne deleted the feat/warehouse-v140-tables branch August 6, 2026 05:54
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