 SET time_zone = "+00:00";
 
 --
--- Database: `sparta`
---
-CREATE DATABASE IF NOT EXISTS `sparta` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
-USE `sparta`;
+-- Database: `sparta_unittest`
+--
+CREATE DATABASE IF NOT EXISTS `sparta_unittest` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
+USE `sparta_unittest`;
 
 DELIMITER $$
 --

CREATE DEFINER=`mgreenhill`@`%` PROCEDURE `PopulateLocoOrgs`(IN LOCO_CLASS_ID INT, IN LOCO_OPERATOR_ID INT, IN LOCO_LINK_WEIGHT INT, IN LOCO_LINK_TYPE INT)
BEGIN

INSERT INTO `sparta`.`loco_org_link` (`loco_id`, `operator_id`, `link_type`, `link_weight`) SELECT `loco_id`, LOCO_OPERATOR_ID, LOCO_LINK_TYPE, LOCO_LINK_WEIGHT FROM `sparta`.`loco_unit` WHERE `class_id` = LOCO_CLASS_ID AND `loco_id` NOT IN (SELECT `loco_id` FROM `sparta`.`loco_org_link` WHERE `operator_id` = LOCO_OPERATOR_ID AND `link_type` = LOCO_LINK_TYPE);

END$$



SET @num_length := CHAR_LENGTH(loco_number);

INSERT INTO `sparta_unittest`.`loco_unit` (`loco_id`, `loco_num`, `loco_name`, `loco_gauge`, `loco_gauge_id`, `loco_status_id`, `class_id`, `owner_id`, `operator_id`, `date_added`, `date_modified`, `entered_service`, `withdrawn`, `builders_number`, `photo_id`, `manufacturer_id`) VALUES (NULL, CONCAT(prefix, loco_number), '', '', loco_gauge_id, loco_status_id, loco_class_id, '0', '0', UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), '0', '0', '', '0', loco_manufacturer_id);

SET loco_number = lpad(loco_number + 1, @num_length, 0);

