CREATE TABLE IF NOT EXISTS export_templates (
  id              INT AUTO_INCREMENT PRIMARY KEY,
  company_id      INT NOT NULL,
  spreadsheet_id  VARCHAR(255) NOT NULL,
  spreadsheet_url VARCHAR(512) NOT NULL,
  report_type     VARCHAR(50) NOT NULL,
  summarize_by    VARCHAR(20) NOT NULL DEFAULT 'Month',
  data_tab_name   VARCHAR(100) NOT NULL,
  detail_tab_name VARCHAR(100) DEFAULT NULL,
  last_synced_at  TIMESTAMP NULL,
  created_at      TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  updated_at      TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  UNIQUE KEY unique_mapping (company_id, spreadsheet_id, report_type, summarize_by),
  FOREIGN KEY (company_id) REFERENCES companies(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
