diff options
author | Camil Staps | 2016-08-01 17:21:49 +0200 |
---|---|---|
committer | Camil Staps | 2016-08-01 17:21:49 +0200 |
commit | 38736c4b8fd1e9da5f3e6d0c6c088db90c4186d2 (patch) | |
tree | 560d63b7cc31227751c9f32bd7e560c835e8d1d7 | |
parent | Better Braintree error message (diff) |
Fix payment table
-rw-r--r-- | install/index.php | 10 | ||||
-rw-r--r-- | install/upgrade.php | 6 |
2 files changed, 10 insertions, 6 deletions
diff --git a/install/index.php b/install/index.php index 1bb4bdd..990c6eb 100644 --- a/install/index.php +++ b/install/index.php @@ -102,13 +102,14 @@ if (isset($_GET['create_tables'])) { KEY `invoice_fileId_2` (`invoice_fileId`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1"); - $_pdo->query("CREATE TABLE IF NOT EXISTS `payment` ( + $_pdo->query("CREATE TABLE IF NOT EXISTS `".Constants::db_prefix."payment` ( `id` smallint(5) unsigned NOT NULL AUTO_INCREMENT, `offerId` smallint(5) unsigned NOT NULL, `date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `braintree_id` varchar(36) DEFAULT NULL, `braintree_status` varchar(63) DEFAULT NULL, - PRIMARY KEY (`id`) + PRIMARY KEY (`id`), + UNIQUE KEY `offerId` (`offerId`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1;"); $_pdo->query("CREATE TABLE IF NOT EXISTS `".Constants::db_prefix."user` ( @@ -135,9 +136,8 @@ if (isset($_GET['create_tables'])) { ADD CONSTRAINT `offer_ibfk_1` FOREIGN KEY (`invoice_fileId`) REFERENCES `".Constants::db_prefix."file` (`id`), ADD CONSTRAINT `offer_ibfk_2` FOREIGN KEY (`contactId`) REFERENCES `".Constants::db_prefix."contact` (`id`)"); - $_pdo->query("CREATE UNIQUE INDEX `payment_uniq_1` ON `".Constants::db_prefix."payment` (`offerId`);"); - $_pdo->query("ALTER TABLE `payment` - ADD CONSTRAINT `payment_ibfk_1` FOREIGN KEY (`offerId`) REFERENCES `offer` (`id`);"); + $_pdo->query("ALTER TABLE `".Constants::db_prefix."payment` + ADD CONSTRAINT `payment_ibfk_1` FOREIGN KEY (`offerId`) REFERENCES `".Constants::db_prefix."offer` (`id`);"); echo "Succeeded creating the database tables."; diff --git a/install/upgrade.php b/install/upgrade.php index 0ebff57..8c97172 100644 --- a/install/upgrade.php +++ b/install/upgrade.php @@ -94,9 +94,13 @@ if (isset($_GET['upgrade'])) { `id` smallint(5) unsigned NOT NULL AUTO_INCREMENT, `offerId` smallint(5) unsigned NOT NULL, `date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - PRIMARY KEY (`id`) + PRIMARY KEY (`id`), + UNIQUE KEY `offerId` (`offerId`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1;"); + $_pdo->query("ALTER TABLE `".Constants::db_prefix."payment` + ADD CONSTRAINT `payment_ibfk_1` FOREIGN KEY (`offerId`) REFERENCES `".Constants::db_prefix."offer` (`id`);"); + $offers = $_pdo->query("SELECT `id`,`payment_received` FROM `".Constants::db_prefix."offer` WHERE `payment_received` IS NOT NULL"); $offers = $offers->fetchAll(PDO::FETCH_ASSOC); foreach ($offers as $offer) { |