Skip to main content

Data Model Architecture

The portal hierarchy consists of three tables in the portal schema that provide a consistent structure for managing customer accounts.

Schema Diagram

View:
Complete account hierarchy with CieTrade integration
PORTAL HIERARCHY (portal schema)Tier 1Tier 2Tier 31:N1:NCPIDwg_parent_accountsparent_account_idwg_accountscietrade_account_idwg_account_locationscietrade_address_idnew_ct.accountsaccount_id = CPIDnew_ct.addressesaddress_idPortal schemaCieTrade source

Table Definitions

Tier 1: Parent Accounts

Top-level entity representing the customer organization (e.g., "UPS").

portal.wg_parent_accounts
ColumnTypePurpose
parent_account_idrequiredINT IDENTITY(1001,1)Primary key
parent_account_namerequiredVARCHAR(250)Customer name (e.g., "UPS")
parent_display_nameVARCHAR(250)Display name (usually same as name)
portal_load_phaseINTLoading priority
active_accountBITActive flag

Tier 2: Accounts

Links to CieTrade counterparties via CPID.

portal.wg_accounts
ColumnTypePurpose
account_idrequiredINT IDENTITY(11,1)Primary key
parent_account_idrequiredINTFK to wg_parent_accounts
account_namerequiredVARCHAR(250)Account/facility name
cietrade_account_idrequiredINTCPID - links to new_ct.accounts.account_id
Unique Constraint

cietrade_account_id has a unique constraint preventing duplicate CieTrade links.

Tier 3: Account Locations

Individual service addresses linked to CieTrade addresses.

portal.wg_account_locations
ColumnTypePurpose
location_idrequiredINT IDENTITYPrimary key
account_idrequiredINTFK to wg_accounts
cietrade_address_idINTLinks to new_ct.addresses.address_id
location_namerequiredVARCHAR(250)Location identifier (business key)
addressVARCHARStreet address
cityVARCHARCity
stateVARCHARState
zipVARCHARZIP code
location_udf1VARCHARUser-defined field 1
location_udf2VARCHARUser-defined field 2
location_udf3VARCHARUser-defined field 3
location_udf4VARCHARUser-defined field 4
cietrade_active_statusVARCHARActive/Inactive flag
Unique Constraint

Composite unique constraint on (location_name, account_id).

Relationship Cardinalities

The hierarchy supports two patterns:

PatternStructureWhen to Use
Standard (1:1:N)1 Parent → 1 Account → N LocationsSingle CPID with multiple service addresses
Complex (1:N:N)1 Parent → N Accounts → N LocationsMultiple CPIDs requiring consolidated reporting (e.g., UPS, McKesson)

Key Join Fields

Portal FieldCieTrade FieldNotes
cietrade_account_idaccounts.account_idCPID - counterparty identifier
cietrade_address_idaddresses.address_idLocation identifier
location_nameaddresses.location_nameBusiness key - must match exactly
Critical Join Rule

Always join on BOTH cietrade_account_id (CPID) AND location_name. Address IDs alone are insufficient because location_name is the business key.

Standard Join Pattern

-- Join CieTrade fact tables to portal hierarchy
FROM new_ct.billing_charges bc
JOIN portal.vw_wg_accounts v
ON v.cietrade_account_id = bc.account_id
AND v.location_name = bc.location_name

Primary Interface

portal.vw_wg_accounts is the primary integration point for all reporting. This view flattens the three-tier hierarchy into a single queryable interface.