Files
backend/database/migrations/016_product_variation_values.sql
T
Ali Reza bb59d5e9ba Initial commit: Meshkee CMS API
NestJS backend with Prisma, Docker Compose for Postgres/Redis, and deploy docs for the production VM.
2026-07-21 17:52:36 +03:30

21 lines
940 B
SQL

-- Product-level variation value selections (which category options apply to a product).
-- Store item variants are created later from these values.
CREATE TABLE product_variation_values (
product_id BIGINT NOT NULL,
variation_id BIGINT NOT NULL,
option_id BIGINT NOT NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
CONSTRAINT product_variation_values_pkey PRIMARY KEY (product_id, option_id),
CONSTRAINT product_variation_values_product_id_fkey
FOREIGN KEY (product_id) REFERENCES products (id) ON DELETE CASCADE,
CONSTRAINT product_variation_values_variation_id_fkey
FOREIGN KEY (variation_id) REFERENCES category_variations (id) ON DELETE RESTRICT,
CONSTRAINT product_variation_values_option_id_fkey
FOREIGN KEY (option_id) REFERENCES category_variation_options (id) ON DELETE RESTRICT
);
CREATE INDEX idx_product_variation_values_variation_id
ON product_variation_values (variation_id);