-- Migration 062: Mimecast multi-tenant credentials
-- Stores per-client Mimecast API credentials for held mail and other per-tenant queries

CREATE TABLE IF NOT EXISTS mimecast_tenants (
  id                  SERIAL PRIMARY KEY,
  company_id          BIGINT REFERENCES companies(id) ON DELETE SET NULL,
  account_code        VARCHAR(50),
  account_name        VARCHAR(255),
  client_id           VARCHAR(255) NOT NULL,
  client_secret       VARCHAR(255) NOT NULL,
  base_url            VARCHAR(255) DEFAULT 'https://api.services.mimecast.com',
  enabled             BOOLEAN DEFAULT true,
  notes               TEXT,
  created_at          TIMESTAMP WITHOUT TIME ZONE DEFAULT NOW(),
  updated_at          TIMESTAMP WITHOUT TIME ZONE DEFAULT NOW()
);

CREATE INDEX IF NOT EXISTS idx_mimecast_tenants_company ON mimecast_tenants(company_id);
CREATE INDEX IF NOT EXISTS idx_mimecast_tenants_enabled ON mimecast_tenants(enabled);
