DROP TABLE IF EXISTS product_image;

-- DROP SEQUENCE IF EXISTS product_image_product_image_id_seq;
-- CREATE SEQUENCE product_image_product_image_id_seq;


CREATE TABLE product_image (
  "product_image_id" int PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, -- SERIAL PRIMARY KEY
  "product_id" int check ("product_id" > 0) NOT NULL,
  "image" varchar(191) NOT NULL,
  "sort_order" int NOT NULL DEFAULT 0
  -- PRIMARY KEY("product_image_id")
);

CREATE INDEX "product_image_product_id" ON product_image ("product_id", "product_image_id", "sort_order");
SELECT setval('product_image_product_image_id_seq', 53, true); -- last inserted id by sample data