feat: add TCO fields migration (refs #15)
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 <noreply@anthropic.com>
This commit is contained in:
@@ -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);
|
||||||
Reference in New Issue
Block a user