

CREATE TABLE gift_card_types (
  id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(),
  card_type VARCHAR(64) NOT NULL,
  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);

INSERT INTO gift_card_types (id, card_type) VALUES ('jam_tracks_5', 'jam_tracks_5');
INSERT INTO gift_card_types (id, card_type) VALUES  ('jam_tracks_10', 'jam_tracks_10');

CREATE TABLE gift_card_purchases (
  id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(),
  user_id VARCHAR(64) NOT NULL  REFERENCES users(id) ON DELETE SET NULL,
  gift_card_type_id VARCHAR(64) REFERENCES gift_card_types(id) ON DELETE SET NULL,
  recurly_adjustment_uuid VARCHAR(500),
  recurly_adjustment_credit_uuid VARCHAR(500),
  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);


ALTER TABLE sale_line_items ADD COLUMN gift_card_purchase_id VARCHAR(64) REFERENCES gift_card_purchases(id);
