DROP TABLE IF EXISTS glt_user_ticket_log;
DROP TABLE IF EXISTS glt_user_ticket_release;
DROP TABLE IF EXISTS glt_user_ticket;

CREATE TABLE glt_user_ticket (
  id INT AUTO_INCREMENT PRIMARY KEY,
  template_id INT,
  goods_id INT,
  order_id INT,
  order_no VARCHAR(64),
  order_goods_id INT,
  total_qty INT,
  available_qty INT,
  frozen_qty INT,
  used_qty INT,
  released_qty INT,
  user_id INT,
  sort_number INT,
  comments VARCHAR(255),
  status INT,
  deleted INT DEFAULT 0,
  tenant_id INT,
  create_time TIMESTAMP,
  update_time TIMESTAMP
);

CREATE TABLE glt_user_ticket_release (
  id BIGINT AUTO_INCREMENT PRIMARY KEY,
  user_ticket_id BIGINT,
  user_id INT,
  period_no INT,
  release_qty INT,
  release_time TIMESTAMP,
  status INT,
  deleted INT DEFAULT 0,
  tenant_id INT,
  create_time TIMESTAMP,
  update_time TIMESTAMP
);

CREATE TABLE glt_user_ticket_log (
  id INT AUTO_INCREMENT PRIMARY KEY,
  user_ticket_id INT,
  change_type INT,
  change_available INT,
  change_frozen INT,
  change_used INT,
  available_after INT,
  frozen_after INT,
  used_after INT,
  order_id INT,
  order_no VARCHAR(64),
  user_id INT,
  sort_number INT,
  comments VARCHAR(255),
  status INT,
  deleted INT DEFAULT 0,
  tenant_id INT,
  create_time TIMESTAMP,
  update_time TIMESTAMP
);

