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: Remove the copies

A claim is against a policy, and a policy is held by a customer. The customer's name and email belong to the customer, not to each claim.

  • Claims hold no copy of the customer: the customer is reached through the policy.
  • Each claim still reaches its customer through its policy.
  • The customer's name and email live on customers.
Back to chapter 6
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 claims

A claim against a policy, with the customer's details copied in when it was reported.

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 customers (
    customer_id integer GENERATED BY DEFAULT AS IDENTITY NOT NULL,
    name text NOT NULL,
    email text,
    CONSTRAINT pk_customers PRIMARY KEY (customer_id)
);

COMMENT ON TABLE customers IS 'A customer, recorded once.';

COMMENT ON COLUMN customers.customer_id IS 'Surrogate key';

CREATE TABLE policies (
    policy_id integer GENERATED BY DEFAULT AS IDENTITY NOT NULL,
    customer_id integer NOT NULL,
    policy_number text NOT NULL,
    CONSTRAINT pk_policies PRIMARY KEY (policy_id),
    CONSTRAINT fk_policies_customer_id FOREIGN KEY (customer_id) REFERENCES customers (customer_id)
);

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

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

COMMENT ON COLUMN policies.customer_id IS 'the customers row';

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

COMMENT ON TABLE claims IS 'A claim against a policy, with the customer''s details copied in when it was reported.';

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

COMMENT ON COLUMN claims.policy_id IS 'the policies 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.