DROP TABLE IF EXISTS product_question;

-- DROP SEQUENCE IF EXISTS product_question_product_question_id_seq;
-- CREATE SEQUENCE product_question_product_question_id_seq;


CREATE TABLE product_question (
  "product_question_id" int PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, -- SERIAL PRIMARY KEY
  "product_id" int check ("product_id" > 0) NOT NULL,
  "user_id" int check ("user_id" >= 0) NOT NULL DEFAULT 0,
  "author" varchar(64) NOT NULL,
  "content" text NOT NULL,
  "status" smallint NOT NULL DEFAULT 0,
  "parent_id" int check ("parent_id" >= 0) NOT NULL DEFAULT 0,
  "created_at" timestamp(0) NOT NULL DEFAULT now(),
  "updated_at" timestamp(0) NOT NULL DEFAULT now()
  -- PRIMARY KEY("product_question_id")
);

CREATE INDEX "product_question_product_id" ON product_question ("product_id", "status");
CREATE INDEX "product_question_user_id" ON product_question ("user_id");
SELECT setval('product_question_product_question_id_seq', 5, true); -- last inserted id by sample data