-- ======================
-- ACCOUNTING: Account
-- ======================
CREATE TABLE "unified_accounting_account" (
  "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,
  "description"            VARCHAR,
  "type"                   VARCHAR,
  "status"                 VARCHAR,
  "balance"                FLOAT,
  "currency"               VARCHAR,
  "customer_defined_code"  VARCHAR,
  "is_payable"             BOOLEAN,
  "section"                VARCHAR,
  "subsection"             VARCHAR,
  "group"                  VARCHAR,
  "subgroup"               VARCHAR,
  "parent_id"              VARCHAR,
  "taxonomy"               VARIANT,
  "organization_id"        VARCHAR,
  "raw"                    VARIANT,
  UNIQUE ("unified_connection_id", "unified_id")
);
-- ======================
-- ACCOUNTING: Journal
-- ======================
CREATE TABLE "unified_accounting_journal" (
  "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,
  "reference"              VARCHAR,
  "tax_amount"             FLOAT,
  "currency"               VARCHAR,
  "lineitems"              VARIANT,
  "taxrate_id"             VARCHAR,
  "description"            VARCHAR,
  "posted_at"              TIMESTAMP_NTZ,
  "source"                 VARCHAR,
  "organization_id"        VARCHAR,
  "raw"                    VARIANT,
  UNIQUE ("unified_connection_id", "unified_id")
);
-- ======================
-- ACCOUNTING: Transaction
-- ======================
CREATE TABLE "unified_accounting_transaction" (
  "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,
  "memo"                   VARCHAR,
  "total_amount"           FLOAT,
  "tax_amount"             FLOAT,
  "account_id"             VARCHAR,
  "reference"              VARCHAR,
  "sub_total_amount"       FLOAT,
  "split_account_id"       VARCHAR,
  "payment_method"         VARCHAR,
  "payment_terms"          VARCHAR,
  "customer_message"       VARCHAR,
  "type"                   VARCHAR,
  "lineitems"              VARIANT,
  "currency"               VARCHAR,
  "contacts"               VARIANT,
  "organization_id"        VARCHAR,
  "raw"                    VARIANT,
  UNIQUE ("unified_connection_id", "unified_id")
);
-- ======================
-- ACCOUNTING: Contact
-- ======================
CREATE TABLE "unified_accounting_contact" (
  "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,
  "first_name"             VARCHAR,
  "last_name"              VARCHAR,
  "emails"                 VARIANT,
  "telephones"             VARIANT,
  "currency"               VARCHAR,
  "billing_address"        VARIANT,
  "shipping_address"       VARIANT,
  "is_active"              BOOLEAN,
  "tax_exemption"          VARCHAR,
  "tax_number"             VARCHAR,
  "is_customer"            BOOLEAN,
  "is_supplier"            BOOLEAN,
  "portal_url"             VARCHAR,
  "payment_methods"        VARIANT,
  "company_name"           VARCHAR,
  "identification"         VARCHAR,
  "associated_contacts"    VARIANT,
  "organization_id"        VARCHAR,
  "raw"                    VARIANT,
  UNIQUE ("unified_connection_id", "unified_id")
);
-- ======================
-- ACCOUNTING: Invoice
-- ======================
CREATE TABLE "unified_accounting_invoice" (
  "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,
  "due_at"                 TIMESTAMP_NTZ,
  "paid_at"                TIMESTAMP_NTZ,
  "refunded_at"            TIMESTAMP_NTZ,
  "cancelled_at"           TIMESTAMP_NTZ,
  "posted_at"              TIMESTAMP_NTZ,
  "total_amount"           FLOAT,
  "paid_amount"            FLOAT,
  "refund_amount"          FLOAT,
  "tax_amount"             FLOAT,
  "discount_amount"        FLOAT,
  "balance_amount"         FLOAT,
  "invoice_number"         VARCHAR,
  "reference"              VARCHAR,
  "contact_id"             VARCHAR,
  "currency"               VARCHAR,
  "notes"                  VARCHAR,
  "refund_reason"          VARCHAR,
  "term"                   VARCHAR,
  "lineitems"              VARIANT,
  "status"                 VARCHAR,
  "url"                    VARCHAR,
  "payment_collection_method" VARCHAR,
  "type"                   VARCHAR,
  "attachments"            VARIANT,
  "send"                   BOOLEAN,
  "organization_id"        VARCHAR,
  "raw"                    VARIANT,
  UNIQUE ("unified_connection_id", "unified_id")
);
-- ======================
-- ACCOUNTING: Bill
-- ======================
CREATE TABLE "unified_accounting_bill" (
  "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,
  "bill_number"            VARCHAR,
  "created_at"             TIMESTAMP_NTZ,
  "updated_at"             TIMESTAMP_NTZ,
  "due_at"                 TIMESTAMP_NTZ,
  "paid_at"                TIMESTAMP_NTZ,
  "refunded_at"            TIMESTAMP_NTZ,
  "cancelled_at"           TIMESTAMP_NTZ,
  "posted_at"              TIMESTAMP_NTZ,
  "total_amount"           FLOAT,
  "paid_amount"            FLOAT,
  "refund_amount"          FLOAT,
  "tax_amount"             FLOAT,
  "discount_amount"        FLOAT,
  "balance_amount"         FLOAT,
  "contact_id"             VARCHAR,
  "currency"               VARCHAR,
  "notes"                  VARCHAR,
  "refund_reason"          VARCHAR,
  "lineitems"              VARIANT,
  "status"                 VARCHAR,
  "url"                    VARCHAR,
  "payment_collection_method" VARCHAR,
  "attachments"            VARIANT,
  "send"                   BOOLEAN,
  "organization_id"        VARCHAR,
  "raw"                    VARIANT,
  "term"                   VARCHAR,
  UNIQUE ("unified_connection_id", "unified_id")
);
-- ======================
-- ACCOUNTING: Creditmemo
-- ======================
CREATE TABLE "unified_accounting_creditmemo" (
  "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,
  "due_at"                 TIMESTAMP_NTZ,
  "paid_at"                TIMESTAMP_NTZ,
  "refunded_at"            TIMESTAMP_NTZ,
  "cancelled_at"           TIMESTAMP_NTZ,
  "posted_at"              TIMESTAMP_NTZ,
  "total_amount"           FLOAT,
  "paid_amount"            FLOAT,
  "refund_amount"          FLOAT,
  "tax_amount"             FLOAT,
  "discount_amount"        FLOAT,
  "balance_amount"         FLOAT,
  "creditmemo_number"      VARCHAR,
  "contact_id"             VARCHAR,
  "invoice_id"             VARCHAR,
  "currency"               VARCHAR,
  "notes"                  VARCHAR,
  "refund_reason"          VARCHAR,
  "lineitems"              VARIANT,
  "status"                 VARCHAR,
  "url"                    VARCHAR,
  "payment_collection_method" VARCHAR,
  "attachments"            VARIANT,
  "send"                   BOOLEAN,
  "organization_id"        VARCHAR,
  "apply_amount"           FLOAT,
  "raw"                    VARIANT,
  UNIQUE ("unified_connection_id", "unified_id")
);
-- ======================
-- ACCOUNTING: Vendorcredit
-- ======================
CREATE TABLE "unified_accounting_vendorcredit" (
  "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,
  "due_at"                 TIMESTAMP_NTZ,
  "posted_at"              TIMESTAMP_NTZ,
  "total_amount"           FLOAT,
  "balance_amount"         FLOAT,
  "account_id"             VARCHAR,
  "currency"               VARCHAR,
  "contact_id"             VARCHAR,
  "bill_id"                VARCHAR,
  "notes"                  VARCHAR,
  "lineitems"              VARIANT,
  "status"                 VARCHAR,
  "organization_id"        VARCHAR,
  "apply_amount"           FLOAT,
  "raw"                    VARIANT,
  UNIQUE ("unified_connection_id", "unified_id")
);
-- ======================
-- ACCOUNTING: Taxrate
-- ======================
CREATE TABLE "unified_accounting_taxrate" (
  "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,
  "description"            VARCHAR,
  "rate"                   FLOAT,
  "is_active"              BOOLEAN,
  "organization_id"        VARCHAR,
  "raw"                    VARIANT,
  UNIQUE ("unified_connection_id", "unified_id")
);
-- ======================
-- ACCOUNTING: Organization
-- ======================
CREATE TABLE "unified_accounting_organization" (
  "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,
  "legal_name"             VARCHAR,
  "currency"               VARCHAR,
  "address"                VARIANT,
  "tax_number"             VARCHAR,
  "timezone"               VARCHAR,
  "website"                VARCHAR,
  "parent_id"              VARCHAR,
  "fiscal_year_end_month"  FLOAT,
  "organization_code"      VARCHAR,
  "raw"                    VARIANT,
  UNIQUE ("unified_connection_id", "unified_id")
);
-- ======================
-- ACCOUNTING: Order
-- ======================
CREATE TABLE "unified_accounting_order" (
  "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,
  "posted_at"              TIMESTAMP_NTZ,
  "contact_id"             VARCHAR,
  "account_id"             VARCHAR,
  "type"                   VARCHAR,
  "currency"               VARCHAR,
  "total_amount"           FLOAT,
  "shipping_address"       VARIANT,
  "billing_address"        VARIANT,
  "status"                 VARCHAR,
  "lineitems"              VARIANT,
  "raw"                    VARIANT,
  UNIQUE ("unified_connection_id", "unified_id")
);
-- ======================
-- ACCOUNTING: Purchaseorder
-- ======================
CREATE TABLE "unified_accounting_purchaseorder" (
  "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,
  "posted_at"              TIMESTAMP_NTZ,
  "contact_id"             VARCHAR,
  "account_id"             VARCHAR,
  "currency"               VARCHAR,
  "total_amount"           FLOAT,
  "shipping_address"       VARIANT,
  "billing_address"        VARIANT,
  "status"                 VARCHAR,
  "lineitems"              VARIANT,
  "organization_id"        VARCHAR,
  "raw"                    VARIANT,
  UNIQUE ("unified_connection_id", "unified_id")
);
-- ======================
-- ACCOUNTING: Salesorder
-- ======================
CREATE TABLE "unified_accounting_salesorder" (
  "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,
  "posted_at"              TIMESTAMP_NTZ,
  "contact_id"             VARCHAR,
  "account_id"             VARCHAR,
  "currency"               VARCHAR,
  "total_amount"           FLOAT,
  "shipping_address"       VARIANT,
  "billing_address"        VARIANT,
  "status"                 VARCHAR,
  "lineitems"              VARIANT,
  "sales_channel"          VARCHAR,
  "organization_id"        VARCHAR,
  "fees"                   VARIANT,
  "raw"                    VARIANT,
  UNIQUE ("unified_connection_id", "unified_id")
);
-- ======================
-- ACCOUNTING: Report
-- ======================
CREATE TABLE "unified_accounting_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,
  "type"                   VARCHAR,
  "name"                   VARCHAR,
  "currency"               VARCHAR,
  "start_at"               TIMESTAMP_NTZ,
  "end_at"                 TIMESTAMP_NTZ,
  "balance_sheet"          VARIANT,
  "profit_and_loss"        VARIANT,
  "trial_balance"          VARIANT,
  "raw"                    VARIANT,
  UNIQUE ("unified_connection_id", "unified_id")
);
-- ======================
-- ACCOUNTING: Balancesheet
-- ======================
CREATE TABLE "unified_accounting_balancesheet" (
  "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,
  "start_at"               TIMESTAMP_NTZ,
  "end_at"                 TIMESTAMP_NTZ,
  "name"                   VARCHAR,
  "currency"               VARCHAR,
  "net_assets_amount"      FLOAT,
  "assets"                 VARIANT,
  "liabilities"            VARIANT,
  "equity"                 VARIANT,
  "raw"                    VARIANT,
  UNIQUE ("unified_connection_id", "unified_id")
);
-- ======================
-- ACCOUNTING: Trialbalance
-- ======================
CREATE TABLE "unified_accounting_trialbalance" (
  "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,
  "start_at"               TIMESTAMP_NTZ,
  "name"                   VARCHAR,
  "currency"               VARCHAR,
  "end_at"                 TIMESTAMP_NTZ,
  "total_debit_amount"     FLOAT,
  "total_credit_amount"    FLOAT,
  "sub_items"              VARIANT,
  "raw"                    VARIANT,
  UNIQUE ("unified_connection_id", "unified_id")
);
-- ======================
-- ACCOUNTING: Profitloss
-- ======================
CREATE TABLE "unified_accounting_profitlos" (
  "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,
  "category_ids"           VARIANT,
  "start_at"               TIMESTAMP_NTZ,
  "end_at"                 TIMESTAMP_NTZ,
  "name"                   VARCHAR,
  "currency"               VARCHAR,
  "income"                 VARIANT,
  "expenses"               VARIANT,
  "cost_of_goods_sold"     VARIANT,
  "gross_profit_amount"    FLOAT,
  "net_profit_amount"      FLOAT,
  "income_total_amount"    FLOAT,
  "net_income_amount"      FLOAT,
  "expenses_total_amount"  FLOAT,
  "cost_of_goods_sold_total_amount" FLOAT,
  "income_sections"        VARIANT,
  "expenses_sections"      VARIANT,
  "cost_of_goods_sold_sections" VARIANT,
  "raw"                    VARIANT,
  UNIQUE ("unified_connection_id", "unified_id")
);
-- ======================
-- ACCOUNTING: Cashflow
-- ======================
CREATE TABLE "unified_accounting_cashflow" (
  "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,
  "start_at"               TIMESTAMP_NTZ,
  "end_at"                 TIMESTAMP_NTZ,
  "category_ids"           VARIANT,
  "contact_id"             VARCHAR,
  "name"                   VARCHAR,
  "currency"               VARCHAR,
  "cash_beginning_amount"  FLOAT,
  "cash_ending_amount"     FLOAT,
  "net_change_in_cash_amount" FLOAT,
  "operating_sections"     VARIANT,
  "investing_sections"     VARIANT,
  "financing_sections"     VARIANT,
  "raw"                    VARIANT,
  UNIQUE ("unified_connection_id", "unified_id")
);
-- ======================
-- ACCOUNTING: Category
-- ======================
CREATE TABLE "unified_accounting_category" (
  "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,
  "description"            VARCHAR,
  "is_active"              BOOLEAN,
  "parent_id"              VARCHAR,
  "raw"                    VARIANT,
  UNIQUE ("unified_connection_id", "unified_id")
);
-- ======================
-- ACCOUNTING: Expense
-- ======================
CREATE TABLE "unified_accounting_expense" (
  "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,
  "user_id"                VARCHAR,
  "contact_id"             VARCHAR,
  "account_id"             VARCHAR,
  "name"                   VARCHAR,
  "payment_method"         VARCHAR,
  "posted_at"              TIMESTAMP_NTZ,
  "total_amount"           FLOAT,
  "currency"               VARCHAR,
  "tax_amount"             FLOAT,
  "reimbursed_amount"      FLOAT,
  "reimbursed_at"          TIMESTAMP_NTZ,
  "approved_at"            TIMESTAMP_NTZ,
  "approver_user_id"       VARCHAR,
  "lineitems"              VARIANT,
  "attachments"            VARIANT,
  "organization_id"        VARCHAR,
  "raw"                    VARIANT,
  UNIQUE ("unified_connection_id", "unified_id")
);
