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")
);

-- SELECT setval('coupon_log_coupon_log_id_seq', 0, true); -- last inserted id by sample data
