Files
template-vitrine/backend/migrations/000008_create_price_tiers.up.sql
2026-09-14 20:50:19 +02:00

13 lines
544 B
SQL

CREATE TABLE price_tiers (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
product_id UUID NOT NULL REFERENCES products(id) ON DELETE CASCADE,
unit_id UUID NOT NULL REFERENCES units(id) ON DELETE RESTRICT,
quantity NUMERIC(14, 3) NOT NULL CHECK (quantity > 0),
price_cents BIGINT NOT NULL CHECK (price_cents >= 0),
position INT NOT NULL DEFAULT 0,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE INDEX idx_price_tiers_product_id ON price_tiers(product_id);