DROP TABLE IF EXISTS product_discount;

-- DROP SEQUENCE IF EXISTS product_discount_product_discount_id_seq;
-- CREATE SEQUENCE product_discount_product_discount_id_seq;

CREATE TABLE product_discount (
  "product_discount_id" int PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, -- SERIAL PRIMARY KEY
  "product_id" int check ("product_id" > 0) NOT NULL,
  "user_group_id" int check ("user_group_id" > 0) NOT NULL,
  "quantity" int NOT NULL DEFAULT 0,
  "priority" int NOT NULL DEFAULT 1,
  "price" decimal(15,4) NOT NULL DEFAULT 0.0000,
  "from_date" date,
  "to_date" date
--  PRIMARY KEY("product_discount_id")
);

CREATE INDEX "product_discount_product_id" ON product_discount ("product_id");
CREATE INDEX "product_discount_user_group_id" ON product_discount ("user_group_id");
SELECT setval('product_discount_product_discount_id_seq', 19, true); -- last inserted id by sample data