ids-svc-product/scripts/sql/create-inventory-adjustments.sql

15 lines
809 B
SQL
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

CREATE TABLE IF NOT EXISTS product.inventory_adjustments (
order_id BIGINT NOT NULL,
action VARCHAR(20) NOT NULL,
sku_id BIGINT NOT NULL REFERENCES product.product_items(id) ON DELETE CASCADE,
quantity INTEGER NOT NULL CHECK (quantity > 0),
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
PRIMARY KEY (order_id, action, sku_id),
CONSTRAINT chk_inventory_adjustments_action CHECK (action IN ('confirm', 'release'))
);
COMMENT ON TABLE product.inventory_adjustments IS '订单库存动作幂等表:记录确认成交和释放锁定库存';
COMMENT ON COLUMN product.inventory_adjustments.action IS '库存动作:confirm 支付成功确认成交;release 待支付取消/超时释放锁定';
GRANT SELECT, INSERT, UPDATE, DELETE ON product.inventory_adjustments TO svc_product;