DROP TABLE IF EXISTS product_option;

-- DROP SEQUENCE IF EXISTS product_option_product_option_id_seq;
-- CREATE SEQUENCE product_option_product_option_id_seq;


CREATE TABLE product_option (
  "product_option_id" int PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, -- SERIAL PRIMARY KEY
  "product_id" int check ("product_id" > 0) NOT NULL,
  "option_id" int check ("option_id" > 0) NOT NULL,
  "value" text NOT NULL,
  "required" smallint NOT NULL DEFAULT 0,
  "sort_order" smallint NOT NULL DEFAULT 0
  -- PRIMARY KEY("product_option_id")
);

CREATE INDEX "product_option_product_id" ON product_option ("product_id");
CREATE INDEX "product_option_option_id" ON product_option ("option_id");
SELECT setval('product_option_product_option_id_seq', 3, true); -- last inserted id by sample data
