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.

Estate
Level
Physical dialect

Physical: the same model as one database's columns and types; switch the dialect to compare.

Edit claims

A loss reported against one policy.

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 regions (
    region_id integer GENERATED BY DEFAULT AS IDENTITY NOT NULL,
    country char(2) NOT NULL,
    name text NOT NULL,
    CONSTRAINT pk_regions PRIMARY KEY (region_id)
);

COMMENT ON TABLE regions IS 'A region of one of the three countries Harbour Mutual sells in.';

COMMENT ON COLUMN regions.region_id IS 'Surrogate key';

COMMENT ON COLUMN regions.country IS 'NL, PL or DE';

CREATE TABLE products (
    product_id integer GENERATED BY DEFAULT AS IDENTITY NOT NULL,
    line text NOT NULL,
    name text NOT NULL,
    launched_on date NOT NULL,
    CONSTRAINT pk_products PRIMARY KEY (product_id)
);

COMMENT ON TABLE products IS 'Something Harbour Mutual sells, in one line of business.';

COMMENT ON COLUMN products.product_id IS 'Surrogate key';

COMMENT ON COLUMN products.line IS 'motor, home or travel: the line of business';

CREATE TABLE coverage_types (
    coverage_id integer GENERATED BY DEFAULT AS IDENTITY NOT NULL,
    product_id integer NOT NULL,
    name text NOT NULL,
    default_limit numeric(12,2) NOT NULL,
    CONSTRAINT pk_coverage_types PRIMARY KEY (coverage_id),
    CONSTRAINT fk_coverage_types_product_id FOREIGN KEY (product_id) REFERENCES products (product_id)
);

COMMENT ON TABLE coverage_types IS 'What a product can cover, with its default limit.';

COMMENT ON COLUMN coverage_types.coverage_id IS 'Surrogate key';

COMMENT ON COLUMN coverage_types.name IS 'what is covered: third party, own damage, theft, flood';

COMMENT ON COLUMN coverage_types.default_limit IS 'the most the insurer pays under this coverage, unless the policy says otherwise';

CREATE TABLE brokers (
    broker_id integer GENERATED BY DEFAULT AS IDENTITY NOT NULL,
    region_id integer NOT NULL,
    name text NOT NULL,
    commission_rate numeric(4,3) NOT NULL,
    CONSTRAINT pk_brokers PRIMARY KEY (broker_id),
    CONSTRAINT fk_brokers_region_id FOREIGN KEY (region_id) REFERENCES regions (region_id)
);

COMMENT ON TABLE brokers IS 'An intermediary who sells Harbour Mutual''s policies for a commission.';

COMMENT ON COLUMN brokers.broker_id IS 'Surrogate key';

COMMENT ON COLUMN brokers.commission_rate IS 'share of the premium paid to the broker, e.g. 0.125';

CREATE TABLE customers (
    customer_id integer GENERATED BY DEFAULT AS IDENTITY NOT NULL,
    region_id integer NOT NULL,
    name text NOT NULL,
    birth_date date NOT NULL,
    customer_since date NOT NULL,
    email text,
    CONSTRAINT pk_customers PRIMARY KEY (customer_id),
    CONSTRAINT fk_customers_region_id FOREIGN KEY (region_id) REFERENCES regions (region_id)
);

COMMENT ON TABLE customers IS 'A person who holds, or has held, a Harbour Mutual policy.';

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

COMMENT ON COLUMN customers.email IS 'contact address; not every customer gave one';

CREATE TABLE policies (
    policy_id integer GENERATED BY DEFAULT AS IDENTITY NOT NULL,
    policy_number text NOT NULL,
    customer_id integer NOT NULL,
    product_id integer NOT NULL,
    broker_id integer,
    start_date date NOT NULL,
    end_date date NOT NULL,
    status text NOT NULL,
    annual_premium numeric(10,2) NOT NULL,
    CONSTRAINT pk_policies PRIMARY KEY (policy_id),
    CONSTRAINT fk_policies_customer_id FOREIGN KEY (customer_id) REFERENCES customers (customer_id),
    CONSTRAINT fk_policies_product_id FOREIGN KEY (product_id) REFERENCES products (product_id),
    CONSTRAINT fk_policies_broker_id FOREIGN KEY (broker_id) REFERENCES brokers (broker_id)
);

