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 model for both companies

Harbour Mutual's customers, policies and claims become the combined model; Kestrel's klanten, polissen and schades are shown beside them as they are today, and stay as they are. Make the combined tables hold Kestrel's rows too: every row records the company it came from (source_company) and its key there (source_key); a person can be a customer of both companies, so a customer's source records go in a table of their own that refers to the customer; a policy can say it is in its grace period (grace_until, a date, or in_grace_period, yes or no); and the reserve stays in euros with cents.

  • A customer's source records are in a table of their own that refers to the customer, and the customers table holds no source key.
  • Every policy and every claim says where it came from.
  • A policy can say it is in its grace period.
  • The combined claims keep the reserve in euros with cents, and nothing in whole cents.
  • Every claim still refers to its policy.
Back to chapter 39
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 customers

Harbour Mutual's customers: the combined party table.

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,
    full_name text NOT NULL,
    birth_date date NOT NULL,
    email text,
    CONSTRAINT pk_customers PRIMARY KEY (customer_id)
);

COMMENT ON TABLE customers IS 'Harbour Mutual''s customers: the combined party table.';

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

CREATE TABLE policies (
    policy_id integer GENERATED BY DEFAULT AS IDENTITY NOT NULL,
    policy_number text NOT NULL,
    customer_id integer NOT NULL,
    product_line char(3) NOT NULL,
    status char(3) NOT NULL,
    end_date date 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 'Harbour Mutual''s policies: the combined policy table.';

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,
    cause text NOT NULL,
    reserve numeric(12,2) NOT NULL,
    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 'Harbour Mutual''s claims: the combined claim table.';

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

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

CREATE TABLE klanten (
    klant_id integer GENERATED BY DEFAULT AS IDENTITY NOT NULL,
    naam text NOT NULL,
    geboortedatum date NOT NULL,
    CONSTRAINT pk_klanten PRIMARY KEY (klant_id)
);

COMMENT ON TABLE klanten IS 'Kestrel''s customers, as Kestrel keeps them.';

COMMENT ON COLUMN klanten.klant_id IS 'Surrogate key';

CREATE TABLE polissen (
    polis_id integer GENERATED BY DEFAULT AS IDENTITY NOT NULL,
    polis_nr text NOT NULL,
    klant_id integer NOT NULL,
    product_code char(3) NOT NULL,
    status char(3) NOT NULL,
    CONSTRAINT pk_polissen PRIMARY KEY (polis_id),
    CONSTRAINT fk_polissen_klant_id FOREIGN KEY (klant_id) REFERENCES klanten (klant_id)
);

COMMENT ON TABLE polissen IS 'Kestrel''s policies, as Kestrel keeps them.';

COMMENT ON COLUMN polissen.polis_id IS 'Surrogate key';

COMMENT ON COLUMN polissen.klant_id IS 'the klanten row';

CREATE TABLE schades (
    schade_id integer GENERATED BY DEFAULT AS IDENTITY NOT NULL,
    polis_id integer NOT NULL,
    oorzaak_code text NOT NULL,
    reserve_cent integer NOT NULL,
    CONSTRAINT pk_schades PRIMARY KEY (schade_id)
);

COMMENT ON TABLE schades IS 'Kestrel''s claims: the policy is a number the package does not check.';

COMMENT ON COLUMN schades.schade_id IS 'Surrogate key';

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.