Skip to content

Commit 8f3dafd

Browse files
authored
Merge pull request #2720 from r4sas/sql-sharestats
fix "field doesn't have a default values" error
2 parents 3b23295 + 832d67f commit 8f3dafd

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

include/version.inc.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
$defflip = (!cfip()) ? exit(header('HTTP/1.1 401 Unauthorized')) : 1;
33

44
define('MPOS_VERSION', '1.0.9');
5-
define('DB_VERSION', '1.0.2');
5+
define('DB_VERSION', '1.0.3');
66
define('CONFIG_VERSION', '1.0.1');
77
define('HASH_VERSION', 1);
88

sql/000_base_structure.sql

+3-3
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ CREATE TABLE IF NOT EXISTS `settings` (
142142
UNIQUE KEY `setting` (`name`)
143143
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
144144

145-
INSERT INTO `settings` (`name`, `value`) VALUES ('DB_VERSION', '1.0.2');
145+
INSERT INTO `settings` (`name`, `value`) VALUES ('DB_VERSION', '1.0.3');
146146

147147
CREATE TABLE IF NOT EXISTS `shares` (
148148
`id` bigint(30) NOT NULL AUTO_INCREMENT,
@@ -182,9 +182,9 @@ CREATE TABLE IF NOT EXISTS `statistics_shares` (
182182
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
183183
`account_id` int(10) unsigned NOT NULL,
184184
`block_id` int(10) unsigned NOT NULL,
185-
`valid` bigint(20) NOT NULL,
185+
`valid` bigint(20) NOT NULL DEFAULT '0',
186186
`invalid` bigint(20) NOT NULL DEFAULT '0',
187-
`pplns_valid` bigint(20) NOT NULL,
187+
`pplns_valid` bigint(20) NOT NULL DEFAULT '0',
188188
`pplns_invalid` bigint(20) NOT NULL DEFAULT '0',
189189
PRIMARY KEY (`id`),
190190
KEY `account_id` (`account_id`),
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
function run_103() {
3+
// Ugly but haven't found a better way
4+
global $setting, $config, $coin_address, $user, $mysqli;
5+
6+
// Version information
7+
$db_version_old = '1.0.2'; // What version do we expect
8+
$db_version_new = '1.0.3'; // What is the new version we wish to upgrade to
9+
$db_version_now = $setting->getValue('DB_VERSION'); // Our actual version installed
10+
11+
// Upgrade specific variables
12+
$aSql[] = "UPDATE `statistics_shares` SET `valid` = '0' WHERE `valid` IS NULL;";
13+
$aSql[] = "UPDATE `statistics_shares` SET `pplns_valid` = '0' WHERE `pplns_valid` IS NULL;";
14+
$aSql[] = "ALTER TABLE `statistics_shares` CHANGE `valid` `valid` BIGINT(20) NOT NULL DEFAULT '0', CHANGE `pplns_valid` `pplns_valid` BIGINT(20) NOT NULL DEFAULT '0';";
15+
$aSql[] = "UPDATE " . $setting->getTableName() . " SET value = '" . $db_version_new . "' WHERE name = 'DB_VERSION';";
16+
17+
if ($db_version_now == $db_version_old && version_compare($db_version_now, DB_VERSION, '<')) {
18+
// Run the upgrade
19+
echo '- Starting database migration to version ' . $db_version_new . PHP_EOL;
20+
foreach ($aSql as $sql) {
21+
echo '- Preparing: ' . $sql . PHP_EOL;
22+
$stmt = $mysqli->prepare($sql);
23+
if ($stmt && $stmt->execute()) {
24+
echo '- success' . PHP_EOL;
25+
} else {
26+
echo '- failed: ' . $mysqli->error . PHP_EOL;
27+
exit(1);
28+
}
29+
}
30+
}
31+
}
32+
?>

0 commit comments

Comments
 (0)