 --
 ALTER TABLE `credit`
   ADD CONSTRAINT `credit_ibfk_1` FOREIGN KEY (`user`) REFERENCES `user` (`id`);
+
+--
+-- Constraints der Tabelle `food_order`
+--
+ALTER TABLE `food_order`
+  ADD CONSTRAINT `food_order_ibfk_1` FOREIGN KEY (`admin`) REFERENCES `user` (`id`);
 
 --
 -- Constraints der Tabelle `product_line`

--

INSERT INTO `product` (`id`, `name`, `price_buy`, `price_sell`, `created`, `modified`) VALUES
(2, 'Döner mild', '3.40', '3.50', '2016-05-01 19:19:49', '2016-05-01 20:32:41'),
(3, 'Döner scharf', '3.50', '3.70', '2016-05-02 20:32:58', '2016-05-03 20:29:58'),
(4, 'Pizza Salami', '8.20', '8.70', '2016-05-02 20:33:09', '2016-05-03 20:36:00');

--
-- Trigger `product`
--
DELIMITER $$
CREATE TRIGGER `after_update_products` AFTER UPDATE ON `product` FOR EACH ROW BEGIN
        IF NEW.price_sell <> OLD.price_sell THEN         	
          UPDATE product_price_log SET valid_to = NOW() WHERE field = 'price_sell' AND valid_to IS NULL;             
          INSERT INTO product_price_log (id, product_id, field, price, valid_from, valid_to) VALUES (NULL, NEW.id, 'price_sell', NEW.price_sell, NOW(), NULL);         
        END IF;
        
        IF NEW.price_buy <> OLD.price_buy THEN         	
          UPDATE product_price_log SET valid_to = NOW() WHERE field = 'price_buy' AND valid_to IS NULL;             
          INSERT INTO product_price_log (id, product_id, field, price, valid_from, valid_to) VALUES (NULL, NEW.id, 'price_buy', NEW.price_buy, NOW(), NULL);         
        END IF;
    END
$$
DELIMITER ;

-- AUTO_INCREMENT für Tabelle `food_order`
--
ALTER TABLE `food_order`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=5;
--
-- AUTO_INCREMENT für Tabelle `product`
--
ALTER TABLE `product`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=8;
--
-- AUTO_INCREMENT für Tabelle `product_line`
--
