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,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();
|
||||
Reference in new issue
Block a user