-- ======================
-- CDP: Profile
-- ======================
CREATE TABLE unified_cdp_profile (
  unified_connection_id  text NOT NULL,
  unified_webhook_id     text NOT NULL,
  unified_external_xref  text,
  unified_integration_type text NOT NULL,
  unified_raw_id         text,
  unified_id             text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  name                 text,
  first_name           text,
  last_name            text,
  email                text,
  telephone            text,
  gender               text,
  birthdate            text,
  title                text,
  company              text,
  address              jsonb,
  identifiers          jsonb,
  metadata             jsonb,
  segments             jsonb,
  is_anonymous         boolean,
  consent              jsonb,
  source_id            text,
  raw                  jsonb
);
-- ======================
-- CDP: Segment
-- ======================
CREATE TABLE unified_cdp_segment (
  unified_connection_id  text NOT NULL,
  unified_webhook_id     text NOT NULL,
  unified_external_xref  text,
  unified_integration_type text NOT NULL,
  unified_raw_id         text,
  unified_id             text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  name                 text,
  slug                 text,
  description          text,
  definition           text,
  type                 text,
  compute_mode         text,
  size                 numeric,
  is_active            boolean,
  source_id            text,
  raw                  jsonb
);
-- ======================
-- CDP: Event
-- ======================
CREATE TABLE unified_cdp_event (
  unified_connection_id  text NOT NULL,
  unified_webhook_id     text NOT NULL,
  unified_external_xref  text,
  unified_integration_type text NOT NULL,
  unified_raw_id         text,
  unified_id             text NOT NULL,
  id                   text,
  created_at           timestamptz,
  name                 text,
  type                 text,
  occurred_at          timestamptz,
  profile_id           text,
  identifiers          jsonb,
  metadata             jsonb,
  source               text,
  source_id            text,
  raw                  jsonb
);
-- ======================
-- CDP: Source
-- ======================
CREATE TABLE unified_cdp_source (
  unified_connection_id  text NOT NULL,
  unified_webhook_id     text NOT NULL,
  unified_external_xref  text,
  unified_integration_type text NOT NULL,
  unified_raw_id         text,
  unified_id             text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  name                 text,
  slug                 text,
  type                 text,
  direction            text,
  is_enabled           boolean,
  raw                  jsonb
);
-- ======================
-- CDP: Destination
-- ======================
CREATE TABLE unified_cdp_destination (
  unified_connection_id  text NOT NULL,
  unified_webhook_id     text NOT NULL,
  unified_external_xref  text,
  unified_integration_type text NOT NULL,
  unified_raw_id         text,
  unified_id             text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  name                 text,
  slug                 text,
  type                 text,
  direction            text,
  is_enabled           boolean,
  raw                  jsonb
);
-- ======================
-- CDP: Activation
-- ======================
CREATE TABLE unified_cdp_activation (
  unified_connection_id  text NOT NULL,
  unified_webhook_id     text NOT NULL,
  unified_external_xref  text,
  unified_integration_type text NOT NULL,
  unified_raw_id         text,
  unified_id             text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  name                 text,
  segment_id           text,
  destination_id       text,
  source_id            text,
  schedule             text,
  status               text,
  last_run_at          timestamptz,
  is_enabled           boolean,
  raw                  jsonb
);
