BEGIN;

CREATE TABLE IF NOT EXISTS "discount" (
  "discount_id" SERIAL PRIMARY KEY,
  "discount_value" INTEGER NOT NULL,
  "discount_code" TEXT NOT NULL UNIQUE
);

INSERT INTO "discount" (discount_value, discount_code)
VALUES
  (900000, 'A7K2M'),
  (800000, 'Z19QX8'),
  (700000, 'N4T8B3W'),
  (600000, 'P6R1D9L0'),
  (500000, 'H2V9C'),
  (400000, 'M8J3S7Q'),
  (300000, 'X5A0N2K9'),
  (200000, 'B7F4T1'),
  (100000, 'Q3W9E1R8T')
ON CONFLICT (discount_code) DO UPDATE
SET discount_value = EXCLUDED.discount_value;

SELECT setval(
  pg_get_serial_sequence('"discount"', 'discount_id'),
  GREATEST((SELECT COALESCE(MAX(discount_id), 0) FROM "discount"), 1)
);

COMMIT;
