BEGIN;

ALTER TABLE recording_depletions
    ADD COLUMN IF NOT EXISTS total_used_qty numeric(15, 3) NOT NULL DEFAULT 0,
    ADD COLUMN IF NOT EXISTS usage_qty numeric(15, 3) NOT NULL DEFAULT 0;

UPDATE recording_depletions
SET pending_qty = 0
WHERE pending_qty IS NULL OR pending_qty <> 0;

ALTER TABLE recording_depletions
    ADD CONSTRAINT chk_recording_depletions_pending_zero
    CHECK (pending_qty = 0);

COMMIT;
