diff --git a/database/purchases.sql b/database/purchases.sql index 280ea34..45741c4 100644 --- a/database/purchases.sql +++ b/database/purchases.sql @@ -14,7 +14,7 @@ CREATE TABLE IF NOT EXISTS `purchases` ( `bitcoin_price` DECIMAL(16, 4) NOT NULL, -- The amount of Bitcoin that can be purchased in relation to the amount of currency entered - `bitcoin_amount` DECIMAL(8, 8) NOT NULL DEFAULT 0.0000, + `bitcoin_amount` DECIMAL(16, 8) NOT NULL DEFAULT 0.0000, -- The Bitcoin network TXID that establishes the transaction has happened `txid` VARCHAR(64) NULL DEFAULT NULL, diff --git a/includes/Purchase.php b/includes/Purchase.php index e2784b6..4162051 100644 --- a/includes/Purchase.php +++ b/includes/Purchase.php @@ -242,7 +242,7 @@ public function getCurrencyAmount() { private $bitcoinAmount; - public function setBitcoinAmount(Amount $amt) { + private function setBitcoinAmount(Amount $amt) { $this->bitcoinAmount = $amt; return $this; } diff --git a/update.php b/update.php index 33abf2f..7411dde 100644 --- a/update.php +++ b/update.php @@ -8,12 +8,17 @@ $addEmailToNotify = true; $addNTXID = true; +$fixPrecision = true; foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) { - echo $row['Field'] . "\n"; if ($row['Field'] === 'email_to_notify') { $addEmailToNotify = false; } + if ($row['Field'] === 'bitcoin_amount') { + if (strpos($row['Type'], '16') !== false) { + $fixPrecision = false; + } + } if ($row['Field'] === 'ntxid') { $addNTXID = false; } @@ -37,6 +42,15 @@ echo "Column 'ntxid' added.\n"; } +if ($fixPrecision) { + $db->query(' + ALTER TABLE `purchases` + MODIFY COLUMN + bitcoin_amount DECIMAL(16, 8) NOT NULL DEFAULT 0.0000 + '); + echo "Column 'bitcoin_amount' fixed.\n"; +} + $stmt = $db->query(file_get_contents(__DIR__ . '/database/jobs.sql')); echo "update finished\n";