USE vn;

INSERT INTO salix.ACL (model, property, accessType, permission, principalType, principalId)
	VALUES ('Vehicle', 'filter', 'READ', 'ALLOW', 'ROLE', 'administrative'),
			('Vehicle', 'filter', 'READ', 'ALLOW', 'ROLE', 'deliveryAssistant'),
			('Vehicle', 'find', 'READ', 'ALLOW', 'ROLE', 'administrative'),
			('Vehicle', 'find', 'READ', 'ALLOW', 'ROLE', 'deliveryAssistant'),
			('Vehicle', 'findById', 'READ', 'ALLOW', 'ROLE', 'administrative'),
			('Vehicle', 'updateAttributes', 'WRITE', 'ALLOW', 'ROLE', 'administrative'),
			('Vehicle', 'updateAttributes', 'WRITE', 'ALLOW', 'ROLE', 'deliveryAssistant'),
			('BankPolicy', 'find', 'READ', 'ALLOW', 'ROLE', 'administrative'),
			('BankPolicy', 'find', 'READ', 'ALLOW', 'ROLE', 'deliveryAssistant'),
			('VehicleState', 'find', 'READ', 'ALLOW', 'ROLE', 'administrative'),
			('VehicleState', 'find', 'READ', 'ALLOW', 'ROLE', 'deliveryAssistant'),
			('Ppe', 'find', 'READ', 'ALLOW', 'ROLE', 'administrative' ),
			('Ppe', 'find', 'READ', 'ALLOW', 'ROLE', 'deliveryAssistant' ),
			('Vehicle', 'deleteById', 'WRITE', 'ALLOW', 'ROLE', 'administrative'),
			('Vehicle', 'deleteById', 'WRITE', 'ALLOW', 'ROLE', 'deliveryAssistant'),
			('VehicleType', 'find', 'READ', 'ALLOW', 'ROLE', 'employee'),
			('Vehicle', '__get__active', 'READ', 'ALLOW', 'ROLE', 'employee');

CREATE TABLE IF NOT EXISTS vehicleType (
	id INT(11) PRIMARY KEY AUTO_INCREMENT,
	name VARCHAR(45) NOT NULL
);

INSERT IGNORE INTO vehicleType (id, name)
	VALUES (1,'vehículo empresa'),
		(2, 'furgoneta'),
		(3, 'cabeza tractora'),
		(4, 'remolque');

ALTER TABLE vehicle ADD COLUMN importCooler  decimal(10,2) DEFAULT NULL;
ALTER TABLE vehicle ADD COLUMN vehicleTypeFk INT(11) DEFAULT 1;
ALTER TABLE vehicle ADD CONSTRAINT fk_vehicle_vehicleType FOREIGN KEY (vehicleTypeFk) REFERENCES vehicleType(id);

