Add database foreign keys related to rewards

This commit is contained in:
FrancescoUK
2017-07-29 22:21:20 +01:00
parent cd792eb56a
commit 6485cf050d
5 changed files with 130 additions and 51 deletions

View File

@@ -117,7 +117,8 @@ CREATE TABLE `ospos_customers` (
`points` int(11) DEFAULT NULL,
`deleted` int(1) NOT NULL DEFAULT '0',
UNIQUE KEY `account_number` (`account_number`),
KEY `person_id` (`person_id`)
KEY `person_id` (`person_id`),
KEY `package_id` (`package_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
@@ -923,7 +924,10 @@ CREATE TABLE IF NOT EXISTS `ospos_customers_points` (
`package_id` int(11) NOT NULL,
`sale_id` int(11) NOT NULL,
`points_earned` int(11) NOT NULL,
PRIMARY KEY (`id`)
PRIMARY KEY (`id`),
KEY `person_id` (`person_id`),
KEY `package_id` (`package_id`),
KEY `sale_id` (`sale_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
@@ -938,7 +942,8 @@ CREATE TABLE IF NOT EXISTS `ospos_sales_reward_points` (
`sale_id` int(11) NOT NULL,
`earned` float NOT NULL,
`used` float NOT NULL,
PRIMARY KEY (`id`)
PRIMARY KEY (`id`),
KEY `sale_id` (`sale_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
@@ -952,7 +957,8 @@ CREATE TABLE IF NOT EXISTS `ospos_sales_reward_points` (
-- Constraints for table `ospos_customers`
--
ALTER TABLE `ospos_customers`
ADD CONSTRAINT `ospos_customers_ibfk_1` FOREIGN KEY (`person_id`) REFERENCES `ospos_people` (`person_id`);
ADD CONSTRAINT `ospos_customers_ibfk_1` FOREIGN KEY (`person_id`) REFERENCES `ospos_people` (`person_id`),
ADD CONSTRAINT `ospos_customers_ibfk_2` FOREIGN KEY (`package_id`) REFERENCES `ospos_customers_packages` (`package_id`);
--
-- Constraints for table `ospos_employees`
@@ -1092,3 +1098,16 @@ ALTER TABLE `ospos_suppliers`
ALTER TABLE `ospos_giftcards`
ADD CONSTRAINT `ospos_giftcards_ibfk_1` FOREIGN KEY (`person_id`) REFERENCES `ospos_people` (`person_id`);
--
-- Constraints for table `ospos_customers_points`
--
ALTER TABLE `ospos_customers_points`
ADD CONSTRAINT `ospos_customers_points_ibfk_1` FOREIGN KEY (`person_id`) REFERENCES `ospos_customers` (`person_id`),
ADD CONSTRAINT `ospos_customers_points_ibfk_2` FOREIGN KEY (`package_id`) REFERENCES `ospos_customers_packages` (`package_id`),
ADD CONSTRAINT `ospos_customers_points_ibfk_3` FOREIGN KEY (`sale_id`) REFERENCES `ospos_sales_items` (`sale_id`);
--
-- Constraints for table `ospos_sales_reward_points`
--
ALTER TABLE `ospos_sales_reward_points`
ADD CONSTRAINT `ospos_sales_reward_points_ibfk_1` FOREIGN KEY (`sale_id`) REFERENCES `ospos_sales_items` (`sale_id`);