PR Review Lab · Move Shipping Addresses to Their Own Table

35:00left of 35:00

Move Shipping Addresses to Their Own Table

Shipping addresses move out of orders and into their own addresses table, which unblocks split shipments and saved addresses next quarter. Migration 0087 creates the table and copies every existing address, the repository now reads and writes the new table, and 0088 drops the old ship_* columns. orders has about 140 million rows. I ran both migrations against last week's staging snapshot and they finished in about 6 minutes. Planning to ship it all in Thursday's release.

Amigrations/0087_create_addresses.sql1 of 4

Files Changed

migrations/

orders/

tests/

migrations/0087_create_addresses.sql

SQL · Click a line number to comment · Tap a line to comment
@@ -0,0 +1,23 @@
Added: BEGIN;
Added:
Added: CREATE TABLE addresses (
Added: id bigserial PRIMARY KEY,
Added: order_id bigint NOT NULL REFERENCES orders (id),
Added: kind text NOT NULL,
Added: name text NOT NULL,
Added: line1 text NOT NULL,
Added: line2 text,
Added: city text NOT NULL,
Added: region text,
Added: postal_code text NOT NULL,
Added: country char(2) NOT NULL,
Added: created_at timestamptz NOT NULL DEFAULT now()
Added: );
Added:
Added: CREATE UNIQUE INDEX addresses_order_id_kind_key ON addresses (order_id, kind);
Added:
Added: INSERT INTO addresses (order_id, kind, name, line1, line2, city, region, postal_code, country)
Added: SELECT id, 'shipping', ship_name, ship_line1, ship_line2, ship_city, ship_region, ship_postal_code, ship_country
Added: FROM orders;
Added:
Added: COMMIT;