Tools

Model studio

Draw a data model at three levels, change it, and generate the tables for PostgreSQL, Spark SQL with Delta Lake and T-SQL; then run the PostgreSQL version on the estate's data, in your browser.

Exercise: One party, many roles

One person can be a policyholder, a claimant and a driver at once. Store each person's name and birth date once, in a party table of its own, and let policyholders and claimants refer to it.

  • A person's full name and birth date are stored in exactly one table.
  • That table is a party of its own, not one of the roles.
  • Policyholders and claimants each refer to the party.
  • Policies still refer to their policyholder, and claims to their policy and claimant.
Back to chapter 5
Estate
Level
Physical dialect

Logical: every attribute with its type and keys (PK, FK), independent of any database; a question mark marks an optional attribute.

Edit policyholders

A person who holds a policy, with their own copy of the person's details.

New attribute
Type
Attribute to drop
References
New entity (table name)
Information domain

The generated tables

Checked in CI on a real PostgreSQL 18.3, and run below in PGlite, the same release.

CREATE TABLE policyholders (
    policyholder_id integer GENERATED BY DEFAULT AS IDENTITY NOT NULL,
    full_name text NOT NULL,
    birth_date date NOT NULL,
    email text,
    CONSTRAINT pk_policyholders PRIMARY KEY (policyholder_id)
);

COMMENT ON TABLE policyholders IS 'A person who holds a policy, with their own copy of the person''s details.';

COMMENT ON COLUMN policyholders.policyholder_id IS 'Surrogate key';

CREATE TABLE claimants (
    claimant_id integer GENERATED BY DEFAULT AS IDENTITY NOT NULL,
    full_name text NOT NULL,
    birth_date date NOT NULL,
    phone text,
    CONSTRAINT pk_claimants PRIMARY KEY (claimant_id)
);

COMMENT ON TABLE claimants IS 'A person who makes a claim, with their own copy of the person''s details.';

COMMENT ON COLUMN claimants.claimant_id IS 'Surrogate key';

CREATE TABLE policies (
    policy_id integer GENERATED BY DEFAULT AS IDENTITY NOT NULL,
    policy_number text NOT NULL,
    policyholder_id integer NOT NULL,
    start_date date NOT NULL,
    CONSTRAINT pk_policies PRIMARY KEY (policy_id),
    CONSTRAINT fk_policies_policyholder_id FOREIGN KEY (policyholder_id) REFERENCES policyholders (policyholder_id)
);

COMMENT ON TABLE policies IS 'A policy, held by one policyholder.';

COMMENT ON COLUMN policies.policy_id IS 'Surrogate key';

COMMENT ON COLUMN policies.policyholder_id IS 'the policyholders row';

CREATE TABLE claims (
    claim_id integer GENERATED BY DEFAULT AS IDENTITY NOT NULL,
    policy_id integer NOT NULL,
    claimant_id integer NOT NULL,
    loss_date date NOT NULL,
    CONSTRAINT pk_claims PRIMARY KEY (claim_id),
    CONSTRAINT fk_claims_policy_id FOREIGN KEY (policy_id) REFERENCES policies (policy_id),
    CONSTRAINT fk_claims_claimant_id FOREIGN KEY (claimant_id) REFERENCES claimants (claimant_id)
);

COMMENT ON TABLE claims IS 'A claim against a policy, made by a claimant.';

COMMENT ON COLUMN claims.claim_id IS 'Surrogate key';

COMMENT ON COLUMN claims.policy_id IS 'the policies row';

COMMENT ON COLUMN claims.claimant_id IS 'the claimants row';

Run it on the data

PostgreSQL starts in this browser when you press Run.

Rows loaded, against the seed
TablePGliteSeedSame

Try this

0 of 4 done

Switch the level between conceptual, logical and physical with the claims entity selected.

Look for: The boxes stay; what they say changes: names and relationships, then keys and attributes, then each database's own types.

Add a fraud_score attribute (decimal, optional) to claims, then look at the PostgreSQL, Spark SQL and T-SQL tabs.

Look for: One change in the logical model appears in all three dialects, each with its own type.

Press Run in the browser.

Look for: PostgreSQL starts in your browser, creates every table and loads Harbour Mutual's rows; a new column is there and empty.

Switch the estate to Kestrel and compare its claims table with Harbour Mutual's.

Look for: Kestrel keeps reserves in cents and does not enforce the link from a claim to its policy: the merger's first conflicts.

An unhandled error has occurred. Reload 🗙

Reconnecting…

Your connection to the Cloud Data Architecture Lab dropped, probably a Wi-Fi blip. Hold on while it reconnects.

The connection could not be restored. The page will reload in a few seconds.