PhoenixKit.Migrations.Postgres.V140 (phoenix_kit v1.7.197)

Copy Markdown View Source

V140: Warehouse module tables.

Creates the six phoenix_kit_warehouse_* tables that back the standalone phoenix_kit_warehouse package: stock, inventory_documents, internal_orders, supplier_orders, goods_receipts, goods_issues.

These mirror the shape of the host-application tables the module was extracted from, minus every FK that pointed at a host-specific table:

  • internal_orders and goods_issues drop the sub_order_uuid FK — that relationship now lives exclusively in the generic source_refs JSONB column ([%{"kind" => "sub_order", "uuid" => ...}, ...]), resolved by a host-registered callback rather than a hard FK to an order table this package doesn't own. A GIN index on source_refs stands in for the index the dropped FK column used to provide, so the reverse lookup ("which documents reference this order?") stays off a sequential scan.
  • Intra-module FKs are kept: supplier_orders.internal_order_uuidinternal_orders, goods_receipts.supplier_order_uuidsupplier_orders, goods_issues.internal_order_uuidinternal_orders.
  • performed_by_uuid stays FK'd to phoenix_kit_users on every document table (core-to-core reference, unchanged from the originals).
  • item_uuid, location_uuid, storage_folder_uuid, and supplier_uuid are plain UUID columns. Their targets (phoenix_kit_cat_items, phoenix_kit_locations, phoenix_kit_media_folders, phoenix_kit_cat_suppliers) are all created by this same core migration set, so an FK would be physically possible. It is omitted because the delete semantics — restrict a location that still holds stock, versus cascade the documents away with it — are a product decision the warehouse package has not made yet. Until it does, referential integrity for these four columns is not enforced by the database, and a dangling location_uuid will not be rejected on insert.

This migration ships the tables only — no application code reads or writes them yet, and no data is copied from the host's legacy tables (that is a separate, later host-side data migration, run only after the new package and its LiveViews are built and verified).

Summary

Functions

Drops all six warehouse tables and their sequences, in FK-safe order (dependents before the tables they reference). Destroys any data written to them — safe only because, per this plan, nothing writes to them yet.

Functions

down(opts)

Drops all six warehouse tables and their sequences, in FK-safe order (dependents before the tables they reference). Destroys any data written to them — safe only because, per this plan, nothing writes to them yet.

up(opts)