add database upgrade script, update version in initial database
This commit is contained in:
parent
cdba6ce722
commit
b007bfa9a9
@ -142,7 +142,7 @@ CREATE TABLE IF NOT EXISTS `settings` (
|
|||||||
UNIQUE KEY `setting` (`name`)
|
UNIQUE KEY `setting` (`name`)
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||||
|
|
||||||
INSERT INTO `settings` (`name`, `value`) VALUES ('DB_VERSION', '1.0.2');
|
INSERT INTO `settings` (`name`, `value`) VALUES ('DB_VERSION', '1.0.3');
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS `shares` (
|
CREATE TABLE IF NOT EXISTS `shares` (
|
||||||
`id` bigint(30) NOT NULL AUTO_INCREMENT,
|
`id` bigint(30) NOT NULL AUTO_INCREMENT,
|
||||||
|
|||||||
36
upgrade/definitions/1.0.2_to_1.0.3.inc.php
Normal file
36
upgrade/definitions/1.0.2_to_1.0.3.inc.php
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
function run_103() {
|
||||||
|
// Ugly but haven't found a better way
|
||||||
|
global $setting, $config, $coin_address, $user, $mysqli;
|
||||||
|
|
||||||
|
// Version information
|
||||||
|
$db_version_old = '1.0.2'; // What version do we expect
|
||||||
|
$db_version_new = '1.0.3'; // What is the new version we wish to upgrade to
|
||||||
|
$db_version_now = $setting->getValue('DB_VERSION'); // Our actual version installed
|
||||||
|
|
||||||
|
// Upgrade specific variables
|
||||||
|
$aSql[] = "
|
||||||
|
ALTER TABLE `statistics_shares`
|
||||||
|
CHANGE `valid` `valid` BIGINT(20) NOT NULL DEFAULT '0',
|
||||||
|
CHANGE `invalid` `invalid` BIGINT(20) NOT NULL DEFAULT '0',
|
||||||
|
CHANGE `pplns_valid` `pplns_valid` BIGINT(20) NOT NULL DEFAULT '0',
|
||||||
|
CHANGE `pplns_invalid` `pplns_invalid` BIGINT(20) NOT NULL DEFAULT '0';
|
||||||
|
";
|
||||||
|
$aSql[] = "UPDATE " . $setting->getTableName() . " SET value = '" . $db_version_new . "' WHERE name = 'DB_VERSION';";
|
||||||
|
|
||||||
|
if ($db_version_now == $db_version_old && version_compare($db_version_now, DB_VERSION, '<')) {
|
||||||
|
// Run the upgrade
|
||||||
|
echo '- Starting database migration to version ' . $db_version_new . PHP_EOL;
|
||||||
|
foreach ($aSql as $sql) {
|
||||||
|
echo '- Preparing: ' . $sql . PHP_EOL;
|
||||||
|
$stmt = $mysqli->prepare($sql);
|
||||||
|
if ($stmt && $stmt->execute()) {
|
||||||
|
echo '- success' . PHP_EOL;
|
||||||
|
} else {
|
||||||
|
echo '- failed: ' . $mysqli->error . PHP_EOL;
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
Loading…
Reference in New Issue
Block a user