-- ======================
-- ANALYTICS: Property
-- ======================
CREATE TABLE "unified_analytics_property" (
  "unified_connection_id"  VARCHAR NOT NULL,
  "unified_webhook_id"     VARCHAR NOT NULL,
  "unified_external_xref"  VARCHAR,
  "unified_integration_type" VARCHAR NOT NULL,
  "unified_raw_id"         VARCHAR,
  "unified_id"             VARCHAR NOT NULL,
  "id"                     VARCHAR,
  "created_at"             TIMESTAMP_NTZ,
  "updated_at"             TIMESTAMP_NTZ,
  "name"                   VARCHAR,
  "timezone"               VARCHAR,
  "currency"               VARCHAR,
  "industry"               VARCHAR,
  "parent_id"              VARCHAR,
  "raw"                    VARIANT,
  UNIQUE ("unified_connection_id", "unified_id")
);
-- ======================
-- ANALYTICS: Event
-- ======================
CREATE TABLE "unified_analytics_event" (
  "unified_connection_id"  VARCHAR NOT NULL,
  "unified_webhook_id"     VARCHAR NOT NULL,
  "unified_external_xref"  VARCHAR,
  "unified_integration_type" VARCHAR NOT NULL,
  "unified_raw_id"         VARCHAR,
  "unified_id"             VARCHAR NOT NULL,
  "id"                     VARCHAR,
  "created_at"             TIMESTAMP_NTZ,
  "updated_at"             TIMESTAMP_NTZ,
  "name"                   VARCHAR,
  "event_type"             VARCHAR,
  "visitor_id"             VARCHAR,
  "property_id"            VARCHAR,
  "session_id"             VARCHAR,
  "page_url"               VARCHAR,
  "page_title"             VARCHAR,
  "page_referrer"          VARCHAR,
  "device"                 VARCHAR,
  "browser"                VARCHAR,
  "os"                     VARCHAR,
  "country"                VARCHAR,
  "country_code"           VARCHAR,
  "region"                 VARCHAR,
  "city"                   VARCHAR,
  "metadata"               VARIANT,
  "value"                  FLOAT,
  "currency"               VARCHAR,
  "utm_source"             VARCHAR,
  "utm_medium"             VARCHAR,
  "utm_campaign"           VARCHAR,
  "utm_term"               VARCHAR,
  "utm_content"            VARCHAR,
  "raw"                    VARIANT,
  UNIQUE ("unified_connection_id", "unified_id")
);
-- ======================
-- ANALYTICS: Session
-- ======================
CREATE TABLE "unified_analytics_session" (
  "unified_connection_id"  VARCHAR NOT NULL,
  "unified_webhook_id"     VARCHAR NOT NULL,
  "unified_external_xref"  VARCHAR,
  "unified_integration_type" VARCHAR NOT NULL,
  "unified_raw_id"         VARCHAR,
  "unified_id"             VARCHAR NOT NULL,
  "id"                     VARCHAR,
  "created_at"             TIMESTAMP_NTZ,
  "updated_at"             TIMESTAMP_NTZ,
  "property_id"            VARCHAR,
  "visitor_id"             VARCHAR,
  "start_at"               TIMESTAMP_NTZ,
  "end_at"                 TIMESTAMP_NTZ,
  "duration_seconds"       FLOAT,
  "landing_page"           VARCHAR,
  "exit_page"              VARCHAR,
  "page_views"             FLOAT,
  "events_count"           FLOAT,
  "source"                 VARCHAR,
  "medium"                 VARCHAR,
  "campaign"               VARCHAR,
  "device"                 VARCHAR,
  "browser"                VARCHAR,
  "os"                     VARCHAR,
  "country"                VARCHAR,
  "city"                   VARCHAR,
  "is_bounce"              BOOLEAN,
  "is_conversion"          BOOLEAN,
  "raw"                    VARIANT,
  UNIQUE ("unified_connection_id", "unified_id")
);
-- ======================
-- ANALYTICS: Visitor
-- ======================
CREATE TABLE "unified_analytics_visitor" (
  "unified_connection_id"  VARCHAR NOT NULL,
  "unified_webhook_id"     VARCHAR NOT NULL,
  "unified_external_xref"  VARCHAR,
  "unified_integration_type" VARCHAR NOT NULL,
  "unified_raw_id"         VARCHAR,
  "unified_id"             VARCHAR NOT NULL,
  "id"                     VARCHAR,
  "created_at"             TIMESTAMP_NTZ,
  "updated_at"             TIMESTAMP_NTZ,
  "property_id"            VARCHAR,
  "email"                  VARCHAR,
  "name"                   VARCHAR,
  "age"                    FLOAT,
  "gender"                 VARCHAR,
  "country"                VARCHAR,
  "country_code"           VARCHAR,
  "city"                   VARCHAR,
  "language"               VARCHAR,
  "timezone"               VARCHAR,
  "first_seen_at"          TIMESTAMP_NTZ,
  "last_seen_at"           TIMESTAMP_NTZ,
  "total_sessions"         FLOAT,
  "total_page_views"       FLOAT,
  "total_events"           FLOAT,
  "metadata"               VARIANT,
  "raw"                    VARIANT,
  UNIQUE ("unified_connection_id", "unified_id")
);
-- ======================
-- ANALYTICS: Report
-- ======================
CREATE TABLE "unified_analytics_report" (
  "unified_connection_id"  VARCHAR NOT NULL,
  "unified_webhook_id"     VARCHAR NOT NULL,
  "unified_external_xref"  VARCHAR,
  "unified_integration_type" VARCHAR NOT NULL,
  "unified_raw_id"         VARCHAR,
  "unified_id"             VARCHAR NOT NULL,
  "id"                     VARCHAR,
  "created_at"             TIMESTAMP_NTZ,
  "updated_at"             TIMESTAMP_NTZ,
  "property_id"            VARCHAR,
  "start_at"               TIMESTAMP_NTZ,
  "end_at"                 TIMESTAMP_NTZ,
  "metrics"                VARIANT,
  "raw"                    VARIANT,
  UNIQUE ("unified_connection_id", "unified_id")
);
