feat(workshop): vehicles must be assigned to a customer
- Added customer_id column to fleet_vehicles with FK to customers. - Enforced customer_id on create_vehicle endpoints (workshop and fleet). - New vehicle modal now requires a selected customer and stores customer_id. - Migration v4.13 applied to all tenants.
This commit is contained in:
20
pos/migrations/v4.13_fleet_vehicle_customer.sql
Normal file
20
pos/migrations/v4.13_fleet_vehicle_customer.sql
Normal file
@@ -0,0 +1,20 @@
|
||||
-- v4.13_fleet_vehicle_customer.sql
|
||||
-- Link fleet vehicles to a customer.
|
||||
|
||||
ALTER TABLE fleet_vehicles
|
||||
ADD COLUMN IF NOT EXISTS customer_id INTEGER;
|
||||
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM pg_constraint
|
||||
WHERE conname = 'fleet_vehicles_customer_id_fkey'
|
||||
) THEN
|
||||
ALTER TABLE fleet_vehicles
|
||||
ADD CONSTRAINT fleet_vehicles_customer_id_fkey
|
||||
FOREIGN KEY (customer_id) REFERENCES customers(id);
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_fleet_vehicles_customer_id
|
||||
ON fleet_vehicles (customer_id);
|
||||
Reference in New Issue
Block a user