eProtons Engineering Lab Migration analysis: Can we retire this column? Example schema and query supplied by eProtons. Column under review: customers.customer_status Example schema 1 CREATE TABLE customers ( 2 id BIGINT PRIMARY KEY, 3 name VARCHAR(200) NOT NULL, 4 customer_status VARCHAR(20) NOT NULL DEFAULT 'active', 5 status_code SMALLINT, 6 updated_at TIMESTAMP NOT NULL 7 ); 8 9 CREATE INDEX ix_customers_status ON customers (customer_status); 10 11 CREATE VIEW active_customers AS 12 SELECT id, name FROM customers WHERE customer_status = 'active'; Report query 1 -- Report: customers by status 2 SELECT customer_status, COUNT(*) AS customers 3 FROM customers 4 GROUP BY customer_status; Dependencies and the effect of dropping the column - Index ix_customers_status (Line 9): Dropped together with the column. Any query that relied on it for filtering by status loses that access path. - View active_customers (Lines 11 to 12): The view filters on the column. Dropping the column is refused while the view depends on it, and a cascading drop removes the view. - Report query Customers by status (Query lines 2 and 4): The query selects and groups by the column, so it fails once the column is removed. Open questions the schema cannot answer - Which application code writes or reads customer_status? - Do reporting tools or exports read the view active_customers? - Does status_code cover every customer_status value, or do some values have no mapping? - Do scheduled jobs filter on customer_status? Staged migration 1. Map and backfill: Map each customer_status value to status_code and backfill existing rows. 2. Move readers: Point the view and the report query to status_code. 3. Stop writes: Remove writes to customer_status and monitor for remaining use. 4. Remove: Drop the index, then the column. Checks before removal - Row counts by status match between the two columns. - active_customers returns the same rows before and after the change. - No reads of customer_status appear in query logs over an agreed period. - Application writes to customer_status are confirmed removed. The schema and query were analyzed as text. Nothing was executed against a database.