Skip to content

Warehouse 0.5.0: The module takes over its own database tables

Warehouse 0.5.0 gives the PhoenixKit stock module its own migration chain, so its eight tables can change shape in later releases without waiting for a core release. Nothing changes in the admin pages or in stock.

Its own migration chain

Until now, PhoenixKit core created the warehouse tables: stock, goods receipts, goods issues, internal orders, supplier orders, stocktakes, transfers and minimum stock. Core still creates them, and the module’s first migration, V1, adopts them as they are. It checks the same columns, keys, indexes and constraints with IF NOT EXISTS and records the version on the stock table. No column, row or index changes. The chain also makes sure the pgcrypto extension and the uuid_generate_v7() function exist instead of assuming core made them, because its CREATE TABLE statements are meant to be the only thing that builds these tables once core stops doing so.

Rolling the chain back only removes that version mark. It never drops a table or a row, because the tables hold live stock balances and document history. There is deliberately no automatic uninstall. The README has a new “Removing this module” section with the SQL an operator can run by hand, including the six document-number sequences that dropping the tables alone leaves behind.

Upgrading

Update the dependency, then run mix phoenix_kit.update. It generates a warehouse_update_v00_to_v01.exs migration that records version 1 and changes nothing else. No core upgrade is needed, the warehouse pages work as before, and new installs and sites without the warehouse module are not affected.

Full release notes: Warehouse 0.5.0

0.5.0 · 15 September 2026

Changed

  • phoenix_kit_warehouse’s future shape now belongs to a module-owned migration chain, PhoenixKitWarehouse.Migrations, marker pkw_schema:<N> (anchored on phoenix_kit_warehouse_stock, core’s first-created, FK-free table — none of the other 7 tables carry a marker of their own), following the canonical dual-reader protocol documented by phoenix_kit_hello_world (migrated_version/1 for migration context, migrated_version_runtime/1 for mix phoenix_kit.update; up/1 re-reads the version before changing anything). Varchar widths (status, on the six document-shaped tables) are sourced from each schema’s own column_widths/0 — the single shape authority — never restated as a second number.

    Ownership unfolds in three phases:

    • Phase 0 (this release) — V1 is an adoption of all 8 tables, not a create: core’s V140/V144 baseline still creates phoenix_kit_warehouse_stock, _goods_receipts, _goods_issues, _internal_orders, _supplier_orders, _inventory_documents, _transfers, and _min_stock on every install, and V1 re-asserts that exact shape idempotently (under core’s exact object names — sequences, columns, primary keys, check constraints, unique and plain indexes, foreign keys) and stamps the marker. Because no shape changes, core’s ExpectedSchema stays accurate — no core release is required and there is no release-ordering hazard.
    • Phase 1 (a future V2+) — the first real shape change to any of the 8 tables requires first adding the altered objects to core’s manifest generator’s @excluded_exact and regenerating ExpectedSchema, then raising this package’s core floor to that release.
    • Phase 2 (a future core baseline squash) — once core stops creating these tables for fresh installs, V1’s CREATE TABLE statements become the only thing that ever creates them from scratch, which is why up/1 already ensures uuid_generate_v7() (and its pgcrypto extension) exist rather than assuming core’s chain provided them.

    down/1 can never drop a table or a row, for any target including 0. It unstamps (or re-stamps) the marker on the anchor table and nothing else — the rows are live stock balances and document history. Test-pinned — no statement in either direction may match DROP/TRUNCATE/DELETE. There is deliberately no automated uninstall path; README.md’s new “Removing this module” section gives the operator manual SQL instead.

    Existing hosts: upgrade, then mix phoenix_kit.update; it generates a warehouse_update_v00_to_v01.exs migration that stamps pkw_schema:1 and nothing else changes. New hosts and hosts without this module: unchanged.

    Same adoption pattern as phoenix_kit_billing (V4, ten adopted tables) and phoenix_kit_dashboards (one adopted table).

Fixed

  • README “Removing this module” SQL now also drops the six document-number sequences — they are not OWNED BY their columns, so DROP TABLE alone left them behind. A test runs the README’s SQL block and asserts no phoenix_kit_warehouse_* relation survives.
  • Test suite applies phoenix_kit_locations’ own migration chain. phoenix_kit_locations 0.5.0 added owner_uuid to phoenix_kit_locations through PhoenixKitLocations.Migrations, which core’s ensure_current/2 does not carry — so after the 0.5.1 bump every LiveView test that loaded a warehouse location failed with column p0.owner_uuid does not exist (181 errors). Runtime code was unaffected; a host runs mix phoenix_kit.update, which applies that chain.

Warehouse 0.5.0. Install or update: {:phoenix_kit_warehouse, "~> 0.5"}, then mix deps.get && mix phoenix_kit.update. Full history: CHANGELOG.