Normalization
One column must be copied, the other must not
A shop ships orders to customers, and customers move house and change email.
Two rules that sound similar and are opposites:
- Where the parcel went is history. If a customer moves after their order shipped, the shipment must still show the address it was actually delivered to. Support answers "where did my package go" with that.
- How to reach the customer is current. If a customer changes their email, every shipment, including old ones, must show the new address, because that is where the notification goes today.
The rest:
- A shipment belongs to a customer that exists.
- The tests read both through a view you provide,
shipment_contact, withshipment_id,ship_toandnotify_email. How you get those two values is the answer.
customers already exists.
The one thing that is fixed
3 relationsThe tests reference these names. Everything else is yours, and is what is being assessed: extra tables, extra columns, types, constraints, indexes.
customers
idemailaddress
shipments
idcustomer_id
shipment_contact
shipment_idship_tonotify_email
The schema that already exists
This runs before your submission. Do not repeat it, extend it.
CREATE TABLE customers (
id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
email TEXT NOT NULL,
address TEXT NOT NULL
);
INSERT INTO customers (email, address) VALUES ('ana@example.com', '10 Old Street');This one is for subscribers
The problem above is the whole problem, and nothing is hidden from it. What a subscription adds is the part that tells you whether your answer holds: a real Postgres runs your schema, a battery of hidden tests decides, and a design review reads what you wrote.
Checking your subscription…