From b0d79a26ae78fb9bd86b22dec2af10c17de23afd Mon Sep 17 00:00:00 2001 From: Eric Gullickson <16152721+ericgullickson@users.noreply.github.com> Date: Mon, 12 Jan 2026 19:56:30 -0600 Subject: [PATCH] feat: add TCO fields migration (refs #15) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add database columns for Total Cost of Ownership: - purchase_price, purchase_date - insurance_cost, insurance_interval - registration_cost, registration_interval - tco_enabled toggle Includes CHECK constraints for interval values and non-negative costs. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- .../migrations/006_add_tco_fields.sql | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 backend/src/features/vehicles/migrations/006_add_tco_fields.sql diff --git a/backend/src/features/vehicles/migrations/006_add_tco_fields.sql b/backend/src/features/vehicles/migrations/006_add_tco_fields.sql new file mode 100644 index 0000000..0f1e993 --- /dev/null +++ b/backend/src/features/vehicles/migrations/006_add_tco_fields.sql @@ -0,0 +1,33 @@ +-- Migration: Add TCO (Total Cost of Ownership) fields to vehicles table +-- Issue: #15 + +ALTER TABLE vehicles + ADD COLUMN IF NOT EXISTS purchase_price DECIMAL(12,2), + ADD COLUMN IF NOT EXISTS purchase_date DATE, + ADD COLUMN IF NOT EXISTS insurance_cost DECIMAL(10,2), + ADD COLUMN IF NOT EXISTS insurance_interval VARCHAR(20), + ADD COLUMN IF NOT EXISTS registration_cost DECIMAL(10,2), + ADD COLUMN IF NOT EXISTS registration_interval VARCHAR(20), + ADD COLUMN IF NOT EXISTS tco_enabled BOOLEAN DEFAULT false; + +-- Add CHECK constraints to enforce valid interval values +ALTER TABLE vehicles + ADD CONSTRAINT chk_insurance_interval + CHECK (insurance_interval IS NULL OR insurance_interval IN ('monthly', 'semi_annual', 'annual')); + +ALTER TABLE vehicles + ADD CONSTRAINT chk_registration_interval + CHECK (registration_interval IS NULL OR registration_interval IN ('monthly', 'semi_annual', 'annual')); + +-- Add CHECK constraints for non-negative costs +ALTER TABLE vehicles + ADD CONSTRAINT chk_purchase_price_non_negative + CHECK (purchase_price IS NULL OR purchase_price >= 0); + +ALTER TABLE vehicles + ADD CONSTRAINT chk_insurance_cost_non_negative + CHECK (insurance_cost IS NULL OR insurance_cost >= 0); + +ALTER TABLE vehicles + ADD CONSTRAINT chk_registration_cost_non_negative + CHECK (registration_cost IS NULL OR registration_cost >= 0);