Add Canonical Party as generated in semprini-blog-dataproducts
The canonical data product for the Digital Core domain, copied unchanged from the blog repository's products/canonical-party (generated by /agent-product from data_model/data_products/canonical.md, 65 of 65 checks on the blog's stack on 2026-09-09). The next commit adapts it to the domain platform. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
commit
cfb32d2d1b
20 files changed
+2222
No files matched your search
@@ -0,0 +1,59 @@
|
||||
{
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||
"$id": "urn:digital-core:canonical-party:address",
|
||||
"title": "Address",
|
||||
"description": "An Address is the canonical record of a location. It holds the structured components of the place itself and nothing else: no party, no purpose, no verification. Those belong on Contact Address. Canonical record published by Canonical Party. Property names are the ODS column names. Used for both the inbound topic (records producers publish) and the compacted outbound topic (every change, keyed by address_id).",
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"required": ["address_id", "country"],
|
||||
"properties": {
|
||||
"address_id": {
|
||||
"type": "string",
|
||||
"format": "uuid",
|
||||
"description": "Globally unique identifier for this location. Immutable once assigned. Many parties may reference the same identifier through their Contact Address records."
|
||||
},
|
||||
"address_type": {
|
||||
"type": ["string", "null"],
|
||||
"enum": ["Street Address", "PO Box", "Registered Office", "Overseas Address", null],
|
||||
"description": "The structural type of the address. Determines which components apply: a PO Box has no street, and an overseas address may have no state or region."
|
||||
},
|
||||
"address_line_1": {
|
||||
"type": ["string", "null"],
|
||||
"description": "The primary street line, typically number and street name. For a PO Box, the box number."
|
||||
},
|
||||
"address_line_2": {
|
||||
"type": ["string", "null"],
|
||||
"description": "Secondary line for a unit, level, suite or building name."
|
||||
},
|
||||
"suburb": {
|
||||
"type": ["string", "null"],
|
||||
"description": "The suburb or locality. Kept distinct from City because in Australia and New Zealand they are genuinely different things and merging them breaks delivery."
|
||||
},
|
||||
"city": {
|
||||
"type": ["string", "null"],
|
||||
"description": "The city or town."
|
||||
},
|
||||
"state_or_region": {
|
||||
"type": ["string", "null"],
|
||||
"description": "The state, territory, province or region, or the local equivalent."
|
||||
},
|
||||
"postcode": {
|
||||
"type": ["string", "null"],
|
||||
"description": "The postal code. Held as a string to preserve leading zeros and to support formats that are not numeric."
|
||||
},
|
||||
"country": {
|
||||
"type": "string",
|
||||
"description": "ISO 3166-1 alpha-2 country code. Mandatory for every address type."
|
||||
},
|
||||
"created_at": {
|
||||
"type": ["string", "null"],
|
||||
"format": "date-time",
|
||||
"description": "Set by the ODS. Optional on the inbound topic."
|
||||
},
|
||||
"updated_at": {
|
||||
"type": ["string", "null"],
|
||||
"format": "date-time",
|
||||
"description": "Set by the ODS on every change. Optional on the inbound topic."
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
{
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||
"$id": "urn:digital-core:canonical-party:company",
|
||||
"title": "Company",
|
||||
"description": "A Company is an organisation with legal standing: a company, partnership, trust, cooperative, charity or public body. It specialises Party and carries the registration and structure attributes that only apply to organisations. Canonical record published by Canonical Party. Property names are the ODS column names. Used for both the inbound topic (records producers publish) and the compacted outbound topic (every change, keyed by company_id).",
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"required": ["company_id"],
|
||||
"properties": {
|
||||
"company_id": {
|
||||
"type": "string",
|
||||
"format": "uuid",
|
||||
"description": "The Party Identifier of the party this company extends (extends Party)."
|
||||
},
|
||||
"company_registration_number": {
|
||||
"type": ["string", "null"],
|
||||
"description": "The registration identifier issued by the relevant companies registry, such as an ACN in Australia, an NZBN in New Zealand or a Companies House number in the UK. The most reliable way to tell two similarly named organisations apart."
|
||||
},
|
||||
"incorporation_country": {
|
||||
"type": ["string", "null"],
|
||||
"description": "ISO 3166-1 alpha-2 code for the country the organisation is incorporated in. Determines which registry the registration number belongs to, and which country's company law applies."
|
||||
},
|
||||
"incorporation_date": {
|
||||
"type": ["string", "null"],
|
||||
"format": "date",
|
||||
"description": "Date the organisation was formally incorporated or registered."
|
||||
},
|
||||
"legal_structure": {
|
||||
"type": ["string", "null"],
|
||||
"enum": ["Private Company", "Public Company", "Partnership", "Sole Trader", "Trust", "Cooperative", "Government Entity", "Non-Profit", null],
|
||||
"description": "The legal form the organisation takes. Determines signing authority, liability and the evidence required to establish who controls it."
|
||||
},
|
||||
"tax_identifier": {
|
||||
"type": ["string", "null"],
|
||||
"description": "Tax registration number issued by the relevant revenue authority, such as an ABN, VAT number or EIN. Needed to invoice the organisation correctly."
|
||||
},
|
||||
"created_at": {
|
||||
"type": ["string", "null"],
|
||||
"format": "date-time",
|
||||
"description": "Set by the ODS. Optional on the inbound topic."
|
||||
},
|
||||
"updated_at": {
|
||||
"type": ["string", "null"],
|
||||
"format": "date-time",
|
||||
"description": "Set by the ODS on every change. Optional on the inbound topic."
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
{
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||
"$id": "urn:digital-core:canonical-party:contact_address",
|
||||
"title": "Contact Address",
|
||||
"description": "A Contact Address is the link between a Party and an Address: what the address is used for, whether it has been confirmed, and the period it was in use. It is not the address itself; the location lives in the Address entity and is shared. Canonical record published by Canonical Party. Property names are the ODS column names. Used for both the inbound topic (records producers publish) and the compacted outbound topic (every change, keyed by contact_address_id).",
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"required": ["contact_address_id", "party_id", "address_id"],
|
||||
"properties": {
|
||||
"contact_address_id": {
|
||||
"type": "string",
|
||||
"format": "uuid",
|
||||
"description": "Globally unique identifier for this party-to-address association."
|
||||
},
|
||||
"address_purpose": {
|
||||
"type": ["string", "null"],
|
||||
"enum": ["Home", "Mailing", "Business", "Registered Office", "Billing", "Delivery", null],
|
||||
"description": "What the party uses this address for. A party can hold several addresses at once for different purposes: home, billing and delivery are frequently different places."
|
||||
},
|
||||
"is_primary": {
|
||||
"type": ["boolean", "null"],
|
||||
"default": false,
|
||||
"description": "Whether this is the party's main address for the given purpose. At most one address may be primary per purpose at any point in time."
|
||||
},
|
||||
"verification_status": {
|
||||
"type": ["string", "null"],
|
||||
"enum": ["Unverified", "Verified", "Failed", "Expired", null],
|
||||
"description": "Whether this address has been confirmed as real and current. Unverified addresses are usable but should not be relied on for anything expensive, such as a physical delivery."
|
||||
},
|
||||
"verification_date": {
|
||||
"type": ["string", "null"],
|
||||
"format": "date",
|
||||
"description": "When the address was last confirmed. Verification ages: an address confirmed five years ago is weaker evidence than one confirmed last month."
|
||||
},
|
||||
"verification_method": {
|
||||
"type": ["string", "null"],
|
||||
"enum": ["Documentary", "Electronic", "In Person", "Self Declared", null],
|
||||
"description": "How the address was confirmed. Recorded because the methods are not equally strong, and knowing which was used determines how much weight to put on the result."
|
||||
},
|
||||
"valid_from": {
|
||||
"type": ["string", "null"],
|
||||
"format": "date",
|
||||
"description": "The date the party started using this address for the stated purpose."
|
||||
},
|
||||
"valid_to": {
|
||||
"type": ["string", "null"],
|
||||
"format": "date",
|
||||
"description": "The date the party stopped using it. Null means still in use. Closed associations are kept rather than deleted, so historical lookups stay accurate."
|
||||
},
|
||||
"party_id": {
|
||||
"type": "string",
|
||||
"format": "uuid",
|
||||
"description": "Identifier of the owning Party (Party Has Contact Addresses)."
|
||||
},
|
||||
"address_id": {
|
||||
"type": "string",
|
||||
"format": "uuid",
|
||||
"description": "Identifier of the referenced Address (Contact Address References Address)."
|
||||
},
|
||||
"created_at": {
|
||||
"type": ["string", "null"],
|
||||
"format": "date-time",
|
||||
"description": "Set by the ODS. Optional on the inbound topic."
|
||||
},
|
||||
"updated_at": {
|
||||
"type": ["string", "null"],
|
||||
"format": "date-time",
|
||||
"description": "Set by the ODS on every change. Optional on the inbound topic."
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
{
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||
"$id": "urn:digital-core:canonical-party:customer",
|
||||
"title": "Customer",
|
||||
"description": "A Customer is a Party Role representing an active or prospective commercial relationship: someone who buys, subscribes, or holds an account with the business. Canonical record published by Canonical Party. Property names are the ODS column names. Used for both the inbound topic (records producers publish) and the compacted outbound topic (every change, keyed by customer_id).",
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"required": ["customer_id", "customer_number"],
|
||||
"properties": {
|
||||
"customer_id": {
|
||||
"type": "string",
|
||||
"format": "uuid",
|
||||
"description": "The Role Identifier of the party role this customer extends (extends Party Role)."
|
||||
},
|
||||
"customer_number": {
|
||||
"type": "string",
|
||||
"description": "The customer identifier quoted in correspondence and used by service and support staff. Unlike the Party Identifier, this one is meant to be readable aloud over the phone. Unique."
|
||||
},
|
||||
"onboarding_date": {
|
||||
"type": ["string", "null"],
|
||||
"format": "date",
|
||||
"description": "Date the customer onboarding process was completed."
|
||||
},
|
||||
"relationship_start_date": {
|
||||
"type": ["string", "null"],
|
||||
"format": "date",
|
||||
"description": "Date the customer relationship became effective. May precede the onboarding date where a relationship was migrated in from another system or acquired with another business."
|
||||
},
|
||||
"created_at": {
|
||||
"type": ["string", "null"],
|
||||
"format": "date-time",
|
||||
"description": "Set by the ODS. Optional on the inbound topic."
|
||||
},
|
||||
"updated_at": {
|
||||
"type": ["string", "null"],
|
||||
"format": "date-time",
|
||||
"description": "Set by the ODS on every change. Optional on the inbound topic."
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
{
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||
"$id": "urn:digital-core:canonical-party:party",
|
||||
"title": "Party",
|
||||
"description": "A Party is any individual or organisation the business has, or may have, a relationship with. It is the foundational abstract concept of the domain: it carries only what is true of every party, whoever they are. Canonical record published by Canonical Party. Property names are the ODS column names. Used for both the inbound topic (records producers publish) and the compacted outbound topic (every change, keyed by party_id).",
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"required": ["party_id", "party_type", "legal_name"],
|
||||
"properties": {
|
||||
"party_id": {
|
||||
"type": "string",
|
||||
"format": "uuid",
|
||||
"description": "Globally unique identifier for this party across all systems. Immutable once assigned."
|
||||
},
|
||||
"party_type": {
|
||||
"type": "string",
|
||||
"enum": ["Person", "Company"],
|
||||
"description": "Discriminator naming the subtype (Person or Company) that extends this party."
|
||||
},
|
||||
"legal_name": {
|
||||
"type": "string",
|
||||
"description": "The party's full name as it appears on official documentation. For an individual this is the full given and family name; for an organisation it is the registered name."
|
||||
},
|
||||
"also_known_as": {
|
||||
"type": ["string", "null"],
|
||||
"description": "Alternative names: trading names, former names, maiden names, or the name a person actually goes by. Several names are separated by semicolons."
|
||||
},
|
||||
"party_status": {
|
||||
"type": ["string", "null"],
|
||||
"enum": ["Prospect", "Active", "Suspended", "Inactive", "Closed", null],
|
||||
"description": "Where the party sits in its lifecycle with the business. Controls whether new relationships may be established."
|
||||
},
|
||||
"created_at": {
|
||||
"type": ["string", "null"],
|
||||
"format": "date-time",
|
||||
"description": "Set by the ODS. Optional on the inbound topic."
|
||||
},
|
||||
"updated_at": {
|
||||
"type": ["string", "null"],
|
||||
"format": "date-time",
|
||||
"description": "Set by the ODS on every change. Optional on the inbound topic."
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
{
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||
"$id": "urn:digital-core:canonical-party:party_association",
|
||||
"title": "Party Related To Party",
|
||||
"description": "A Party may be related to other Parties through ownership, control, employment, household or family ties. A relationship instance is directional and named; the same pair of parties may hold several associations of different types at once. Canonical record published by Canonical Party. Property names are the ODS column names. Used for both the inbound topic (records producers publish) and the compacted outbound topic (every change, keyed by party_association_id).",
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"required": ["party_association_id", "source_party_id", "target_party_id"],
|
||||
"properties": {
|
||||
"party_association_id": {
|
||||
"type": "string",
|
||||
"format": "uuid",
|
||||
"description": "Globally unique identifier for this party-to-party association."
|
||||
},
|
||||
"source_party_id": {
|
||||
"type": "string",
|
||||
"format": "uuid",
|
||||
"description": "Identifier of the Party the association is stated from."
|
||||
},
|
||||
"target_party_id": {
|
||||
"type": "string",
|
||||
"format": "uuid",
|
||||
"description": "Identifier of the Party the association points at."
|
||||
},
|
||||
"association_type": {
|
||||
"type": ["string", "null"],
|
||||
"enum": ["Parent Organisation", "Subsidiary", "Owner", "Director", "Authorised Signatory", "Employer", "Employee", "Partner", "Family Member", "Household Member", null],
|
||||
"description": "The nature of the relationship between the two parties, read from source to target."
|
||||
},
|
||||
"association_start_date": {
|
||||
"type": ["string", "null"],
|
||||
"format": "date",
|
||||
"description": "The date the association began."
|
||||
},
|
||||
"association_end_date": {
|
||||
"type": ["string", "null"],
|
||||
"format": "date",
|
||||
"description": "The date the association ended. Null means still current."
|
||||
},
|
||||
"verified": {
|
||||
"type": ["boolean", "null"],
|
||||
"description": "Whether the association has been confirmed against acceptable evidence."
|
||||
},
|
||||
"created_at": {
|
||||
"type": ["string", "null"],
|
||||
"format": "date-time",
|
||||
"description": "Set by the ODS. Optional on the inbound topic."
|
||||
},
|
||||
"updated_at": {
|
||||
"type": ["string", "null"],
|
||||
"format": "date-time",
|
||||
"description": "Set by the ODS on every change. Optional on the inbound topic."
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
{
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||
"$id": "urn:digital-core:canonical-party:party_role",
|
||||
"title": "Party Role",
|
||||
"description": "A Party Role is the capacity in which a Party acts. It separates who someone is from what they are doing. Canonical record published by Canonical Party. Property names are the ODS column names. Used for both the inbound topic (records producers publish) and the compacted outbound topic (every change, keyed by party_role_id).",
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"required": ["party_role_id", "party_role_type", "party_id"],
|
||||
"properties": {
|
||||
"party_role_id": {
|
||||
"type": "string",
|
||||
"format": "uuid",
|
||||
"description": "Globally unique identifier for this role instance. Distinct from the Party Identifier: one party holding two roles has two Role Identifiers."
|
||||
},
|
||||
"party_role_type": {
|
||||
"type": "string",
|
||||
"enum": ["Customer"],
|
||||
"description": "Discriminator naming the subtype (Customer) that extends this role."
|
||||
},
|
||||
"role_status": {
|
||||
"type": ["string", "null"],
|
||||
"enum": ["Pending", "Active", "Suspended", "Closed", null],
|
||||
"description": "The current lifecycle status of this role. Controls whether the role confers its business permissions."
|
||||
},
|
||||
"role_start_date": {
|
||||
"type": ["string", "null"],
|
||||
"format": "date",
|
||||
"description": "The date this role became effective."
|
||||
},
|
||||
"role_end_date": {
|
||||
"type": ["string", "null"],
|
||||
"format": "date",
|
||||
"description": "The date this role ceased to be effective. Null means the role is still open. Roles are closed rather than deleted, so that history stays intact."
|
||||
},
|
||||
"party_id": {
|
||||
"type": "string",
|
||||
"format": "uuid",
|
||||
"description": "Identifier of the owning Party (Party Assumes Roles)."
|
||||
},
|
||||
"created_at": {
|
||||
"type": ["string", "null"],
|
||||
"format": "date-time",
|
||||
"description": "Set by the ODS. Optional on the inbound topic."
|
||||
},
|
||||
"updated_at": {
|
||||
"type": ["string", "null"],
|
||||
"format": "date-time",
|
||||
"description": "Set by the ODS on every change. Optional on the inbound topic."
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
{
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||
"$id": "urn:digital-core:canonical-party:party_role_contact_address",
|
||||
"title": "Party Role Uses Contact Addresses",
|
||||
"description": "A Party Role may use one or more Contact Addresses owned by the underlying Party. The Party owns its addresses; a role picks which of them applies in its context. Canonical record published by Canonical Party. Property names are the ODS column names. Used for both the inbound topic (records producers publish) and the compacted outbound topic (every change, keyed by party_role_contact_address_id).",
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"required": ["party_role_contact_address_id", "party_role_id", "contact_address_id"],
|
||||
"properties": {
|
||||
"party_role_contact_address_id": {
|
||||
"type": "string",
|
||||
"format": "uuid",
|
||||
"description": "Globally unique identifier for this role-to-contact-address association."
|
||||
},
|
||||
"party_role_id": {
|
||||
"type": "string",
|
||||
"format": "uuid",
|
||||
"description": "Identifier of the Party Role that uses the contact address."
|
||||
},
|
||||
"contact_address_id": {
|
||||
"type": "string",
|
||||
"format": "uuid",
|
||||
"description": "Identifier of the Contact Address the role uses."
|
||||
},
|
||||
"created_at": {
|
||||
"type": ["string", "null"],
|
||||
"format": "date-time",
|
||||
"description": "Set by the ODS. Optional on the inbound topic."
|
||||
},
|
||||
"updated_at": {
|
||||
"type": ["string", "null"],
|
||||
"format": "date-time",
|
||||
"description": "Set by the ODS on every change. Optional on the inbound topic."
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
{
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||
"$id": "urn:digital-core:canonical-party:person",
|
||||
"title": "Person",
|
||||
"description": "A Person is a human being. Person specialises Party, inheriting everything that is true of any party and adding what only applies to people. Canonical record published by Canonical Party. Property names are the ODS column names. Used for both the inbound topic (records producers publish) and the compacted outbound topic (every change, keyed by person_id).",
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"required": ["person_id"],
|
||||
"properties": {
|
||||
"person_id": {
|
||||
"type": "string",
|
||||
"format": "uuid",
|
||||
"description": "The Party Identifier of the party this person extends (extends Party)."
|
||||
},
|
||||
"date_of_birth": {
|
||||
"type": ["string", "null"],
|
||||
"format": "date",
|
||||
"description": "The individual's date of birth. Used to confirm identity, to check age eligibility for age-restricted products, and to avoid confusing two people with the same name."
|
||||
},
|
||||
"preferred_name": {
|
||||
"type": ["string", "null"],
|
||||
"description": "What the person actually wants to be called, when that differs from their legal name. Used for greetings and correspondence."
|
||||
},
|
||||
"country_of_residence": {
|
||||
"type": ["string", "null"],
|
||||
"description": "ISO 3166-1 alpha-2 code for the country the individual currently lives in. Drives tax treatment, applicable consumer law, currency defaults and delivery options."
|
||||
},
|
||||
"created_at": {
|
||||
"type": ["string", "null"],
|
||||
"format": "date-time",
|
||||
"description": "Set by the ODS. Optional on the inbound topic."
|
||||
},
|
||||
"updated_at": {
|
||||
"type": ["string", "null"],
|
||||
"format": "date-time",
|
||||
"description": "Set by the ODS on every change. Optional on the inbound topic."
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,748 @@
|
||||
-- Canonical Party: streaming job (Flink SQL, Flink 2.1).
|
||||
-- Submitted by the platform CLI with `bin/sql-client.sh -f job.sql` on the jobmanager.
|
||||
--
|
||||
-- Per entity table, four Flink tables and two continuous INSERTs:
|
||||
-- <table>_inbound kafka Publish Input: records producers publish (JSON, schema in events/schemas)
|
||||
-- <table>_ods jdbc upserts inbound records into the ODS table by primary key
|
||||
-- <table>_cdc postgres-cdc every change committed to the ODS table, however it arrived
|
||||
-- <table>_outbound upsert-kafka Subscribe Output: compacted topic keyed by <table>_id, deletes as tombstones
|
||||
-- Column lists match the ODS table (snake_case). Types follow the mapping table in template/README.md.
|
||||
-- Requires the connector jars listed under "Platform prerequisites" in template/README.md.
|
||||
-- Nine tables: with pg_duckpipe's two slots this job needs eleven replication slots on the ODS,
|
||||
-- one more than max_replication_slots=10 allows; raise the limit before submitting it.
|
||||
|
||||
SET 'pipeline.name' = 'canonical-party';
|
||||
SET 'execution.checkpointing.interval' = '10 s';
|
||||
|
||||
-- Party
|
||||
|
||||
CREATE TABLE party_inbound (
|
||||
party_id STRING,
|
||||
party_type STRING,
|
||||
legal_name STRING,
|
||||
also_known_as STRING,
|
||||
party_status STRING
|
||||
) WITH (
|
||||
'connector' = 'kafka',
|
||||
'topic' = 'digital-core.canonical-party.party.inbound',
|
||||
'properties.bootstrap.servers' = 'kafka:29092',
|
||||
'properties.group.id' = 'canonical-party.party.inbound',
|
||||
'scan.startup.mode' = 'group-offsets',
|
||||
'properties.auto.offset.reset' = 'earliest',
|
||||
'format' = 'json',
|
||||
'json.fail-on-missing-field' = 'false',
|
||||
'json.ignore-parse-errors' = 'false',
|
||||
'json.timestamp-format.standard' = 'ISO-8601'
|
||||
);
|
||||
|
||||
CREATE TABLE party_ods (
|
||||
party_id STRING,
|
||||
party_type STRING,
|
||||
legal_name STRING,
|
||||
also_known_as STRING,
|
||||
party_status STRING,
|
||||
PRIMARY KEY (party_id) NOT ENFORCED
|
||||
) WITH (
|
||||
'connector' = 'jdbc',
|
||||
'url' = 'jdbc:postgresql://postgres:5432/digital?stringtype=unspecified',
|
||||
'table-name' = 'canonical_party.party',
|
||||
'username' = 'semprini',
|
||||
'password' = 'semprini'
|
||||
);
|
||||
|
||||
CREATE TABLE party_cdc (
|
||||
party_id STRING,
|
||||
party_type STRING,
|
||||
legal_name STRING,
|
||||
also_known_as STRING,
|
||||
party_status STRING,
|
||||
updated_at TIMESTAMP_LTZ(6),
|
||||
PRIMARY KEY (party_id) NOT ENFORCED
|
||||
) WITH (
|
||||
'connector' = 'postgres-cdc',
|
||||
'hostname' = 'postgres',
|
||||
'port' = '5432',
|
||||
'username' = 'semprini',
|
||||
'password' = 'semprini',
|
||||
'database-name' = 'digital',
|
||||
'schema-name' = 'canonical_party',
|
||||
'table-name' = 'party',
|
||||
'slot.name' = 'canonical_party_party_flink',
|
||||
'decoding.plugin.name' = 'pgoutput',
|
||||
'scan.incremental.snapshot.enabled' = 'true'
|
||||
);
|
||||
|
||||
CREATE TABLE party_outbound (
|
||||
party_id STRING,
|
||||
party_type STRING,
|
||||
legal_name STRING,
|
||||
also_known_as STRING,
|
||||
party_status STRING,
|
||||
updated_at TIMESTAMP_LTZ(6),
|
||||
PRIMARY KEY (party_id) NOT ENFORCED
|
||||
) WITH (
|
||||
'connector' = 'upsert-kafka',
|
||||
'topic' = 'digital-core.canonical-party.party.outbound',
|
||||
'properties.bootstrap.servers' = 'kafka:29092',
|
||||
'key.format' = 'raw',
|
||||
'value.format' = 'json',
|
||||
'value.json.timestamp-format.standard' = 'ISO-8601'
|
||||
);
|
||||
|
||||
-- Address
|
||||
|
||||
CREATE TABLE address_inbound (
|
||||
address_id STRING,
|
||||
address_type STRING,
|
||||
address_line_1 STRING,
|
||||
address_line_2 STRING,
|
||||
suburb STRING,
|
||||
city STRING,
|
||||
state_or_region STRING,
|
||||
postcode STRING,
|
||||
country STRING
|
||||
) WITH (
|
||||
'connector' = 'kafka',
|
||||
'topic' = 'digital-core.canonical-party.address.inbound',
|
||||
'properties.bootstrap.servers' = 'kafka:29092',
|
||||
'properties.group.id' = 'canonical-party.address.inbound',
|
||||
'scan.startup.mode' = 'group-offsets',
|
||||
'properties.auto.offset.reset' = 'earliest',
|
||||
'format' = 'json',
|
||||
'json.fail-on-missing-field' = 'false',
|
||||
'json.ignore-parse-errors' = 'false',
|
||||
'json.timestamp-format.standard' = 'ISO-8601'
|
||||
);
|
||||
|
||||
CREATE TABLE address_ods (
|
||||
address_id STRING,
|
||||
address_type STRING,
|
||||
address_line_1 STRING,
|
||||
address_line_2 STRING,
|
||||
suburb STRING,
|
||||
city STRING,
|
||||
state_or_region STRING,
|
||||
postcode STRING,
|
||||
country STRING,
|
||||
PRIMARY KEY (address_id) NOT ENFORCED
|
||||
) WITH (
|
||||
'connector' = 'jdbc',
|
||||
'url' = 'jdbc:postgresql://postgres:5432/digital?stringtype=unspecified',
|
||||
'table-name' = 'canonical_party.address',
|
||||
'username' = 'semprini',
|
||||
'password' = 'semprini'
|
||||
);
|
||||
|
||||
CREATE TABLE address_cdc (
|
||||
address_id STRING,
|
||||
address_type STRING,
|
||||
address_line_1 STRING,
|
||||
address_line_2 STRING,
|
||||
suburb STRING,
|
||||
city STRING,
|
||||
state_or_region STRING,
|
||||
postcode STRING,
|
||||
country STRING,
|
||||
updated_at TIMESTAMP_LTZ(6),
|
||||
PRIMARY KEY (address_id) NOT ENFORCED
|
||||
) WITH (
|
||||
'connector' = 'postgres-cdc',
|
||||
'hostname' = 'postgres',
|
||||
'port' = '5432',
|
||||
'username' = 'semprini',
|
||||
'password' = 'semprini',
|
||||
'database-name' = 'digital',
|
||||
'schema-name' = 'canonical_party',
|
||||
'table-name' = 'address',
|
||||
'slot.name' = 'canonical_party_address_flink',
|
||||
'decoding.plugin.name' = 'pgoutput',
|
||||
'scan.incremental.snapshot.enabled' = 'true'
|
||||
);
|
||||
|
||||
CREATE TABLE address_outbound (
|
||||
address_id STRING,
|
||||
address_type STRING,
|
||||
address_line_1 STRING,
|
||||
address_line_2 STRING,
|
||||
suburb STRING,
|
||||
city STRING,
|
||||
state_or_region STRING,
|
||||
postcode STRING,
|
||||
country STRING,
|
||||
updated_at TIMESTAMP_LTZ(6),
|
||||
PRIMARY KEY (address_id) NOT ENFORCED
|
||||
) WITH (
|
||||
'connector' = 'upsert-kafka',
|
||||
'topic' = 'digital-core.canonical-party.address.outbound',
|
||||
'properties.bootstrap.servers' = 'kafka:29092',
|
||||
'key.format' = 'raw',
|
||||
'value.format' = 'json',
|
||||
'value.json.timestamp-format.standard' = 'ISO-8601'
|
||||
);
|
||||
|
||||
-- Person
|
||||
|
||||
CREATE TABLE person_inbound (
|
||||
person_id STRING,
|
||||
date_of_birth DATE,
|
||||
preferred_name STRING,
|
||||
country_of_residence STRING
|
||||
) WITH (
|
||||
'connector' = 'kafka',
|
||||
'topic' = 'digital-core.canonical-party.person.inbound',
|
||||
'properties.bootstrap.servers' = 'kafka:29092',
|
||||
'properties.group.id' = 'canonical-party.person.inbound',
|
||||
'scan.startup.mode' = 'group-offsets',
|
||||
'properties.auto.offset.reset' = 'earliest',
|
||||
'format' = 'json',
|
||||
'json.fail-on-missing-field' = 'false',
|
||||
'json.ignore-parse-errors' = 'false',
|
||||
'json.timestamp-format.standard' = 'ISO-8601'
|
||||
);
|
||||
|
||||
CREATE TABLE person_ods (
|
||||
person_id STRING,
|
||||
date_of_birth DATE,
|
||||
preferred_name STRING,
|
||||
country_of_residence STRING,
|
||||
PRIMARY KEY (person_id) NOT ENFORCED
|
||||
) WITH (
|
||||
'connector' = 'jdbc',
|
||||
'url' = 'jdbc:postgresql://postgres:5432/digital?stringtype=unspecified',
|
||||
'table-name' = 'canonical_party.person',
|
||||
'username' = 'semprini',
|
||||
'password' = 'semprini'
|
||||
);
|
||||
|
||||
CREATE TABLE person_cdc (
|
||||
person_id STRING,
|
||||
date_of_birth DATE,
|
||||
preferred_name STRING,
|
||||
country_of_residence STRING,
|
||||
updated_at TIMESTAMP_LTZ(6),
|
||||
PRIMARY KEY (person_id) NOT ENFORCED
|
||||
) WITH (
|
||||
'connector' = 'postgres-cdc',
|
||||
'hostname' = 'postgres',
|
||||
'port' = '5432',
|
||||
'username' = 'semprini',
|
||||
'password' = 'semprini',
|
||||
'database-name' = 'digital',
|
||||
'schema-name' = 'canonical_party',
|
||||
'table-name' = 'person',
|
||||
'slot.name' = 'canonical_party_person_flink',
|
||||
'decoding.plugin.name' = 'pgoutput',
|
||||
'scan.incremental.snapshot.enabled' = 'true'
|
||||
);
|
||||
|
||||
CREATE TABLE person_outbound (
|
||||
person_id STRING,
|
||||
date_of_birth DATE,
|
||||
preferred_name STRING,
|
||||
country_of_residence STRING,
|
||||
updated_at TIMESTAMP_LTZ(6),
|
||||
PRIMARY KEY (person_id) NOT ENFORCED
|
||||
) WITH (
|
||||
'connector' = 'upsert-kafka',
|
||||
'topic' = 'digital-core.canonical-party.person.outbound',
|
||||
'properties.bootstrap.servers' = 'kafka:29092',
|
||||
'key.format' = 'raw',
|
||||
'value.format' = 'json',
|
||||
'value.json.timestamp-format.standard' = 'ISO-8601'
|
||||
);
|
||||
|
||||
-- Company
|
||||
|
||||
CREATE TABLE company_inbound (
|
||||
company_id STRING,
|
||||
company_registration_number STRING,
|
||||
incorporation_country STRING,
|
||||
incorporation_date DATE,
|
||||
legal_structure STRING,
|
||||
tax_identifier STRING
|
||||
) WITH (
|
||||
'connector' = 'kafka',
|
||||
'topic' = 'digital-core.canonical-party.company.inbound',
|
||||
'properties.bootstrap.servers' = 'kafka:29092',
|
||||
'properties.group.id' = 'canonical-party.company.inbound',
|
||||
'scan.startup.mode' = 'group-offsets',
|
||||
'properties.auto.offset.reset' = 'earliest',
|
||||
'format' = 'json',
|
||||
'json.fail-on-missing-field' = 'false',
|
||||
'json.ignore-parse-errors' = 'false',
|
||||
'json.timestamp-format.standard' = 'ISO-8601'
|
||||
);
|
||||
|
||||
CREATE TABLE company_ods (
|
||||
company_id STRING,
|
||||
company_registration_number STRING,
|
||||
incorporation_country STRING,
|
||||
incorporation_date DATE,
|
||||
legal_structure STRING,
|
||||
tax_identifier STRING,
|
||||
PRIMARY KEY (company_id) NOT ENFORCED
|
||||
) WITH (
|
||||
'connector' = 'jdbc',
|
||||
'url' = 'jdbc:postgresql://postgres:5432/digital?stringtype=unspecified',
|
||||
'table-name' = 'canonical_party.company',
|
||||
'username' = 'semprini',
|
||||
'password' = 'semprini'
|
||||
);
|
||||
|
||||
CREATE TABLE company_cdc (
|
||||
company_id STRING,
|
||||
company_registration_number STRING,
|
||||
incorporation_country STRING,
|
||||
incorporation_date DATE,
|
||||
legal_structure STRING,
|
||||
tax_identifier STRING,
|
||||
updated_at TIMESTAMP_LTZ(6),
|
||||
PRIMARY KEY (company_id) NOT ENFORCED
|
||||
) WITH (
|
||||
'connector' = 'postgres-cdc',
|
||||
'hostname' = 'postgres',
|
||||
'port' = '5432',
|
||||
'username' = 'semprini',
|
||||
'password' = 'semprini',
|
||||
'database-name' = 'digital',
|
||||
'schema-name' = 'canonical_party',
|
||||
'table-name' = 'company',
|
||||
'slot.name' = 'canonical_party_company_flink',
|
||||
'decoding.plugin.name' = 'pgoutput',
|
||||
'scan.incremental.snapshot.enabled' = 'true'
|
||||
);
|
||||
|
||||
CREATE TABLE company_outbound (
|
||||
company_id STRING,
|
||||
company_registration_number STRING,
|
||||
incorporation_country STRING,
|
||||
incorporation_date DATE,
|
||||
legal_structure STRING,
|
||||
tax_identifier STRING,
|
||||
updated_at TIMESTAMP_LTZ(6),
|
||||
PRIMARY KEY (company_id) NOT ENFORCED
|
||||
) WITH (
|
||||
'connector' = 'upsert-kafka',
|
||||
'topic' = 'digital-core.canonical-party.company.outbound',
|
||||
'properties.bootstrap.servers' = 'kafka:29092',
|
||||
'key.format' = 'raw',
|
||||
'value.format' = 'json',
|
||||
'value.json.timestamp-format.standard' = 'ISO-8601'
|
||||
);
|
||||
|
||||
-- Party Role
|
||||
|
||||
CREATE TABLE party_role_inbound (
|
||||
party_role_id STRING,
|
||||
party_role_type STRING,
|
||||
role_status STRING,
|
||||
role_start_date DATE,
|
||||
role_end_date DATE,
|
||||
party_id STRING
|
||||
) WITH (
|
||||
'connector' = 'kafka',
|
||||
'topic' = 'digital-core.canonical-party.party_role.inbound',
|
||||
'properties.bootstrap.servers' = 'kafka:29092',
|
||||
'properties.group.id' = 'canonical-party.party_role.inbound',
|
||||
'scan.startup.mode' = 'group-offsets',
|
||||
'properties.auto.offset.reset' = 'earliest',
|
||||
'format' = 'json',
|
||||
'json.fail-on-missing-field' = 'false',
|
||||
'json.ignore-parse-errors' = 'false',
|
||||
'json.timestamp-format.standard' = 'ISO-8601'
|
||||
);
|
||||
|
||||
CREATE TABLE party_role_ods (
|
||||
party_role_id STRING,
|
||||
party_role_type STRING,
|
||||
role_status STRING,
|
||||
role_start_date DATE,
|
||||
role_end_date DATE,
|
||||
party_id STRING,
|
||||
PRIMARY KEY (party_role_id) NOT ENFORCED
|
||||
) WITH (
|
||||
'connector' = 'jdbc',
|
||||
'url' = 'jdbc:postgresql://postgres:5432/digital?stringtype=unspecified',
|
||||
'table-name' = 'canonical_party.party_role',
|
||||
'username' = 'semprini',
|
||||
'password' = 'semprini'
|
||||
);
|
||||
|
||||
CREATE TABLE party_role_cdc (
|
||||
party_role_id STRING,
|
||||
party_role_type STRING,
|
||||
role_status STRING,
|
||||
role_start_date DATE,
|
||||
role_end_date DATE,
|
||||
party_id STRING,
|
||||
updated_at TIMESTAMP_LTZ(6),
|
||||
PRIMARY KEY (party_role_id) NOT ENFORCED
|
||||
) WITH (
|
||||
'connector' = 'postgres-cdc',
|
||||
'hostname' = 'postgres',
|
||||
'port' = '5432',
|
||||
'username' = 'semprini',
|
||||
'password' = 'semprini',
|
||||
'database-name' = 'digital',
|
||||
'schema-name' = 'canonical_party',
|
||||
'table-name' = 'party_role',
|
||||
'slot.name' = 'canonical_party_party_role_flink',
|
||||
'decoding.plugin.name' = 'pgoutput',
|
||||
'scan.incremental.snapshot.enabled' = 'true'
|
||||
);
|
||||
|
||||
CREATE TABLE party_role_outbound (
|
||||
party_role_id STRING,
|
||||
party_role_type STRING,
|
||||
role_status STRING,
|
||||
role_start_date DATE,
|
||||
role_end_date DATE,
|
||||
party_id STRING,
|
||||
updated_at TIMESTAMP_LTZ(6),
|
||||
PRIMARY KEY (party_role_id) NOT ENFORCED
|
||||
) WITH (
|
||||
'connector' = 'upsert-kafka',
|
||||
'topic' = 'digital-core.canonical-party.party_role.outbound',
|
||||
'properties.bootstrap.servers' = 'kafka:29092',
|
||||
'key.format' = 'raw',
|
||||
'value.format' = 'json',
|
||||
'value.json.timestamp-format.standard' = 'ISO-8601'
|
||||
);
|
||||
|
||||
-- Customer
|
||||
|
||||
CREATE TABLE customer_inbound (
|
||||
customer_id STRING,
|
||||
customer_number STRING,
|
||||
onboarding_date DATE,
|
||||
relationship_start_date DATE
|
||||
) WITH (
|
||||
'connector' = 'kafka',
|
||||
'topic' = 'digital-core.canonical-party.customer.inbound',
|
||||
'properties.bootstrap.servers' = 'kafka:29092',
|
||||
'properties.group.id' = 'canonical-party.customer.inbound',
|
||||
'scan.startup.mode' = 'group-offsets',
|
||||
'properties.auto.offset.reset' = 'earliest',
|
||||
'format' = 'json',
|
||||
'json.fail-on-missing-field' = 'false',
|
||||
'json.ignore-parse-errors' = 'false',
|
||||
'json.timestamp-format.standard' = 'ISO-8601'
|
||||
);
|
||||
|
||||
CREATE TABLE customer_ods (
|
||||
customer_id STRING,
|
||||
customer_number STRING,
|
||||
onboarding_date DATE,
|
||||
relationship_start_date DATE,
|
||||
PRIMARY KEY (customer_id) NOT ENFORCED
|
||||
) WITH (
|
||||
'connector' = 'jdbc',
|
||||
'url' = 'jdbc:postgresql://postgres:5432/digital?stringtype=unspecified',
|
||||
'table-name' = 'canonical_party.customer',
|
||||
'username' = 'semprini',
|
||||
'password' = 'semprini'
|
||||
);
|
||||
|
||||
CREATE TABLE customer_cdc (
|
||||
customer_id STRING,
|
||||
customer_number STRING,
|
||||
onboarding_date DATE,
|
||||
relationship_start_date DATE,
|
||||
updated_at TIMESTAMP_LTZ(6),
|
||||
PRIMARY KEY (customer_id) NOT ENFORCED
|
||||
) WITH (
|
||||
'connector' = 'postgres-cdc',
|
||||
'hostname' = 'postgres',
|
||||
'port' = '5432',
|
||||
'username' = 'semprini',
|
||||
'password' = 'semprini',
|
||||
'database-name' = 'digital',
|
||||
'schema-name' = 'canonical_party',
|
||||
'table-name' = 'customer',
|
||||
'slot.name' = 'canonical_party_customer_flink',
|
||||
'decoding.plugin.name' = 'pgoutput',
|
||||
'scan.incremental.snapshot.enabled' = 'true'
|
||||
);
|
||||
|
||||
CREATE TABLE customer_outbound (
|
||||
customer_id STRING,
|
||||
customer_number STRING,
|
||||
onboarding_date DATE,
|
||||
relationship_start_date DATE,
|
||||
updated_at TIMESTAMP_LTZ(6),
|
||||
PRIMARY KEY (customer_id) NOT ENFORCED
|
||||
) WITH (
|
||||
'connector' = 'upsert-kafka',
|
||||
'topic' = 'digital-core.canonical-party.customer.outbound',
|
||||
'properties.bootstrap.servers' = 'kafka:29092',
|
||||
'key.format' = 'raw',
|
||||
'value.format' = 'json',
|
||||
'value.json.timestamp-format.standard' = 'ISO-8601'
|
||||
);
|
||||
|
||||
-- Contact Address
|
||||
|
||||
CREATE TABLE contact_address_inbound (
|
||||
contact_address_id STRING,
|
||||
address_purpose STRING,
|
||||
is_primary BOOLEAN,
|
||||
verification_status STRING,
|
||||
verification_date DATE,
|
||||
verification_method STRING,
|
||||
valid_from DATE,
|
||||
valid_to DATE,
|
||||
party_id STRING,
|
||||
address_id STRING
|
||||
) WITH (
|
||||
'connector' = 'kafka',
|
||||
'topic' = 'digital-core.canonical-party.contact_address.inbound',
|
||||
'properties.bootstrap.servers' = 'kafka:29092',
|
||||
'properties.group.id' = 'canonical-party.contact_address.inbound',
|
||||
'scan.startup.mode' = 'group-offsets',
|
||||
'properties.auto.offset.reset' = 'earliest',
|
||||
'format' = 'json',
|
||||
'json.fail-on-missing-field' = 'false',
|
||||
'json.ignore-parse-errors' = 'false',
|
||||
'json.timestamp-format.standard' = 'ISO-8601'
|
||||
);
|
||||
|
||||
CREATE TABLE contact_address_ods (
|
||||
contact_address_id STRING,
|
||||
address_purpose STRING,
|
||||
is_primary BOOLEAN,
|
||||
verification_status STRING,
|
||||
verification_date DATE,
|
||||
verification_method STRING,
|
||||
valid_from DATE,
|
||||
valid_to DATE,
|
||||
party_id STRING,
|
||||
address_id STRING,
|
||||
PRIMARY KEY (contact_address_id) NOT ENFORCED
|
||||
) WITH (
|
||||
'connector' = 'jdbc',
|
||||
'url' = 'jdbc:postgresql://postgres:5432/digital?stringtype=unspecified',
|
||||
'table-name' = 'canonical_party.contact_address',
|
||||
'username' = 'semprini',
|
||||
'password' = 'semprini'
|
||||
);
|
||||
|
||||
CREATE TABLE contact_address_cdc (
|
||||
contact_address_id STRING,
|
||||
address_purpose STRING,
|
||||
is_primary BOOLEAN,
|
||||
verification_status STRING,
|
||||
verification_date DATE,
|
||||
verification_method STRING,
|
||||
valid_from DATE,
|
||||
valid_to DATE,
|
||||
party_id STRING,
|
||||
address_id STRING,
|
||||
updated_at TIMESTAMP_LTZ(6),
|
||||
PRIMARY KEY (contact_address_id) NOT ENFORCED
|
||||
) WITH (
|
||||
'connector' = 'postgres-cdc',
|
||||
'hostname' = 'postgres',
|
||||
'port' = '5432',
|
||||
'username' = 'semprini',
|
||||
'password' = 'semprini',
|
||||
'database-name' = 'digital',
|
||||
'schema-name' = 'canonical_party',
|
||||
'table-name' = 'contact_address',
|
||||
'slot.name' = 'canonical_party_contact_address_flink',
|
||||
'decoding.plugin.name' = 'pgoutput',
|
||||
'scan.incremental.snapshot.enabled' = 'true'
|
||||
);
|
||||
|
||||
CREATE TABLE contact_address_outbound (
|
||||
contact_address_id STRING,
|
||||
address_purpose STRING,
|
||||
is_primary BOOLEAN,
|
||||
verification_status STRING,
|
||||
verification_date DATE,
|
||||
verification_method STRING,
|
||||
valid_from DATE,
|
||||
valid_to DATE,
|
||||
party_id STRING,
|
||||
address_id STRING,
|
||||
updated_at TIMESTAMP_LTZ(6),
|
||||
PRIMARY KEY (contact_address_id) NOT ENFORCED
|
||||
) WITH (
|
||||
'connector' = 'upsert-kafka',
|
||||
'topic' = 'digital-core.canonical-party.contact_address.outbound',
|
||||
'properties.bootstrap.servers' = 'kafka:29092',
|
||||
'key.format' = 'raw',
|
||||
'value.format' = 'json',
|
||||
'value.json.timestamp-format.standard' = 'ISO-8601'
|
||||
);
|
||||
|
||||
-- Party Role Uses Contact Addresses
|
||||
|
||||
CREATE TABLE party_role_contact_address_inbound (
|
||||
party_role_contact_address_id STRING,
|
||||
party_role_id STRING,
|
||||
contact_address_id STRING
|
||||
) WITH (
|
||||
'connector' = 'kafka',
|
||||
'topic' = 'digital-core.canonical-party.party_role_contact_address.inbound',
|
||||
'properties.bootstrap.servers' = 'kafka:29092',
|
||||
'properties.group.id' = 'canonical-party.party_role_contact_address.inbound',
|
||||
'scan.startup.mode' = 'group-offsets',
|
||||
'properties.auto.offset.reset' = 'earliest',
|
||||
'format' = 'json',
|
||||
'json.fail-on-missing-field' = 'false',
|
||||
'json.ignore-parse-errors' = 'false',
|
||||
'json.timestamp-format.standard' = 'ISO-8601'
|
||||
);
|
||||
|
||||
CREATE TABLE party_role_contact_address_ods (
|
||||
party_role_contact_address_id STRING,
|
||||
party_role_id STRING,
|
||||
contact_address_id STRING,
|
||||
PRIMARY KEY (party_role_contact_address_id) NOT ENFORCED
|
||||
) WITH (
|
||||
'connector' = 'jdbc',
|
||||
'url' = 'jdbc:postgresql://postgres:5432/digital?stringtype=unspecified',
|
||||
'table-name' = 'canonical_party.party_role_contact_address',
|
||||
'username' = 'semprini',
|
||||
'password' = 'semprini'
|
||||
);
|
||||
|
||||
CREATE TABLE party_role_contact_address_cdc (
|
||||
party_role_contact_address_id STRING,
|
||||
party_role_id STRING,
|
||||
contact_address_id STRING,
|
||||
updated_at TIMESTAMP_LTZ(6),
|
||||
PRIMARY KEY (party_role_contact_address_id) NOT ENFORCED
|
||||
) WITH (
|
||||
'connector' = 'postgres-cdc',
|
||||
'hostname' = 'postgres',
|
||||
'port' = '5432',
|
||||
'username' = 'semprini',
|
||||
'password' = 'semprini',
|
||||
'database-name' = 'digital',
|
||||
'schema-name' = 'canonical_party',
|
||||
'table-name' = 'party_role_contact_address',
|
||||
'slot.name' = 'canonical_party_party_role_contact_address_flink',
|
||||
'decoding.plugin.name' = 'pgoutput',
|
||||
'scan.incremental.snapshot.enabled' = 'true'
|
||||
);
|
||||
|
||||
CREATE TABLE party_role_contact_address_outbound (
|
||||
party_role_contact_address_id STRING,
|
||||
party_role_id STRING,
|
||||
contact_address_id STRING,
|
||||
updated_at TIMESTAMP_LTZ(6),
|
||||
PRIMARY KEY (party_role_contact_address_id) NOT ENFORCED
|
||||
) WITH (
|
||||
'connector' = 'upsert-kafka',
|
||||
'topic' = 'digital-core.canonical-party.party_role_contact_address.outbound',
|
||||
'properties.bootstrap.servers' = 'kafka:29092',
|
||||
'key.format' = 'raw',
|
||||
'value.format' = 'json',
|
||||
'value.json.timestamp-format.standard' = 'ISO-8601'
|
||||
);
|
||||
|
||||
-- Party Related To Party
|
||||
|
||||
CREATE TABLE party_association_inbound (
|
||||
party_association_id STRING,
|
||||
source_party_id STRING,
|
||||
target_party_id STRING,
|
||||
association_type STRING,
|
||||
association_start_date DATE,
|
||||
association_end_date DATE,
|
||||
verified BOOLEAN
|
||||
) WITH (
|
||||
'connector' = 'kafka',
|
||||
'topic' = 'digital-core.canonical-party.party_association.inbound',
|
||||
'properties.bootstrap.servers' = 'kafka:29092',
|
||||
'properties.group.id' = 'canonical-party.party_association.inbound',
|
||||
'scan.startup.mode' = 'group-offsets',
|
||||
'properties.auto.offset.reset' = 'earliest',
|
||||
'format' = 'json',
|
||||
'json.fail-on-missing-field' = 'false',
|
||||
'json.ignore-parse-errors' = 'false',
|
||||
'json.timestamp-format.standard' = 'ISO-8601'
|
||||
);
|
||||
|
||||
CREATE TABLE party_association_ods (
|
||||
party_association_id STRING,
|
||||
source_party_id STRING,
|
||||
target_party_id STRING,
|
||||
association_type STRING,
|
||||
association_start_date DATE,
|
||||
association_end_date DATE,
|
||||
verified BOOLEAN,
|
||||
PRIMARY KEY (party_association_id) NOT ENFORCED
|
||||
) WITH (
|
||||
'connector' = 'jdbc',
|
||||
'url' = 'jdbc:postgresql://postgres:5432/digital?stringtype=unspecified',
|
||||
'table-name' = 'canonical_party.party_association',
|
||||
'username' = 'semprini',
|
||||
'password' = 'semprini'
|
||||
);
|
||||
|
||||
CREATE TABLE party_association_cdc (
|
||||
party_association_id STRING,
|
||||
source_party_id STRING,
|
||||
target_party_id STRING,
|
||||
association_type STRING,
|
||||
association_start_date DATE,
|
||||
association_end_date DATE,
|
||||
verified BOOLEAN,
|
||||
updated_at TIMESTAMP_LTZ(6),
|
||||
PRIMARY KEY (party_association_id) NOT ENFORCED
|
||||
) WITH (
|
||||
'connector' = 'postgres-cdc',
|
||||
'hostname' = 'postgres',
|
||||
'port' = '5432',
|
||||
'username' = 'semprini',
|
||||
'password' = 'semprini',
|
||||
'database-name' = 'digital',
|
||||
'schema-name' = 'canonical_party',
|
||||
'table-name' = 'party_association',
|
||||
'slot.name' = 'canonical_party_party_association_flink',
|
||||
'decoding.plugin.name' = 'pgoutput',
|
||||
'scan.incremental.snapshot.enabled' = 'true'
|
||||
);
|
||||
|
||||
CREATE TABLE party_association_outbound (
|
||||
party_association_id STRING,
|
||||
source_party_id STRING,
|
||||
target_party_id STRING,
|
||||
association_type STRING,
|
||||
association_start_date DATE,
|
||||
association_end_date DATE,
|
||||
verified BOOLEAN,
|
||||
updated_at TIMESTAMP_LTZ(6),
|
||||
PRIMARY KEY (party_association_id) NOT ENFORCED
|
||||
) WITH (
|
||||
'connector' = 'upsert-kafka',
|
||||
'topic' = 'digital-core.canonical-party.party_association.outbound',
|
||||
'properties.bootstrap.servers' = 'kafka:29092',
|
||||
'key.format' = 'raw',
|
||||
'value.format' = 'json',
|
||||
'value.json.timestamp-format.standard' = 'ISO-8601'
|
||||
);
|
||||
|
||||
EXECUTE STATEMENT SET
|
||||
BEGIN
|
||||
INSERT INTO party_ods SELECT * FROM party_inbound;
|
||||
INSERT INTO party_outbound SELECT * FROM party_cdc;
|
||||
INSERT INTO address_ods SELECT * FROM address_inbound;
|
||||
INSERT INTO address_outbound SELECT * FROM address_cdc;
|
||||
INSERT INTO person_ods SELECT * FROM person_inbound;
|
||||
INSERT INTO person_outbound SELECT * FROM person_cdc;
|
||||
INSERT INTO company_ods SELECT * FROM company_inbound;
|
||||
INSERT INTO company_outbound SELECT * FROM company_cdc;
|
||||
INSERT INTO party_role_ods SELECT * FROM party_role_inbound;
|
||||
INSERT INTO party_role_outbound SELECT * FROM party_role_cdc;
|
||||
INSERT INTO customer_ods SELECT * FROM customer_inbound;
|
||||
INSERT INTO customer_outbound SELECT * FROM customer_cdc;
|
||||
INSERT INTO contact_address_ods SELECT * FROM contact_address_inbound;
|
||||
INSERT INTO contact_address_outbound SELECT * FROM contact_address_cdc;
|
||||
INSERT INTO party_role_contact_address_ods SELECT * FROM party_role_contact_address_inbound;
|
||||
INSERT INTO party_role_contact_address_outbound SELECT * FROM party_role_contact_address_cdc;
|
||||
INSERT INTO party_association_ods SELECT * FROM party_association_inbound;
|
||||
INSERT INTO party_association_outbound SELECT * FROM party_association_cdc;
|
||||
END;
|
||||
@@ -0,0 +1,165 @@
|
||||
# Canonical Party: GraphQL surface reflected by pg_graphql from the canonical_party ODS tables.
|
||||
#
|
||||
# This file documents the contract consumers can rely on. It is not loaded anywhere; the live
|
||||
# schema is reflected from the tables and available by introspection:
|
||||
# curl http://localhost:3000/rpc/canonical_party_graphql -H 'Content-Type: application/json' \
|
||||
# --data '{"query":"{ __type(name: \"Party\") { fields { name } } }"}'
|
||||
#
|
||||
# Naming (inflect_names: true): table party_role -> type PartyRole; column role_status -> roleStatus.
|
||||
# Scalars: uuid -> UUID, text -> String, boolean -> Boolean, date -> Date, timestamptz -> Datetime.
|
||||
# A relationship field backed by a NOT NULL foreign key is non-null (Party!).
|
||||
#
|
||||
# Relationship fields are derived from the foreign keys. Two cases need the @graphql directives
|
||||
# set in ods/020_tables.sql: the subtype primary-key-as-foreign-key (Person, Company, Customer),
|
||||
# which otherwise reflects as Person.person / Party.person, and the two foreign keys from
|
||||
# party_association to party, which otherwise produce two identical partyAssociationCollection
|
||||
# fields on Party. The names below are what the directives produce.
|
||||
|
||||
type Party implements Node {
|
||||
nodeId: ID!
|
||||
partyId: UUID!
|
||||
partyType: String! # discriminator: 'Person' | 'Company'
|
||||
legalName: String!
|
||||
alsoKnownAs: String # semicolon-separated; see template/README.md type mapping
|
||||
partyStatus: String # enum:Party Status, enforced by CHECK in the ODS
|
||||
createdAt: Datetime!
|
||||
updatedAt: Datetime!
|
||||
person: Person # subtype row, when partyType = 'Person'
|
||||
company: Company # subtype row, when partyType = 'Company'
|
||||
partyRoleCollection(first: Int, after: Cursor, filter: PartyRoleFilter, orderBy: [PartyRoleOrderBy!]): PartyRoleConnection
|
||||
contactAddressCollection(first: Int, after: Cursor, filter: ContactAddressFilter, orderBy: [ContactAddressOrderBy!]): ContactAddressConnection
|
||||
outgoingAssociationCollection(first: Int, after: Cursor, filter: PartyAssociationFilter, orderBy: [PartyAssociationOrderBy!]): PartyAssociationConnection # this party is source_party_id
|
||||
incomingAssociationCollection(first: Int, after: Cursor, filter: PartyAssociationFilter, orderBy: [PartyAssociationOrderBy!]): PartyAssociationConnection # this party is target_party_id
|
||||
}
|
||||
|
||||
type Address implements Node {
|
||||
nodeId: ID!
|
||||
addressId: UUID!
|
||||
addressType: String # enum:Address Type
|
||||
addressLine1: String
|
||||
addressLine2: String
|
||||
suburb: String
|
||||
city: String
|
||||
stateOrRegion: String
|
||||
postcode: String
|
||||
country: String!
|
||||
createdAt: Datetime!
|
||||
updatedAt: Datetime!
|
||||
contactAddressCollection(first: Int, after: Cursor, filter: ContactAddressFilter, orderBy: [ContactAddressOrderBy!]): ContactAddressConnection
|
||||
}
|
||||
|
||||
type Person implements Node {
|
||||
nodeId: ID!
|
||||
personId: UUID! # equals the extended party's partyId
|
||||
dateOfBirth: Date
|
||||
preferredName: String
|
||||
countryOfResidence: String
|
||||
createdAt: Datetime!
|
||||
updatedAt: Datetime!
|
||||
party: Party! # from person_id (extends Party)
|
||||
}
|
||||
|
||||
type Company implements Node {
|
||||
nodeId: ID!
|
||||
companyId: UUID! # equals the extended party's partyId
|
||||
companyRegistrationNumber: String
|
||||
incorporationCountry: String
|
||||
incorporationDate: Date
|
||||
legalStructure: String # enum:Company Legal Structure
|
||||
taxIdentifier: String
|
||||
createdAt: Datetime!
|
||||
updatedAt: Datetime!
|
||||
party: Party! # from company_id (extends Party)
|
||||
}
|
||||
|
||||
type PartyRole implements Node {
|
||||
nodeId: ID!
|
||||
partyRoleId: UUID!
|
||||
partyRoleType: String! # discriminator: 'Customer'
|
||||
roleStatus: String # enum:Party Role Status
|
||||
roleStartDate: Date
|
||||
roleEndDate: Date
|
||||
partyId: UUID!
|
||||
createdAt: Datetime!
|
||||
updatedAt: Datetime!
|
||||
party: Party! # from party_id (Party Assumes Roles)
|
||||
customer: Customer # subtype row, when partyRoleType = 'Customer'
|
||||
partyRoleContactAddressCollection(first: Int, after: Cursor, filter: PartyRoleContactAddressFilter, orderBy: [PartyRoleContactAddressOrderBy!]): PartyRoleContactAddressConnection
|
||||
}
|
||||
|
||||
type Customer implements Node {
|
||||
nodeId: ID!
|
||||
customerId: UUID! # equals the extended role's partyRoleId
|
||||
customerNumber: String! # unique business key
|
||||
onboardingDate: Date
|
||||
relationshipStartDate: Date
|
||||
createdAt: Datetime!
|
||||
updatedAt: Datetime!
|
||||
partyRole: PartyRole! # from customer_id (extends Party Role)
|
||||
}
|
||||
|
||||
type ContactAddress implements Node {
|
||||
nodeId: ID!
|
||||
contactAddressId: UUID!
|
||||
addressPurpose: String # enum:Address Purpose
|
||||
isPrimary: Boolean
|
||||
verificationStatus: String # enum:Address Verification Status
|
||||
verificationDate: Date
|
||||
verificationMethod: String # enum:Verification Method
|
||||
validFrom: Date
|
||||
validTo: Date
|
||||
partyId: UUID!
|
||||
addressId: UUID!
|
||||
createdAt: Datetime!
|
||||
updatedAt: Datetime!
|
||||
party: Party! # from party_id (Party Has Contact Addresses)
|
||||
address: Address! # from address_id (Contact Address References Address)
|
||||
partyRoleContactAddressCollection(first: Int, after: Cursor, filter: PartyRoleContactAddressFilter, orderBy: [PartyRoleContactAddressOrderBy!]): PartyRoleContactAddressConnection
|
||||
}
|
||||
|
||||
type PartyRoleContactAddress implements Node {
|
||||
nodeId: ID!
|
||||
partyRoleContactAddressId: UUID!
|
||||
partyRoleId: UUID!
|
||||
contactAddressId: UUID!
|
||||
createdAt: Datetime!
|
||||
updatedAt: Datetime!
|
||||
partyRole: PartyRole! # from party_role_id
|
||||
contactAddress: ContactAddress! # from contact_address_id
|
||||
}
|
||||
|
||||
type PartyAssociation implements Node {
|
||||
nodeId: ID!
|
||||
partyAssociationId: UUID!
|
||||
sourcePartyId: UUID!
|
||||
targetPartyId: UUID!
|
||||
associationType: String # enum:Association Type
|
||||
associationStartDate: Date
|
||||
associationEndDate: Date
|
||||
verified: Boolean
|
||||
createdAt: Datetime!
|
||||
updatedAt: Datetime!
|
||||
sourceParty: Party! # from source_party_id
|
||||
targetParty: Party! # from target_party_id
|
||||
}
|
||||
|
||||
extend type Query {
|
||||
partyCollection(first: Int, last: Int, before: Cursor, after: Cursor, filter: PartyFilter, orderBy: [PartyOrderBy!]): PartyConnection
|
||||
addressCollection(first: Int, last: Int, before: Cursor, after: Cursor, filter: AddressFilter, orderBy: [AddressOrderBy!]): AddressConnection
|
||||
personCollection(first: Int, last: Int, before: Cursor, after: Cursor, filter: PersonFilter, orderBy: [PersonOrderBy!]): PersonConnection
|
||||
companyCollection(first: Int, last: Int, before: Cursor, after: Cursor, filter: CompanyFilter, orderBy: [CompanyOrderBy!]): CompanyConnection
|
||||
partyRoleCollection(first: Int, last: Int, before: Cursor, after: Cursor, filter: PartyRoleFilter, orderBy: [PartyRoleOrderBy!]): PartyRoleConnection
|
||||
customerCollection(first: Int, last: Int, before: Cursor, after: Cursor, filter: CustomerFilter, orderBy: [CustomerOrderBy!]): CustomerConnection
|
||||
contactAddressCollection(first: Int, last: Int, before: Cursor, after: Cursor, filter: ContactAddressFilter, orderBy: [ContactAddressOrderBy!]): ContactAddressConnection
|
||||
partyRoleContactAddressCollection(first: Int, last: Int, before: Cursor, after: Cursor, filter: PartyRoleContactAddressFilter, orderBy: [PartyRoleContactAddressOrderBy!]): PartyRoleContactAddressConnection
|
||||
partyAssociationCollection(first: Int, last: Int, before: Cursor, after: Cursor, filter: PartyAssociationFilter, orderBy: [PartyAssociationOrderBy!]): PartyAssociationConnection
|
||||
}
|
||||
|
||||
# Every type has the same three mutations; shown once for Party.
|
||||
extend type Mutation {
|
||||
insertIntoPartyCollection(objects: [PartyInsertInput!]!): PartyInsertResponse
|
||||
updatePartyCollection(set: PartyUpdateInput!, filter: PartyFilter, atMost: Int! = 1): PartyUpdateResponse
|
||||
deleteFromPartyCollection(filter: PartyFilter, atMost: Int! = 1): PartyDeleteResponse
|
||||
# ... insertIntoAddressCollection, updateAddressCollection, deleteFromAddressCollection, and so on
|
||||
# for Person, Company, PartyRole, Customer, ContactAddress, PartyRoleContactAddress, PartyAssociation.
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
# Run by `semprini-blog-dataproducts test` against POST /rpc/canonical_party_graphql.
|
||||
# It must return a `data` object and no `errors`; it does not need to return rows. The
|
||||
# relationship traversals exercise the field names documented in schema.graphql.
|
||||
query CanonicalPartySmoke {
|
||||
partyCollection(first: 5) {
|
||||
edges {
|
||||
node {
|
||||
partyId
|
||||
partyType
|
||||
legalName
|
||||
partyStatus
|
||||
createdAt
|
||||
updatedAt
|
||||
person { preferredName }
|
||||
company { legalStructure }
|
||||
}
|
||||
}
|
||||
}
|
||||
addressCollection(first: 5) {
|
||||
edges {
|
||||
node {
|
||||
addressId
|
||||
addressType
|
||||
city
|
||||
country
|
||||
createdAt
|
||||
updatedAt
|
||||
}
|
||||
}
|
||||
}
|
||||
personCollection(first: 5) {
|
||||
edges {
|
||||
node {
|
||||
personId
|
||||
preferredName
|
||||
createdAt
|
||||
updatedAt
|
||||
party { legalName }
|
||||
}
|
||||
}
|
||||
}
|
||||
companyCollection(first: 5) {
|
||||
edges {
|
||||
node {
|
||||
companyId
|
||||
companyRegistrationNumber
|
||||
createdAt
|
||||
updatedAt
|
||||
party { legalName }
|
||||
}
|
||||
}
|
||||
}
|
||||
partyRoleCollection(first: 5) {
|
||||
edges {
|
||||
node {
|
||||
partyRoleId
|
||||
partyRoleType
|
||||
roleStatus
|
||||
createdAt
|
||||
updatedAt
|
||||
party { legalName }
|
||||
customer { customerNumber }
|
||||
}
|
||||
}
|
||||
}
|
||||
customerCollection(first: 5) {
|
||||
edges {
|
||||
node {
|
||||
customerId
|
||||
customerNumber
|
||||
createdAt
|
||||
updatedAt
|
||||
partyRole { roleStatus }
|
||||
}
|
||||
}
|
||||
}
|
||||
contactAddressCollection(first: 5) {
|
||||
edges {
|
||||
node {
|
||||
contactAddressId
|
||||
addressPurpose
|
||||
isPrimary
|
||||
createdAt
|
||||
updatedAt
|
||||
party { legalName }
|
||||
address { city }
|
||||
}
|
||||
}
|
||||
}
|
||||
partyRoleContactAddressCollection(first: 5) {
|
||||
edges {
|
||||
node {
|
||||
partyRoleContactAddressId
|
||||
createdAt
|
||||
updatedAt
|
||||
partyRole { partyRoleType }
|
||||
contactAddress { addressPurpose }
|
||||
}
|
||||
}
|
||||
}
|
||||
partyAssociationCollection(first: 5) {
|
||||
edges {
|
||||
node {
|
||||
partyAssociationId
|
||||
associationType
|
||||
verified
|
||||
createdAt
|
||||
updatedAt
|
||||
sourceParty { legalName }
|
||||
targetParty { legalName }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
-- Canonical Party: analytical replication into DuckLake (runs on the lakehouse service).
|
||||
--
|
||||
-- pg_duckpipe follows the ODS write-ahead log and maintains a DuckLake copy of each table as
|
||||
-- Parquet in the digital-lake bucket. The platform-level sync group `digital_oltp` already
|
||||
-- points at the ODS (see compose.yml); the product only registers its tables with it.
|
||||
-- Trino reads the result as lake.canonical_party.<table>.
|
||||
|
||||
CREATE SCHEMA IF NOT EXISTS canonical_party;
|
||||
|
||||
SELECT duckpipe.add_table(
|
||||
'canonical_party.party',
|
||||
target_table => 'canonical_party.party',
|
||||
sync_group => 'digital_oltp'
|
||||
);
|
||||
|
||||
SELECT duckpipe.add_table(
|
||||
'canonical_party.address',
|
||||
target_table => 'canonical_party.address',
|
||||
sync_group => 'digital_oltp'
|
||||
);
|
||||
|
||||
SELECT duckpipe.add_table(
|
||||
'canonical_party.person',
|
||||
target_table => 'canonical_party.person',
|
||||
sync_group => 'digital_oltp'
|
||||
);
|
||||
|
||||
SELECT duckpipe.add_table(
|
||||
'canonical_party.company',
|
||||
target_table => 'canonical_party.company',
|
||||
sync_group => 'digital_oltp'
|
||||
);
|
||||
|
||||
SELECT duckpipe.add_table(
|
||||
'canonical_party.party_role',
|
||||
target_table => 'canonical_party.party_role',
|
||||
sync_group => 'digital_oltp'
|
||||
);
|
||||
|
||||
SELECT duckpipe.add_table(
|
||||
'canonical_party.customer',
|
||||
target_table => 'canonical_party.customer',
|
||||
sync_group => 'digital_oltp'
|
||||
);
|
||||
|
||||
SELECT duckpipe.add_table(
|
||||
'canonical_party.contact_address',
|
||||
target_table => 'canonical_party.contact_address',
|
||||
sync_group => 'digital_oltp'
|
||||
);
|
||||
|
||||
SELECT duckpipe.add_table(
|
||||
'canonical_party.party_role_contact_address',
|
||||
target_table => 'canonical_party.party_role_contact_address',
|
||||
sync_group => 'digital_oltp'
|
||||
);
|
||||
|
||||
SELECT duckpipe.add_table(
|
||||
'canonical_party.party_association',
|
||||
target_table => 'canonical_party.party_association',
|
||||
sync_group => 'digital_oltp'
|
||||
);
|
||||
@@ -0,0 +1,109 @@
|
||||
# Canonical Party: Open Data Product Specification v4.0 manifest, the product's entry in the catalogue.
|
||||
# The details, SLA, license and dataHolder blocks follow Agent Architect's odps-alignment
|
||||
# mapping from the MD-DDL declaration (data_products/canonical.md). The dataAccess block is
|
||||
# platform-specific and lists the product's four interfaces. Fields with TODO need business
|
||||
# input outside the model.
|
||||
schema: https://opendataproducts.org/v4.0/schema/odps.yaml
|
||||
version: 4.0
|
||||
product:
|
||||
details:
|
||||
en:
|
||||
name: "Canonical Party"
|
||||
productID: "digital-core.canonical-party"
|
||||
description: "The governed canonical representation of Party, Party Role, and the identity entities around them, published for downstream domains and cross-domain integration. It publishes the canonical model as modelled, with no reshaping and no aggregation, so that consumers inherit the domain's definitions rather than inventing their own."
|
||||
visibility: organisation
|
||||
status: production # declaration status: Active
|
||||
type: dataset # declaration class: domain-aligned
|
||||
productVersion: "1.0.0"
|
||||
categories:
|
||||
- "Digital Core"
|
||||
tags:
|
||||
- "Party"
|
||||
- "Person"
|
||||
- "Company"
|
||||
- "Party Role"
|
||||
- "Customer"
|
||||
- "Contact Address"
|
||||
- "Address"
|
||||
outputFileFormats:
|
||||
- GraphQL
|
||||
- JSON
|
||||
- SQL
|
||||
|
||||
SLA:
|
||||
declarative:
|
||||
default:
|
||||
name:
|
||||
en: Default SLA
|
||||
description:
|
||||
en: "Service levels for Canonical Party"
|
||||
dimensions:
|
||||
- dimension: uptime
|
||||
displaytitle:
|
||||
en: Availability
|
||||
objective: 99.95 # sla.availability "99.95%"
|
||||
unit: percent
|
||||
- dimension: updateFrequency
|
||||
displaytitle:
|
||||
en: Data Freshness
|
||||
objective: 1 # refresh: real-time (declared sla.freshness "< 0.5 seconds")
|
||||
unit: minutes
|
||||
support:
|
||||
email: "data.architecture@example.com"
|
||||
|
||||
dataAccess:
|
||||
default:
|
||||
name:
|
||||
en: CRUD API
|
||||
description:
|
||||
en: "GraphQL reflected from the operational store by pg_graphql. Reads, inserts, updates and deletes on every entity."
|
||||
outputPorttype: API
|
||||
format: GraphQL
|
||||
authenticationMethod: none # lab stack only
|
||||
accessURL: "http://localhost:3000/rpc/canonical_party_graphql"
|
||||
publish:
|
||||
name:
|
||||
en: Publish Input
|
||||
description:
|
||||
en: "Kafka topics that accept canonical records, one per entity. JSON payloads conform to the schema registered for the topic."
|
||||
outputPorttype: API
|
||||
format: JSON
|
||||
authenticationMethod: none
|
||||
accessURL: "kafka://localhost:9092/digital-core.canonical-party.<table>.inbound"
|
||||
specsURL: "http://localhost:8082/apis/registry/v3/groups/digital-core.canonical-party/artifacts"
|
||||
subscribe:
|
||||
name:
|
||||
en: Subscribe Output
|
||||
description:
|
||||
en: "Compacted Kafka topics carrying every change to each entity, keyed by identifier. Deletes are tombstones."
|
||||
outputPorttype: API
|
||||
format: JSON
|
||||
authenticationMethod: none
|
||||
accessURL: "kafka://localhost:9092/digital-core.canonical-party.<table>.outbound"
|
||||
specsURL: "http://localhost:8082/apis/registry/v3/groups/digital-core.canonical-party/artifacts"
|
||||
sql:
|
||||
name:
|
||||
en: Analytic SQL
|
||||
description:
|
||||
en: "Trino over DuckLake, continuously replicated from the operational store by pg_duckpipe."
|
||||
outputPorttype: SQL
|
||||
format: SQL
|
||||
authenticationMethod: none
|
||||
accessURL: "jdbc:trino://localhost:8083/lake/canonical_party"
|
||||
|
||||
license:
|
||||
en:
|
||||
scope:
|
||||
definition: "TODO: purpose statement for the licence"
|
||||
restrictions: "Confidential. Contains personal data (Party, Person and Contact Address are pii: true). Domain-aligned: published unmasked as the canonical source; masking belongs to consumer-aligned products. Consumers: Cross-domain Integration."
|
||||
permanent: false
|
||||
exclusive: false
|
||||
termination:
|
||||
terminationConditions: "7 years post relationship end"
|
||||
governance:
|
||||
confidentiality: "Confidential, inherited from the Digital Core domain governance (classification: Confidential, pii: true)"
|
||||
|
||||
dataHolder:
|
||||
en:
|
||||
legalName: "TODO: organisation legal name"
|
||||
email: "data.architecture@example.com"
|
||||
@@ -0,0 +1,19 @@
|
||||
-- Canonical Party: operational data store schema (runs on the postgres service).
|
||||
--
|
||||
-- The product owns one PostgreSQL schema. pg_graphql reflects only the schemas on the
|
||||
-- search_path, and the product's RPC endpoint (030_api.sql) sets the search_path to this
|
||||
-- schema, so this is what scopes the GraphQL API to the product.
|
||||
|
||||
CREATE SCHEMA canonical_party;
|
||||
|
||||
COMMENT ON SCHEMA canonical_party IS E'@graphql({"inflect_names": true, "introspection": true, "max_rows": 100})';
|
||||
|
||||
-- Maintains updated_at on every row change. Used by all product tables (020_tables.sql).
|
||||
-- updated_at is the freshness signal carried on the outbound topics and into the lake.
|
||||
CREATE FUNCTION canonical_party.set_updated_at() RETURNS trigger
|
||||
LANGUAGE plpgsql AS $$
|
||||
BEGIN
|
||||
NEW.updated_at := now();
|
||||
RETURN NEW;
|
||||
END
|
||||
$$;
|
||||
@@ -0,0 +1,268 @@
|
||||
-- Canonical Party: operational tables (PostgreSQL 17).
|
||||
--
|
||||
-- Source: data_products/canonical.md and the seven entity files it lists. Order: parents
|
||||
-- (party, address), subtypes (person, company), party_role and its subtype customer, then
|
||||
-- contact_address and the two association tables. product.yaml, 040_seed.sql,
|
||||
-- lakehouse/010_replication.sql and trino/smoke.sql use the same order.
|
||||
--
|
||||
-- Inheritance is class-table: a subtype's primary key is its foreign key to the parent, and
|
||||
-- the abstract parents carry a <table>_type discriminator naming the subtype. Enum attributes
|
||||
-- are text with a CHECK listing the enum values from enums.md verbatim. Foreign keys are
|
||||
-- named <table>_<column>_fkey; the @graphql directives on some of them fix the relationship
|
||||
-- field names pg_graphql would otherwise derive from the column name (see graphql/schema.graphql).
|
||||
--
|
||||
-- The ODS is current state. The bitemporal tracking declared on Party and Party Role is served
|
||||
-- by the compacted outbound topics and the lake, not by history tables here.
|
||||
|
||||
-- Party (entities/party.md; existence: independent, mutability: slowly_changing, temporal: bitemporal).
|
||||
-- Abstract parent of Person and Company.
|
||||
CREATE TABLE canonical_party.party (
|
||||
party_id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
party_type text NOT NULL CHECK (party_type IN ('Person', 'Company')), -- subtypes in this product
|
||||
legal_name text NOT NULL, -- constraint: Legal Name Required
|
||||
also_known_as text,
|
||||
party_status text CHECK (party_status IN ('Prospect', 'Active', 'Suspended', 'Inactive', 'Closed')), -- enum:Party Status
|
||||
created_at timestamptz NOT NULL DEFAULT now(),
|
||||
updated_at timestamptz NOT NULL DEFAULT now()
|
||||
);
|
||||
|
||||
COMMENT ON TABLE canonical_party.party IS 'A Party is any individual or organisation the business has, or may have, a relationship with. It is the foundational abstract concept of the domain: it carries only what is true of every party, whoever they are. Abstract: every row is extended by a person or company row named by party_type. Current state only; the declared bitemporal history is served by the outbound topic and the lake.';
|
||||
COMMENT ON COLUMN canonical_party.party.party_id IS 'Globally unique identifier for this party across all systems. Immutable once assigned.';
|
||||
COMMENT ON COLUMN canonical_party.party.party_type IS 'Discriminator naming the subtype (Person or Company) that extends this party.';
|
||||
COMMENT ON COLUMN canonical_party.party.legal_name IS 'The party''s full name as it appears on official documentation. For an individual this is the full given and family name; for an organisation it is the registered name.';
|
||||
COMMENT ON COLUMN canonical_party.party.also_known_as IS 'Alternative names: trading names, former names, maiden names, or the name a person actually goes by. People and businesses accumulate names, and searching only the legal one finds nobody. Several names are held in the one field, separated by semicolons; PostgreSQL array columns are not used because pg_duckpipe cannot replicate them to the lake.';
|
||||
COMMENT ON COLUMN canonical_party.party.party_status IS 'Where the party sits in its lifecycle with the business. Controls whether new relationships may be established.';
|
||||
|
||||
CREATE TRIGGER party_set_updated_at
|
||||
BEFORE UPDATE ON canonical_party.party
|
||||
FOR EACH ROW EXECUTE FUNCTION canonical_party.set_updated_at();
|
||||
|
||||
-- Address (entities/address.md; existence: independent, mutability: reference).
|
||||
CREATE TABLE canonical_party.address (
|
||||
address_id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
address_type text CHECK (address_type IN ('Street Address', 'PO Box', 'Registered Office', 'Overseas Address')), -- enum:Address Type
|
||||
address_line_1 text,
|
||||
address_line_2 text,
|
||||
suburb text,
|
||||
city text,
|
||||
state_or_region text,
|
||||
postcode text,
|
||||
country text NOT NULL, -- constraint: Country Required
|
||||
created_at timestamptz NOT NULL DEFAULT now(),
|
||||
updated_at timestamptz NOT NULL DEFAULT now(),
|
||||
CONSTRAINT street_address_requires_address_line_1 -- constraint of the same name in the model
|
||||
CHECK (address_type <> 'Street Address' OR address_line_1 IS NOT NULL)
|
||||
);
|
||||
|
||||
COMMENT ON TABLE canonical_party.address IS 'An Address is the canonical record of a location. It holds the structured components of the place itself and nothing else: no party, no purpose, no verification. Those belong on Contact Address. Reference data: one Address record serves every party at that location.';
|
||||
COMMENT ON COLUMN canonical_party.address.address_id IS 'Globally unique identifier for this location. Immutable once assigned. Many parties may reference the same identifier through their Contact Address records.';
|
||||
COMMENT ON COLUMN canonical_party.address.address_type IS 'The structural type of the address. Determines which components apply: a PO Box has no street, and an overseas address may have no state or region.';
|
||||
COMMENT ON COLUMN canonical_party.address.address_line_1 IS 'The primary street line, typically number and street name. For a PO Box, the box number.';
|
||||
COMMENT ON COLUMN canonical_party.address.address_line_2 IS 'Secondary line for a unit, level, suite or building name.';
|
||||
COMMENT ON COLUMN canonical_party.address.suburb IS 'The suburb or locality. Kept distinct from City because in Australia and New Zealand they are genuinely different things and merging them breaks delivery.';
|
||||
COMMENT ON COLUMN canonical_party.address.city IS 'The city or town.';
|
||||
COMMENT ON COLUMN canonical_party.address.state_or_region IS 'The state, territory, province or region, or the local equivalent.';
|
||||
COMMENT ON COLUMN canonical_party.address.postcode IS 'The postal code. Held as a string to preserve leading zeros and to support formats that are not numeric.';
|
||||
COMMENT ON COLUMN canonical_party.address.country IS 'ISO 3166-1 alpha-2 country code. Mandatory for every address type.';
|
||||
|
||||
CREATE TRIGGER address_set_updated_at
|
||||
BEFORE UPDATE ON canonical_party.address
|
||||
FOR EACH ROW EXECUTE FUNCTION canonical_party.set_updated_at();
|
||||
|
||||
-- Person (entities/person.md; extends Party). The primary key is the foreign key to party.
|
||||
CREATE TABLE canonical_party.person (
|
||||
person_id uuid PRIMARY KEY CONSTRAINT person_person_id_fkey REFERENCES canonical_party.party (party_id) ON DELETE CASCADE,
|
||||
date_of_birth date,
|
||||
preferred_name text,
|
||||
country_of_residence text,
|
||||
created_at timestamptz NOT NULL DEFAULT now(),
|
||||
updated_at timestamptz NOT NULL DEFAULT now(),
|
||||
CONSTRAINT date_of_birth_not_in_future -- constraint of the same name in the model
|
||||
CHECK (date_of_birth IS NULL OR date_of_birth <= current_date)
|
||||
);
|
||||
|
||||
COMMENT ON TABLE canonical_party.person IS 'A Person is a human being. Person specialises Party, inheriting everything that is true of any party and adding what only applies to people. Rows share their identifier with the party row they extend (party_type = ''Person'').';
|
||||
COMMENT ON COLUMN canonical_party.person.person_id IS 'The Party Identifier of the party this person extends.';
|
||||
COMMENT ON COLUMN canonical_party.person.date_of_birth IS 'The individual''s date of birth. Used to confirm identity, to check age eligibility for age-restricted products, and to avoid confusing two people with the same name.';
|
||||
COMMENT ON COLUMN canonical_party.person.preferred_name IS 'What the person actually wants to be called, when that differs from their legal name. Used for greetings and correspondence.';
|
||||
COMMENT ON COLUMN canonical_party.person.country_of_residence IS 'ISO 3166-1 alpha-2 code for the country the individual currently lives in. Drives tax treatment, applicable consumer law, currency defaults and delivery options.';
|
||||
|
||||
-- pg_graphql would name both sides of this relationship after the column (Person.person, Party.person).
|
||||
COMMENT ON CONSTRAINT person_person_id_fkey ON canonical_party.person IS E'@graphql({"foreign_name": "party", "local_name": "person"})';
|
||||
|
||||
CREATE TRIGGER person_set_updated_at
|
||||
BEFORE UPDATE ON canonical_party.person
|
||||
FOR EACH ROW EXECUTE FUNCTION canonical_party.set_updated_at();
|
||||
|
||||
-- Company (entities/company.md; extends Party). The primary key is the foreign key to party.
|
||||
CREATE TABLE canonical_party.company (
|
||||
company_id uuid PRIMARY KEY CONSTRAINT company_company_id_fkey REFERENCES canonical_party.party (party_id) ON DELETE CASCADE,
|
||||
company_registration_number text, -- constraint: Registration Number Required For Active Company (lifecycle_stage: Onboarding, see table comment)
|
||||
incorporation_country text,
|
||||
incorporation_date date,
|
||||
legal_structure text CHECK (legal_structure IN ('Private Company', 'Public Company', 'Partnership', 'Sole Trader', 'Trust', 'Cooperative', 'Government Entity', 'Non-Profit')), -- enum:Company Legal Structure
|
||||
tax_identifier text,
|
||||
created_at timestamptz NOT NULL DEFAULT now(),
|
||||
updated_at timestamptz NOT NULL DEFAULT now()
|
||||
);
|
||||
|
||||
COMMENT ON TABLE canonical_party.company IS 'A Company is an organisation with legal standing: a company, partnership, trust, cooperative, charity or public body. It specialises Party and carries the registration and structure attributes that only apply to organisations. Rows share their identifier with the party row they extend (party_type = ''Company''). Not enforced here: Registration Number Required For Active Company, an onboarding-stage rule that a registration number must be recorded before the relationship is activated.';
|
||||
COMMENT ON COLUMN canonical_party.company.company_id IS 'The Party Identifier of the party this company extends.';
|
||||
COMMENT ON COLUMN canonical_party.company.company_registration_number IS 'The registration identifier issued by the relevant companies registry, such as an ACN in Australia, an NZBN in New Zealand or a Companies House number in the UK. The most reliable way to tell two similarly named organisations apart.';
|
||||
COMMENT ON COLUMN canonical_party.company.incorporation_country IS 'ISO 3166-1 alpha-2 code for the country the organisation is incorporated in. Determines which registry the registration number belongs to, and which country''s company law applies.';
|
||||
COMMENT ON COLUMN canonical_party.company.incorporation_date IS 'Date the organisation was formally incorporated or registered.';
|
||||
COMMENT ON COLUMN canonical_party.company.legal_structure IS 'The legal form the organisation takes. Determines signing authority, liability and the evidence required to establish who controls it.';
|
||||
COMMENT ON COLUMN canonical_party.company.tax_identifier IS 'Tax registration number issued by the relevant revenue authority, such as an ABN, VAT number or EIN. Needed to invoice the organisation correctly.';
|
||||
|
||||
COMMENT ON CONSTRAINT company_company_id_fkey ON canonical_party.company IS E'@graphql({"foreign_name": "party", "local_name": "company"})';
|
||||
|
||||
CREATE TRIGGER company_set_updated_at
|
||||
BEFORE UPDATE ON canonical_party.company
|
||||
FOR EACH ROW EXECUTE FUNCTION canonical_party.set_updated_at();
|
||||
|
||||
-- Party Role (entities/party_role.md; existence: independent, mutability: slowly_changing, temporal: bitemporal).
|
||||
-- Abstract parent of Customer. Owned side of Party Assumes Roles.
|
||||
CREATE TABLE canonical_party.party_role (
|
||||
party_role_id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
party_role_type text NOT NULL CHECK (party_role_type IN ('Customer')), -- subtypes in this product
|
||||
role_status text CHECK (role_status IN ('Pending', 'Active', 'Suspended', 'Closed')), -- enum:Party Role Status
|
||||
role_start_date date,
|
||||
role_end_date date,
|
||||
party_id uuid NOT NULL CONSTRAINT party_role_party_id_fkey REFERENCES canonical_party.party (party_id), -- Party Assumes Roles (one-to-many, owned side)
|
||||
created_at timestamptz NOT NULL DEFAULT now(),
|
||||
updated_at timestamptz NOT NULL DEFAULT now(),
|
||||
CONSTRAINT role_end_after_start -- constraint of the same name in the model
|
||||
CHECK (role_end_date IS NULL OR role_end_date > role_start_date),
|
||||
CONSTRAINT closed_role_requires_end_date -- constraint of the same name in the model
|
||||
CHECK (role_status <> 'Closed' OR role_end_date IS NOT NULL)
|
||||
);
|
||||
|
||||
COMMENT ON TABLE canonical_party.party_role IS 'A Party Role is the capacity in which a Party acts. It separates who someone is from what they are doing. Abstract: every row is extended by a subtype row named by party_role_type; of the domain''s six role subtypes only Customer is in this product. Outside this product''s boundary and not materialised: Party Role Governed By Agreement (Agreement is not in the product) and the period-granularity Party Role At Point In Time snapshot. Current state only; the declared bitemporal history is served by the outbound topic and the lake.';
|
||||
COMMENT ON COLUMN canonical_party.party_role.party_role_id IS 'Globally unique identifier for this role instance. Distinct from the Party Identifier: one party holding two roles has two Role Identifiers.';
|
||||
COMMENT ON COLUMN canonical_party.party_role.party_role_type IS 'Discriminator naming the subtype (Customer) that extends this role.';
|
||||
COMMENT ON COLUMN canonical_party.party_role.role_status IS 'The current lifecycle status of this role. Controls whether the role confers its business permissions.';
|
||||
COMMENT ON COLUMN canonical_party.party_role.role_start_date IS 'The date this role became effective.';
|
||||
COMMENT ON COLUMN canonical_party.party_role.role_end_date IS 'The date this role ceased to be effective. Null means the role is still open. Roles are closed rather than deleted, so that history stays intact.';
|
||||
COMMENT ON COLUMN canonical_party.party_role.party_id IS 'The party that assumes this role.';
|
||||
|
||||
CREATE INDEX party_role_party_id_idx ON canonical_party.party_role (party_id);
|
||||
|
||||
CREATE TRIGGER party_role_set_updated_at
|
||||
BEFORE UPDATE ON canonical_party.party_role
|
||||
FOR EACH ROW EXECUTE FUNCTION canonical_party.set_updated_at();
|
||||
|
||||
-- Customer (entities/customer.md; extends Party Role). The primary key is the foreign key to party_role.
|
||||
CREATE TABLE canonical_party.customer (
|
||||
customer_id uuid PRIMARY KEY CONSTRAINT customer_customer_id_fkey REFERENCES canonical_party.party_role (party_role_id) ON DELETE CASCADE,
|
||||
customer_number text NOT NULL UNIQUE, -- identifier: primary on the subtype, kept as a business key
|
||||
onboarding_date date,
|
||||
relationship_start_date date,
|
||||
created_at timestamptz NOT NULL DEFAULT now(),
|
||||
updated_at timestamptz NOT NULL DEFAULT now()
|
||||
);
|
||||
|
||||
COMMENT ON TABLE canonical_party.customer IS 'A Customer is a Party Role representing an active or prospective commercial relationship: someone who buys, subscribes, or holds an account with the business. Rows share their identifier with the party_role row they extend (party_role_type = ''Customer''). Outside this product''s boundary and not materialised: Customer Holds Account (Account) and Customer Has Preferences (Customer Preferences).';
|
||||
COMMENT ON COLUMN canonical_party.customer.customer_id IS 'The Role Identifier of the party role this customer extends.';
|
||||
COMMENT ON COLUMN canonical_party.customer.customer_number IS 'The customer identifier quoted in correspondence and used by service and support staff. Unlike the Party Identifier, this one is meant to be readable aloud over the phone.';
|
||||
COMMENT ON COLUMN canonical_party.customer.onboarding_date IS 'Date the customer onboarding process was completed.';
|
||||
COMMENT ON COLUMN canonical_party.customer.relationship_start_date IS 'Date the customer relationship became effective. May precede the onboarding date where a relationship was migrated in from another system or acquired with another business.';
|
||||
|
||||
COMMENT ON CONSTRAINT customer_customer_id_fkey ON canonical_party.customer IS E'@graphql({"foreign_name": "partyRole", "local_name": "customer"})';
|
||||
|
||||
CREATE TRIGGER customer_set_updated_at
|
||||
BEFORE UPDATE ON canonical_party.customer
|
||||
FOR EACH ROW EXECUTE FUNCTION canonical_party.set_updated_at();
|
||||
|
||||
-- Contact Address (entities/contact_address.md; existence: associative, mutability: slowly_changing, temporal: valid_time).
|
||||
-- Owned side of Party Has Contact Addresses; references exactly one Address.
|
||||
CREATE TABLE canonical_party.contact_address (
|
||||
contact_address_id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
address_purpose text CHECK (address_purpose IN ('Home', 'Mailing', 'Business', 'Registered Office', 'Billing', 'Delivery')), -- enum:Address Purpose
|
||||
is_primary boolean DEFAULT false,
|
||||
verification_status text CHECK (verification_status IN ('Unverified', 'Verified', 'Failed', 'Expired')), -- enum:Address Verification Status
|
||||
verification_date date,
|
||||
verification_method text CHECK (verification_method IN ('Documentary', 'Electronic', 'In Person', 'Self Declared')), -- enum:Verification Method
|
||||
valid_from date,
|
||||
valid_to date,
|
||||
party_id uuid NOT NULL CONSTRAINT contact_address_party_id_fkey REFERENCES canonical_party.party (party_id), -- Party Has Contact Addresses (one-to-many, owned side)
|
||||
address_id uuid NOT NULL CONSTRAINT contact_address_address_id_fkey REFERENCES canonical_party.address (address_id), -- Contact Address References Address (many-to-one)
|
||||
created_at timestamptz NOT NULL DEFAULT now(),
|
||||
updated_at timestamptz NOT NULL DEFAULT now(),
|
||||
CONSTRAINT valid_to_after_valid_from -- constraint of the same name in the model
|
||||
CHECK (valid_to IS NULL OR valid_to > valid_from),
|
||||
CONSTRAINT verification_date_required_when_verified -- constraint of the same name in the model
|
||||
CHECK (verification_status <> 'Verified' OR verification_date IS NOT NULL)
|
||||
);
|
||||
|
||||
COMMENT ON TABLE canonical_party.contact_address IS 'A Contact Address is the link between a Party and an Address: what the address is used for, whether it has been confirmed, and the period it was in use. It is not the address itself; the location lives in the Address entity and is shared. Not enforced here: One Primary Per Purpose, a cross-row rule that a party may have at most one primary Contact Address per purpose at any point in time.';
|
||||
COMMENT ON COLUMN canonical_party.contact_address.contact_address_id IS 'Globally unique identifier for this party-to-address association.';
|
||||
COMMENT ON COLUMN canonical_party.contact_address.address_purpose IS 'What the party uses this address for. A party can hold several addresses at once for different purposes: home, billing and delivery are frequently different places.';
|
||||
COMMENT ON COLUMN canonical_party.contact_address.is_primary IS 'Whether this is the party''s main address for the given purpose. At most one address may be primary per purpose at any point in time.';
|
||||
COMMENT ON COLUMN canonical_party.contact_address.verification_status IS 'Whether this address has been confirmed as real and current. Unverified addresses are usable but should not be relied on for anything expensive, such as a physical delivery.';
|
||||
COMMENT ON COLUMN canonical_party.contact_address.verification_date IS 'When the address was last confirmed. Verification ages: an address confirmed five years ago is weaker evidence than one confirmed last month.';
|
||||
COMMENT ON COLUMN canonical_party.contact_address.verification_method IS 'How the address was confirmed. Recorded because the methods are not equally strong, and knowing which was used determines how much weight to put on the result.';
|
||||
COMMENT ON COLUMN canonical_party.contact_address.valid_from IS 'The date the party started using this address for the stated purpose.';
|
||||
COMMENT ON COLUMN canonical_party.contact_address.valid_to IS 'The date the party stopped using it. Null means still in use. Closed associations are kept rather than deleted, so historical lookups stay accurate.';
|
||||
COMMENT ON COLUMN canonical_party.contact_address.party_id IS 'The party that owns this contact address.';
|
||||
COMMENT ON COLUMN canonical_party.contact_address.address_id IS 'The canonical Address record this contact address points at.';
|
||||
|
||||
CREATE INDEX contact_address_party_id_idx ON canonical_party.contact_address (party_id);
|
||||
CREATE INDEX contact_address_address_id_idx ON canonical_party.contact_address (address_id);
|
||||
|
||||
CREATE TRIGGER contact_address_set_updated_at
|
||||
BEFORE UPDATE ON canonical_party.contact_address
|
||||
FOR EACH ROW EXECUTE FUNCTION canonical_party.set_updated_at();
|
||||
|
||||
-- Party Role Uses Contact Addresses (entities/party_role.md; many-to-many, no relationship attributes).
|
||||
CREATE TABLE canonical_party.party_role_contact_address (
|
||||
party_role_contact_address_id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
party_role_id uuid NOT NULL CONSTRAINT party_role_contact_address_party_role_id_fkey REFERENCES canonical_party.party_role (party_role_id) ON DELETE CASCADE,
|
||||
contact_address_id uuid NOT NULL CONSTRAINT party_role_contact_address_contact_address_id_fkey REFERENCES canonical_party.contact_address (contact_address_id) ON DELETE CASCADE,
|
||||
created_at timestamptz NOT NULL DEFAULT now(),
|
||||
updated_at timestamptz NOT NULL DEFAULT now()
|
||||
);
|
||||
|
||||
COMMENT ON TABLE canonical_party.party_role_contact_address IS 'A Party Role may use one or more Contact Addresses owned by the underlying Party. The Party owns its addresses; a role picks which of them applies in its context.';
|
||||
COMMENT ON COLUMN canonical_party.party_role_contact_address.party_role_id IS 'The role that uses the contact address.';
|
||||
COMMENT ON COLUMN canonical_party.party_role_contact_address.contact_address_id IS 'The contact address the role uses. Owned by the same party as the role.';
|
||||
|
||||
CREATE INDEX party_role_contact_address_source_idx ON canonical_party.party_role_contact_address (party_role_id);
|
||||
CREATE INDEX party_role_contact_address_target_idx ON canonical_party.party_role_contact_address (contact_address_id);
|
||||
|
||||
CREATE TRIGGER party_role_contact_address_set_updated_at
|
||||
BEFORE UPDATE ON canonical_party.party_role_contact_address
|
||||
FOR EACH ROW EXECUTE FUNCTION canonical_party.set_updated_at();
|
||||
|
||||
-- Party Related To Party (entities/party.md; self-referential many-to-many with four relationship attributes).
|
||||
-- Relationship attributes are typed by name: Association Type is an enum, the two dates are date, Verified is boolean.
|
||||
CREATE TABLE canonical_party.party_association (
|
||||
party_association_id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
source_party_id uuid NOT NULL CONSTRAINT party_association_source_party_id_fkey REFERENCES canonical_party.party (party_id) ON DELETE CASCADE,
|
||||
target_party_id uuid NOT NULL CONSTRAINT party_association_target_party_id_fkey REFERENCES canonical_party.party (party_id) ON DELETE CASCADE,
|
||||
association_type text CHECK (association_type IN ('Parent Organisation', 'Subsidiary', 'Owner', 'Director', 'Authorised Signatory', 'Employer', 'Employee', 'Partner', 'Family Member', 'Household Member')), -- enum:Association Type
|
||||
association_start_date date,
|
||||
association_end_date date,
|
||||
verified boolean,
|
||||
created_at timestamptz NOT NULL DEFAULT now(),
|
||||
updated_at timestamptz NOT NULL DEFAULT now()
|
||||
);
|
||||
|
||||
COMMENT ON TABLE canonical_party.party_association IS 'A Party may be related to other Parties through ownership, control, employment, household or family ties. A relationship instance is directional and named: source_party_id is the Association Type of target_party_id ("Director of", "Parent Organisation of"). The same pair of parties may hold several associations of different types at once.';
|
||||
COMMENT ON COLUMN canonical_party.party_association.source_party_id IS 'The party the association is stated from.';
|
||||
COMMENT ON COLUMN canonical_party.party_association.target_party_id IS 'The party the association points at.';
|
||||
COMMENT ON COLUMN canonical_party.party_association.association_type IS 'The nature of the relationship between the two parties, read from source to target.';
|
||||
COMMENT ON COLUMN canonical_party.party_association.association_start_date IS 'The date the association began.';
|
||||
COMMENT ON COLUMN canonical_party.party_association.association_end_date IS 'The date the association ended. Null means still current.';
|
||||
COMMENT ON COLUMN canonical_party.party_association.verified IS 'Whether the association has been confirmed against acceptable evidence.';
|
||||
|
||||
-- Two foreign keys to the same table give distinct sourceParty / targetParty fields here but two
|
||||
-- identical partyAssociationCollection fields on Party; the local_name on each keeps them apart.
|
||||
COMMENT ON CONSTRAINT party_association_source_party_id_fkey ON canonical_party.party_association IS E'@graphql({"foreign_name": "sourceParty", "local_name": "outgoingAssociationCollection"})';
|
||||
COMMENT ON CONSTRAINT party_association_target_party_id_fkey ON canonical_party.party_association IS E'@graphql({"foreign_name": "targetParty", "local_name": "incomingAssociationCollection"})';
|
||||
|
||||
CREATE INDEX party_association_source_idx ON canonical_party.party_association (source_party_id);
|
||||
CREATE INDEX party_association_target_idx ON canonical_party.party_association (target_party_id);
|
||||
|
||||
CREATE TRIGGER party_association_set_updated_at
|
||||
BEFORE UPDATE ON canonical_party.party_association
|
||||
FOR EACH ROW EXECUTE FUNCTION canonical_party.set_updated_at();
|
||||
@@ -0,0 +1,31 @@
|
||||
-- Canonical Party: API surface (runs on the postgres service).
|
||||
--
|
||||
-- PostgREST connects as `authenticator` and switches to the platform's `anon` role, so the
|
||||
-- GraphQL API sees exactly what `anon` is granted here. The lab has no authentication; a real
|
||||
-- deployment would grant per-consumer roles and add row-level security policies.
|
||||
|
||||
GRANT USAGE ON SCHEMA canonical_party TO anon;
|
||||
GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA canonical_party TO anon;
|
||||
GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA canonical_party TO anon;
|
||||
ALTER DEFAULT PRIVILEGES IN SCHEMA canonical_party GRANT SELECT, INSERT, UPDATE, DELETE ON TABLES TO anon;
|
||||
|
||||
-- The product's GraphQL endpoint: POST /rpc/canonical_party_graphql through PostgREST.
|
||||
-- pg_graphql reflects the schemas on the search_path, so the SET clause is what scopes this
|
||||
-- endpoint to the product's tables and keeps other products out of its schema.
|
||||
CREATE FUNCTION api.canonical_party_graphql(
|
||||
query text,
|
||||
variables jsonb DEFAULT '{}'::jsonb,
|
||||
"operationName" text DEFAULT NULL,
|
||||
extensions jsonb DEFAULT NULL
|
||||
) RETURNS jsonb
|
||||
LANGUAGE sql
|
||||
SECURITY INVOKER
|
||||
SET search_path = canonical_party, graphql
|
||||
AS $$
|
||||
SELECT graphql.resolve(query, variables, "operationName", extensions);
|
||||
$$;
|
||||
|
||||
GRANT EXECUTE ON FUNCTION api.canonical_party_graphql(text, jsonb, text, jsonb) TO anon;
|
||||
|
||||
-- PostgREST caches the API definition; ask it to pick up the new endpoint.
|
||||
NOTIFY pgrst, 'reload schema';
|
||||
@@ -0,0 +1,68 @@
|
||||
-- Canonical Party: sample rows (runs on the postgres service).
|
||||
--
|
||||
-- Fixed uuids so child rows can reference their parents and so the same rows can be published
|
||||
-- to the inbound topics or queried through GraphQL in examples. The second uuid group numbers
|
||||
-- the table (0001 party, 0002 address, 0003 party_role, 0004 contact_address, 0005
|
||||
-- party_role_contact_address, 0006 party_association); subtype rows reuse their parent's id.
|
||||
|
||||
INSERT INTO canonical_party.party
|
||||
(party_id, party_type, legal_name, also_known_as, party_status)
|
||||
VALUES
|
||||
('7d1e5a2c-0001-4a7b-9c11-000000000001', 'Person', 'Alice Margaret Ng', 'Alice Ng', 'Active'),
|
||||
('7d1e5a2c-0001-4a7b-9c11-000000000002', 'Person', 'Rangi Parata', NULL, 'Active'),
|
||||
('7d1e5a2c-0001-4a7b-9c11-000000000003', 'Company', 'Kowhai Trading Limited', 'Kowhai Trading; KTL', 'Active'),
|
||||
('7d1e5a2c-0001-4a7b-9c11-000000000004', 'Company', 'Harbour Logistics Pty Ltd', 'Harbour Logistics', 'Prospect');
|
||||
|
||||
INSERT INTO canonical_party.address
|
||||
(address_id, address_type, address_line_1, address_line_2, suburb, city, state_or_region, postcode, country)
|
||||
VALUES
|
||||
('7d1e5a2c-0002-4a7b-9c11-000000000001', 'Street Address', '1 Queen Street', NULL, 'Auckland Central', 'Auckland', 'Auckland', '1010', 'NZ'),
|
||||
('7d1e5a2c-0002-4a7b-9c11-000000000002', 'PO Box', 'PO Box 123', NULL, NULL, 'Wellington', 'Wellington', '6140', 'NZ'),
|
||||
('7d1e5a2c-0002-4a7b-9c11-000000000003', 'Registered Office', 'Level 5, 100 Collins Street', NULL, NULL, 'Melbourne', 'VIC', '3000', 'AU');
|
||||
|
||||
INSERT INTO canonical_party.person
|
||||
(person_id, date_of_birth, preferred_name, country_of_residence)
|
||||
VALUES
|
||||
('7d1e5a2c-0001-4a7b-9c11-000000000001', '1985-03-14', 'Alice', 'NZ'),
|
||||
('7d1e5a2c-0001-4a7b-9c11-000000000002', '1990-11-02', 'Rangi', 'NZ');
|
||||
|
||||
INSERT INTO canonical_party.company
|
||||
(company_id, company_registration_number, incorporation_country, incorporation_date, legal_structure, tax_identifier)
|
||||
VALUES
|
||||
('7d1e5a2c-0001-4a7b-9c11-000000000003', '9429041234567', 'NZ', '2012-07-01', 'Private Company', '123-456-789'),
|
||||
('7d1e5a2c-0001-4a7b-9c11-000000000004', '123456789', 'AU', '2005-03-15', 'Private Company', '51 824 753 556');
|
||||
|
||||
INSERT INTO canonical_party.party_role
|
||||
(party_role_id, party_role_type, role_status, role_start_date, role_end_date, party_id)
|
||||
VALUES
|
||||
('7d1e5a2c-0003-4a7b-9c11-000000000001', 'Customer', 'Active', '2020-01-15', NULL, '7d1e5a2c-0001-4a7b-9c11-000000000001'),
|
||||
('7d1e5a2c-0003-4a7b-9c11-000000000002', 'Customer', 'Active', '2018-06-01', NULL, '7d1e5a2c-0001-4a7b-9c11-000000000003'),
|
||||
('7d1e5a2c-0003-4a7b-9c11-000000000003', 'Customer', 'Closed', '2021-03-01', '2024-08-31', '7d1e5a2c-0001-4a7b-9c11-000000000002');
|
||||
|
||||
INSERT INTO canonical_party.customer
|
||||
(customer_id, customer_number, onboarding_date, relationship_start_date)
|
||||
VALUES
|
||||
('7d1e5a2c-0003-4a7b-9c11-000000000001', 'CUST-000001', '2020-01-15', '2020-01-15'),
|
||||
('7d1e5a2c-0003-4a7b-9c11-000000000002', 'CUST-000002', '2018-06-01', '2015-06-01'),
|
||||
('7d1e5a2c-0003-4a7b-9c11-000000000003', 'CUST-000003', '2021-03-01', '2021-03-01');
|
||||
|
||||
INSERT INTO canonical_party.contact_address
|
||||
(contact_address_id, address_purpose, is_primary, verification_status, verification_date, verification_method, valid_from, valid_to, party_id, address_id)
|
||||
VALUES
|
||||
('7d1e5a2c-0004-4a7b-9c11-000000000001', 'Home', true, 'Verified', '2024-02-10', 'Documentary', '2019-12-01', NULL, '7d1e5a2c-0001-4a7b-9c11-000000000001', '7d1e5a2c-0002-4a7b-9c11-000000000001'),
|
||||
('7d1e5a2c-0004-4a7b-9c11-000000000002', 'Mailing', true, 'Unverified', NULL, NULL, '2022-01-01', NULL, '7d1e5a2c-0001-4a7b-9c11-000000000001', '7d1e5a2c-0002-4a7b-9c11-000000000002'),
|
||||
('7d1e5a2c-0004-4a7b-9c11-000000000003', 'Registered Office', true, 'Verified', '2023-05-20', 'Electronic', '2012-07-01', NULL, '7d1e5a2c-0001-4a7b-9c11-000000000003', '7d1e5a2c-0002-4a7b-9c11-000000000003');
|
||||
|
||||
INSERT INTO canonical_party.party_role_contact_address
|
||||
(party_role_contact_address_id, party_role_id, contact_address_id)
|
||||
VALUES
|
||||
('7d1e5a2c-0005-4a7b-9c11-000000000001', '7d1e5a2c-0003-4a7b-9c11-000000000001', '7d1e5a2c-0004-4a7b-9c11-000000000001'),
|
||||
('7d1e5a2c-0005-4a7b-9c11-000000000002', '7d1e5a2c-0003-4a7b-9c11-000000000001', '7d1e5a2c-0004-4a7b-9c11-000000000002'),
|
||||
('7d1e5a2c-0005-4a7b-9c11-000000000003', '7d1e5a2c-0003-4a7b-9c11-000000000002', '7d1e5a2c-0004-4a7b-9c11-000000000003');
|
||||
|
||||
INSERT INTO canonical_party.party_association
|
||||
(party_association_id, source_party_id, target_party_id, association_type, association_start_date, association_end_date, verified)
|
||||
VALUES
|
||||
('7d1e5a2c-0006-4a7b-9c11-000000000001', '7d1e5a2c-0001-4a7b-9c11-000000000001', '7d1e5a2c-0001-4a7b-9c11-000000000003', 'Director', '2015-01-01', NULL, true),
|
||||
('7d1e5a2c-0006-4a7b-9c11-000000000002', '7d1e5a2c-0001-4a7b-9c11-000000000001', '7d1e5a2c-0001-4a7b-9c11-000000000003', 'Authorised Signatory', '2015-01-01', NULL, true),
|
||||
('7d1e5a2c-0006-4a7b-9c11-000000000003', '7d1e5a2c-0001-4a7b-9c11-000000000002', '7d1e5a2c-0001-4a7b-9c11-000000000001', 'Partner', '2016-06-01', NULL, false);
|
||||
@@ -0,0 +1,183 @@
|
||||
# Canonical Party: data product manifest.
|
||||
# Read by `uv run semprini-blog-dataproducts deploy|test|undeploy products/canonical-party`.
|
||||
# Names every platform resource the product owns. Derived from the MD-DDL declaration
|
||||
# named in `declaration`; see template/README.md for the naming rules.
|
||||
|
||||
product:
|
||||
name: "Canonical Party"
|
||||
slug: "canonical-party"
|
||||
domain: "digital-core"
|
||||
declaration: "data_products/canonical.md"
|
||||
version: "1.0.0"
|
||||
owner: "data.architecture@example.com"
|
||||
|
||||
ods:
|
||||
schema: "canonical_party"
|
||||
tables:
|
||||
# Parents, subtypes, children with foreign keys, association tables; the same order as
|
||||
# ods/020_tables.sql, ods/040_seed.sql, lakehouse/010_replication.sql and trino/smoke.sql.
|
||||
- name: "party"
|
||||
entity: "Party"
|
||||
key: "party_id"
|
||||
- name: "address"
|
||||
entity: "Address"
|
||||
key: "address_id"
|
||||
- name: "person"
|
||||
entity: "Person"
|
||||
key: "person_id"
|
||||
- name: "company"
|
||||
entity: "Company"
|
||||
key: "company_id"
|
||||
- name: "party_role"
|
||||
entity: "Party Role"
|
||||
key: "party_role_id"
|
||||
- name: "customer"
|
||||
entity: "Customer"
|
||||
key: "customer_id"
|
||||
- name: "contact_address"
|
||||
entity: "Contact Address"
|
||||
key: "contact_address_id"
|
||||
- name: "party_role_contact_address"
|
||||
entity: "Party Role Uses Contact Addresses"
|
||||
key: "party_role_contact_address_id"
|
||||
- name: "party_association"
|
||||
entity: "Party Related To Party"
|
||||
key: "party_association_id"
|
||||
|
||||
graphql:
|
||||
endpoint: "/rpc/canonical_party_graphql"
|
||||
smoke: graphql/smoke.graphql
|
||||
|
||||
events:
|
||||
registry_group: "digital-core.canonical-party"
|
||||
compatibility: BACKWARD
|
||||
topics:
|
||||
- name: "digital-core.canonical-party.party.inbound"
|
||||
role: publish-input
|
||||
table: "party"
|
||||
schema: events/schemas/party.schema.json
|
||||
partitions: 3
|
||||
cleanup_policy: delete
|
||||
retention_ms: 604800000
|
||||
- name: "digital-core.canonical-party.party.outbound"
|
||||
role: subscribe-output
|
||||
table: "party"
|
||||
schema: events/schemas/party.schema.json
|
||||
partitions: 3
|
||||
cleanup_policy: compact
|
||||
- name: "digital-core.canonical-party.address.inbound"
|
||||
role: publish-input
|
||||
table: "address"
|
||||
schema: events/schemas/address.schema.json
|
||||
partitions: 3
|
||||
cleanup_policy: delete
|
||||
retention_ms: 604800000
|
||||
- name: "digital-core.canonical-party.address.outbound"
|
||||
role: subscribe-output
|
||||
table: "address"
|
||||
schema: events/schemas/address.schema.json
|
||||
partitions: 3
|
||||
cleanup_policy: compact
|
||||
- name: "digital-core.canonical-party.person.inbound"
|
||||
role: publish-input
|
||||
table: "person"
|
||||
schema: events/schemas/person.schema.json
|
||||
partitions: 3
|
||||
cleanup_policy: delete
|
||||
retention_ms: 604800000
|
||||
- name: "digital-core.canonical-party.person.outbound"
|
||||
role: subscribe-output
|
||||
table: "person"
|
||||
schema: events/schemas/person.schema.json
|
||||
partitions: 3
|
||||
cleanup_policy: compact
|
||||
- name: "digital-core.canonical-party.company.inbound"
|
||||
role: publish-input
|
||||
table: "company"
|
||||
schema: events/schemas/company.schema.json
|
||||
partitions: 3
|
||||
cleanup_policy: delete
|
||||
retention_ms: 604800000
|
||||
- name: "digital-core.canonical-party.company.outbound"
|
||||
role: subscribe-output
|
||||
table: "company"
|
||||
schema: events/schemas/company.schema.json
|
||||
partitions: 3
|
||||
cleanup_policy: compact
|
||||
- name: "digital-core.canonical-party.party_role.inbound"
|
||||
role: publish-input
|
||||
table: "party_role"
|
||||
schema: events/schemas/party_role.schema.json
|
||||
partitions: 3
|
||||
cleanup_policy: delete
|
||||
retention_ms: 604800000
|
||||
- name: "digital-core.canonical-party.party_role.outbound"
|
||||
role: subscribe-output
|
||||
table: "party_role"
|
||||
schema: events/schemas/party_role.schema.json
|
||||
partitions: 3
|
||||
cleanup_policy: compact
|
||||
- name: "digital-core.canonical-party.customer.inbound"
|
||||
role: publish-input
|
||||
table: "customer"
|
||||
schema: events/schemas/customer.schema.json
|
||||
partitions: 3
|
||||
cleanup_policy: delete
|
||||
retention_ms: 604800000
|
||||
- name: "digital-core.canonical-party.customer.outbound"
|
||||
role: subscribe-output
|
||||
table: "customer"
|
||||
schema: events/schemas/customer.schema.json
|
||||
partitions: 3
|
||||
cleanup_policy: compact
|
||||
- name: "digital-core.canonical-party.contact_address.inbound"
|
||||
role: publish-input
|
||||
table: "contact_address"
|
||||
schema: events/schemas/contact_address.schema.json
|
||||
partitions: 3
|
||||
cleanup_policy: delete
|
||||
retention_ms: 604800000
|
||||
- name: "digital-core.canonical-party.contact_address.outbound"
|
||||
role: subscribe-output
|
||||
table: "contact_address"
|
||||
schema: events/schemas/contact_address.schema.json
|
||||
partitions: 3
|
||||
cleanup_policy: compact
|
||||
- name: "digital-core.canonical-party.party_role_contact_address.inbound"
|
||||
role: publish-input
|
||||
table: "party_role_contact_address"
|
||||
schema: events/schemas/party_role_contact_address.schema.json
|
||||
partitions: 3
|
||||
cleanup_policy: delete
|
||||
retention_ms: 604800000
|
||||
- name: "digital-core.canonical-party.party_role_contact_address.outbound"
|
||||
role: subscribe-output
|
||||
table: "party_role_contact_address"
|
||||
schema: events/schemas/party_role_contact_address.schema.json
|
||||
partitions: 3
|
||||
cleanup_policy: compact
|
||||
- name: "digital-core.canonical-party.party_association.inbound"
|
||||
role: publish-input
|
||||
table: "party_association"
|
||||
schema: events/schemas/party_association.schema.json
|
||||
partitions: 3
|
||||
cleanup_policy: delete
|
||||
retention_ms: 604800000
|
||||
- name: "digital-core.canonical-party.party_association.outbound"
|
||||
role: subscribe-output
|
||||
table: "party_association"
|
||||
schema: events/schemas/party_association.schema.json
|
||||
partitions: 3
|
||||
cleanup_policy: compact
|
||||
|
||||
flink:
|
||||
job: flink/job.sql
|
||||
name: "canonical-party"
|
||||
|
||||
lakehouse:
|
||||
sync_group: digital_oltp
|
||||
schema: "canonical_party"
|
||||
|
||||
trino:
|
||||
catalog: lake
|
||||
smoke: trino/smoke.sql
|
||||
@@ -0,0 +1,12 @@
|
||||
-- Canonical Party: analytic SQL smoke test, run by `semprini-blog-dataproducts test`
|
||||
-- through Trino's `lake` catalog. One statement per table and each must succeed.
|
||||
|
||||
SELECT 'party' AS table_name, count(*) AS row_count FROM lake.canonical_party.party;
|
||||
SELECT 'address' AS table_name, count(*) AS row_count FROM lake.canonical_party.address;
|
||||
SELECT 'person' AS table_name, count(*) AS row_count FROM lake.canonical_party.person;
|
||||
SELECT 'company' AS table_name, count(*) AS row_count FROM lake.canonical_party.company;
|
||||
SELECT 'party_role' AS table_name, count(*) AS row_count FROM lake.canonical_party.party_role;
|
||||
SELECT 'customer' AS table_name, count(*) AS row_count FROM lake.canonical_party.customer;
|
||||
SELECT 'contact_address' AS table_name, count(*) AS row_count FROM lake.canonical_party.contact_address;
|
||||
SELECT 'party_role_contact_address' AS table_name, count(*) AS row_count FROM lake.canonical_party.party_role_contact_address;
|
||||
SELECT 'party_association' AS table_name, count(*) AS row_count FROM lake.canonical_party.party_association;
|
||||
Reference in new issue
Block a user