-- Follow-up to 0002/0003. Reading the live Apps Script source
-- (isQPIEligibleMonth, checked across 6 call sites in JavaScript.html)
-- confirms QPI is never a standalone invoice -- it's always a
-- 'qpi'-type line item appended to the items[] of a Cut 2 invoice in
-- eligible months (Mar/Jun/Sep/Dec). The standalone QPI invoice model
-- introduced in 0002/0003 doesn't reflect how the source system
-- actually works, so we're removing it.

-- Drop the shape-validity check before dropping the columns it references.
alter table invoices drop constraint invoices_type_shape_check;

-- q_key only existed to key standalone QPI invoices by quarter -- no
-- longer meaningful once QPI is just a line item on a regular invoice.
alter table invoices drop column q_key;

-- "type" only ever distinguished 'regular' from 'qpi'. With 'qpi' gone
-- as a row-level concept, it would carry exactly one possible value
-- forever -- dropped entirely rather than left around as a single-value
-- column future readers would have to puzzle over.
alter table invoices drop column type;

-- With no more standalone QPI invoices, every row is a real bi-monthly
-- cut invoice again -- restore the original 0001 guarantee.
alter table invoices
  alter column month set not null,
  alter column cut_number set not null;
