DROP TABLE IF EXISTS coupon_log;

-- DROP SEQUENCE IF EXISTS coupon_log_coupon_log_id_seq;
-- CREATE SEQUENCE coupon_log_coupon_log_id_seq;

CREATE TABLE coupon_log (
  "coupon_log_id" int PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, -- SERIAL PRIMARY KEY
  "coupon_id" int check ("coupon_id" > 0) NOT NULL,
  "order_id" int check ("order_id" > 0) NOT NULL,
  "user_id" int check ("user_id" > 0) NOT NULL,
  "discount" decimal(15,4) NOT NULL,
  "created_at" timestamp(0) NOT NULL DEFAULT now()
  -- PRIMARY KEY("coupon_log_id")
);

CREATE INDEX "coupon_log_coupon_id" ON coupon_log ("coupon_id");
CREATE INDEX "coupon_log_order_id" ON coupon_log ("order_id");
CREATE INDEX "coupon_log_user_id" ON coupon_log ("user_id");
-- SELECT setval('coupon_log_coupon_log_id_seq', 0, true); -- last inserted id by sample data
