Files
perauset-e2e-mrg0et1k/sql/0014-inventory-transactions.sql
2026-07-11 08:54:43 +02:00

12 lines
606 B
SQL

CREATE TABLE app.inventory_transaction (
transaction_id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
item_id UUID NOT NULL REFERENCES app.inventory_item(item_id),
quantity_change NUMERIC NOT NULL,
reason TEXT NOT NULL, -- 'stocktake', 'adjustment', 'consumption', 'restock', 'request_fulfilled'
notes TEXT,
created_by_user_id UUID NOT NULL REFERENCES app."user"(user_id),
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE INDEX idx_inventory_transaction_item ON app.inventory_transaction(item_id);
CREATE INDEX idx_inventory_transaction_created ON app.inventory_transaction(created_at);