COMMENT ON TABLE policies IS 'One annual term of cover for one customer and one product.';

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

COMMENT ON COLUMN policies.policy_number IS 'one per annual term, e.g. HM-MC-004211-2024';

COMMENT ON COLUMN policies.broker_id IS 'null: sold directly';

COMMENT ON COLUMN policies.end_date IS 'the last day of cover';

COMMENT ON COLUMN policies.status IS 'active, expired, lapsed (premium not paid) or cancelled';

CREATE TABLE policy_coverages (
    policy_id integer NOT NULL,
    coverage_id integer NOT NULL,
    limit_amount numeric(12,2) NOT NULL,
    deductible numeric(10,2) NOT NULL,
    CONSTRAINT pk_policy_coverages PRIMARY KEY (policy_id, coverage_id),
    CONSTRAINT fk_policy_coverages_policy_id FOREIGN KEY (policy_id) REFERENCES policies (policy_id),
    CONSTRAINT fk_policy_coverages_coverage_id FOREIGN KEY (coverage_id) REFERENCES coverage_types (coverage_id)
);

COMMENT ON TABLE policy_coverages IS 'A coverage a policy includes, with its own limit and deductible.';

COMMENT ON COLUMN policy_coverages.deductible IS 'the part of each claim the customer pays (the excess)';

CREATE TABLE premium_transactions (
    transaction_id integer GENERATED BY DEFAULT AS IDENTITY NOT NULL,
    policy_id integer NOT NULL,
    due_date date NOT NULL,
    amount numeric(10,2) NOT NULL,
    paid_on date,
    CONSTRAINT pk_premium_transactions PRIMARY KEY (transaction_id),
    CONSTRAINT fk_premium_transactions_policy_id FOREIGN KEY (policy_id) REFERENCES policies (policy_id)
);

COMMENT ON TABLE premium_transactions IS 'A premium instalment due on a policy, and whether it was paid.';

COMMENT ON COLUMN premium_transactions.transaction_id IS 'Surrogate key';

COMMENT ON COLUMN premium_transactions.paid_on IS 'null: not paid';

CREATE TABLE claims (
    claim_id integer GENERATED BY DEFAULT AS IDENTITY NOT NULL,
    claim_number text NOT NULL,
    policy_id integer NOT NULL,
    loss_date date NOT NULL,
    reported_date date NOT NULL,
    cause text NOT NULL,
    status 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 'A loss reported against one policy.';

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

COMMENT ON COLUMN claims.loss_date IS 'when the event happened';

COMMENT ON COLUMN claims.reported_date IS 'when Harbour Mutual heard of it';

COMMENT ON COLUMN claims.status IS 'open, closed or rejected';

COMMENT ON COLUMN claims.reserve IS 'what the insurer still expects to pay on an open claim';

CREATE TABLE claim_payments (
    payment_id integer GENERATED BY DEFAULT AS IDENTITY NOT NULL,
    claim_id integer NOT NULL,
    paid_on date NOT NULL,
    amount numeric(12,2) NOT NULL,
    CONSTRAINT pk_claim_payments PRIMARY KEY (payment_id),
    CONSTRAINT fk_claim_payments_claim_id FOREIGN KEY (claim_id) REFERENCES claims (claim_id)
);

COMMENT ON TABLE claim_payments IS 'A payment made on a claim.';

COMMENT ON COLUMN claim_payments.payment_id IS 'Surrogate key';

CREATE TABLE claim_documents (
    document_id uuid NOT NULL DEFAULT gen_random_uuid(),
    claim_id integer NOT NULL,
    doc jsonb NOT NULL,
    CONSTRAINT pk_claim_documents PRIMARY KEY (document_id),
    CONSTRAINT fk_claim_documents_claim_id FOREIGN KEY (claim_id) REFERENCES claims (claim_id)
);

COMMENT ON TABLE claim_documents IS 'An adjuster''s document on a claim, as JSON.';

COMMENT ON COLUMN claim_documents.document_id IS 'Surrogate key, generated';

COMMENT ON COLUMN claim_documents.doc IS 'adjuster notes, damaged items, fraud flags';

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.