forked from MPOS/php-mpos
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add database upgrade script, update version in initial database
- Loading branch information
Showing
2 changed files
with
37 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
} | ||
} | ||
?> |