diff --git a/sql/012_accounts_update.sql b/sql/012_accounts_update.sql deleted file mode 100644 index 2ba7cbbe..00000000 --- a/sql/012_accounts_update.sql +++ /dev/null @@ -1,3 +0,0 @@ -ALTER TABLE `accounts` CHANGE `sessionTimeoutStamp` `last_login` INT( 10 ) NULL DEFAULT NULL ; -INSERT INTO `settings` (`name`, `value`) VALUES ('DB_VERSION', '0.0.2') ON DUPLICATE KEY UPDATE `value` = '0.0.2'; -INSERT INTO `settings` (`name`, `value`) VALUES ('db_upgrade_required', 0) ON DUPLICATE KEY UPDATE `value` = 0; diff --git a/sql/013_tokentype_update.sql b/sql/013_tokentype_update.sql deleted file mode 100644 index 8445e2f7..00000000 --- a/sql/013_tokentype_update.sql +++ /dev/null @@ -1,6 +0,0 @@ -INSERT INTO `token_types` (`name`, `expiration`) VALUES ('account_edit', 360); -INSERT INTO `token_types` (`name`, `expiration`) VALUES ('change_pw', 360); -INSERT INTO `token_types` (`name`, `expiration`) VALUES ('withdraw_funds', 360); -CREATE INDEX `account_id` ON `notification_settings` (`account_id`); -CREATE UNIQUE INDEX `account_id_type` ON `notification_settings` (`account_id`,`type`); -INSERT INTO `settings` (`name`, `value`) VALUES ('DB_VERSION', '0.0.3') ON DUPLICATE KEY UPDATE `value` = '0.0.3'; diff --git a/sql/014_accounts_update.sql b/sql/014_accounts_update.sql deleted file mode 100644 index ed7802c0..00000000 --- a/sql/014_accounts_update.sql +++ /dev/null @@ -1,5 +0,0 @@ -ALTER TABLE `accounts` ADD COLUMN `signup_timestamp` INT( 10 ) NOT NULL DEFAULT '0' AFTER `failed_pins`; -ALTER TABLE `accounts` ADD COLUMN `notify_email` VARCHAR( 255 ) NULL DEFAULT NULL AFTER `email`; -TRUNCATE TABLE `token_types`; -INSERT INTO `token_types` (`id`, `name`, `expiration`) VALUES (1, 'password_reset', 3600), (2, 'confirm_email', 0), (3, 'invitation', 0), (4, 'account_unlock', 0), (5, 'account_edit', 3600), (6, 'change_pw', 3600), (7, 'withdraw_funds', 3600); -INSERT INTO `settings` (`name`, `value`) VALUES ('DB_VERSION', '0.0.4') ON DUPLICATE KEY UPDATE `value` = '0.0.4'; diff --git a/sql/015_accounts_update.sql b/sql/015_accounts_update.sql deleted file mode 100644 index 3ff16668..00000000 --- a/sql/015_accounts_update.sql +++ /dev/null @@ -1,3 +0,0 @@ -UPDATE `accounts` SET `coin_address` = NULL WHERE `coin_address` = ''; -ALTER TABLE `accounts` ADD UNIQUE INDEX ( `coin_address` ) ; -INSERT INTO `settings` (`name`, `value`) VALUES ('DB_VERSION', '0.0.5') ON DUPLICATE KEY UPDATE `value` = '0.0.5'; diff --git a/sql/016_transactions_update.sql b/sql/016_transactions_update.sql deleted file mode 100644 index 6458aab8..00000000 --- a/sql/016_transactions_update.sql +++ /dev/null @@ -1,2 +0,0 @@ -CREATE INDEX `account_id_archived` ON `transactions` (`account_id`,`archived`); -INSERT INTO `settings` (`name`, `value`) VALUES ('DB_VERSION', '0.0.6') ON DUPLICATE KEY UPDATE `value` = '0.0.6'; diff --git a/sql/017_blocks_update.sql b/sql/017_blocks_update.sql deleted file mode 100644 index 0e87da9b..00000000 --- a/sql/017_blocks_update.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE `blocks` CHANGE `share_id` `share_id` BIGINT( 30 ) NULL DEFAULT NULL ; -INSERT INTO `settings` (`name`, `value`) VALUES ('DB_VERSION', '0.0.7') ON DUPLICATE KEY UPDATE `value` = '0.0.7'; diff --git a/upgrade/definitions/0.0.1_to_0.0.2.inc.php b/upgrade/definitions/0.0.1_to_0.0.2.inc.php new file mode 100755 index 00000000..1b24ca56 --- /dev/null +++ b/upgrade/definitions/0.0.1_to_0.0.2.inc.php @@ -0,0 +1,19 @@ +getValue('DB_VERSION'); // Our actual version installed + + // Upgrade specific variables + $aSql[] = "ALTER TABLE `accounts` CHANGE `sessionTimeoutStamp` `last_login` INT( 10 ) NULL DEFAULT NULL"; + $aSql[] = "INSERT INTO `settings` (`name`, `value`) VALUES ('DB_VERSION', '0.0.2') ON DUPLICATE KEY UPDATE `value` = '0.0.2'"; + + if ($db_version_now == $db_version_old && version_compare($db_version_now, DB_VERSION, '<')) { + execute_db_upgrade($aSql); + } +} +?> diff --git a/upgrade/definitions/0.0.2_to_0.0.3.inc.php b/upgrade/definitions/0.0.2_to_0.0.3.inc.php new file mode 100755 index 00000000..c7025fcb --- /dev/null +++ b/upgrade/definitions/0.0.2_to_0.0.3.inc.php @@ -0,0 +1,23 @@ +getValue('DB_VERSION'); // Our actual version installed + + // Upgrade specific variables + $aSql[] = "INSERT INTO `token_types` (`name`, `expiration`) VALUES ('account_edit', 360)"; + $aSql[] = "INSERT INTO `token_types` (`name`, `expiration`) VALUES ('change_pw', 360)"; + $aSql[] = "INSERT INTO `token_types` (`name`, `expiration`) VALUES ('withdraw_funds', 360)"; + $aSql[] = "CREATE INDEX `account_id` ON `notification_settings` (`account_id`)"; + $aSql[] = "CREATE UNIQUE INDEX `account_id_type` ON `notification_settings` (`account_id`,`type`)"; + $aSql[] = "INSERT INTO `settings` (`name`, `value`) VALUES ('DB_VERSION', '0.0.3') ON DUPLICATE KEY UPDATE `value` = '0.0.3'"; + + if ($db_version_now == $db_version_old && version_compare($db_version_now, DB_VERSION, '<')) { + execute_db_upgrade($aSql); + } +} +?> diff --git a/upgrade/definitions/0.0.3_to_0.0.4.inc.php b/upgrade/definitions/0.0.3_to_0.0.4.inc.php new file mode 100755 index 00000000..d843a4aa --- /dev/null +++ b/upgrade/definitions/0.0.3_to_0.0.4.inc.php @@ -0,0 +1,22 @@ +getValue('DB_VERSION'); // Our actual version installed + + // Upgrade specific variables + $aSql[] = "ALTER TABLE `accounts` ADD COLUMN `signup_timestamp` INT( 10 ) NOT NULL DEFAULT '0' AFTER `failed_pins`"; + $aSql[] = "ALTER TABLE `accounts` ADD COLUMN `notify_email` VARCHAR( 255 ) NULL DEFAULT NULL AFTER `email`"; + $aSql[] = "TRUNCATE TABLE `token_types`"; + $aSql[] = "INSERT INTO `token_types` (`id`, `name`, `expiration`) VALUES (1, 'password_reset', 3600), (2, 'confirm_email', 0), (3, 'invitation', 0), (4, 'account_unlock', 0), (5, 'account_edit', 3600), (6, 'change_pw', 3600), (7, 'withdraw_funds', 3600)"; + $aSql[] = "INSERT INTO `settings` (`name`, `value`) VALUES ('DB_VERSION', '0.0.4') ON DUPLICATE KEY UPDATE `value` = '0.0.4'"; + + if ($db_version_now == $db_version_old && version_compare($db_version_now, DB_VERSION, '<')) { + execute_db_upgrade($aSql); + } +} +?> diff --git a/upgrade/definitions/0.0.4_to_0.0.5.inc.php b/upgrade/definitions/0.0.4_to_0.0.5.inc.php new file mode 100755 index 00000000..fb5d87fb --- /dev/null +++ b/upgrade/definitions/0.0.4_to_0.0.5.inc.php @@ -0,0 +1,21 @@ +getValue('DB_VERSION'); // Our actual version installed + + // Upgrade specific variables + $aSql[] = "ALTER TABLE `accounts` ADD COLUMN `signup_timestamp` INT( 10 ) NOT NULL DEFAULT '0' AFTER `failed_pins`"; + $aSql[] = "UPDATE `accounts` SET `coin_address` = NULL WHERE `coin_address` = ''"; + $aSql[] = "ALTER TABLE `accounts` ADD UNIQUE INDEX ( `coin_address` )"; + $aSql[] = "INSERT INTO `settings` (`name`, `value`) VALUES ('DB_VERSION', '0.0.5') ON DUPLICATE KEY UPDATE `value` = '0.0.5'"; + + if ($db_version_now == $db_version_old && version_compare($db_version_now, DB_VERSION, '<')) { + execute_db_upgrade($aSql); + } +} +?> diff --git a/upgrade/definitions/0.0.5_to_0.0.6.inc.php b/upgrade/definitions/0.0.5_to_0.0.6.inc.php new file mode 100755 index 00000000..a87658c5 --- /dev/null +++ b/upgrade/definitions/0.0.5_to_0.0.6.inc.php @@ -0,0 +1,19 @@ +getValue('DB_VERSION'); // Our actual version installed + + // Upgrade specific variables + $aSql[] = "CREATE INDEX `account_id_archived` ON `transactions` (`account_id`,`archived`)"; + $aSql[] = "INSERT INTO `settings` (`name`, `value`) VALUES ('DB_VERSION', '0.0.6') ON DUPLICATE KEY UPDATE `value` = '0.0.6'"; + + if ($db_version_now == $db_version_old && version_compare($db_version_now, DB_VERSION, '<')) { + execute_db_upgrade($aSql); + } +} +?> diff --git a/upgrade/definitions/0.0.6_to_0.0.7.inc.php b/upgrade/definitions/0.0.6_to_0.0.7.inc.php new file mode 100755 index 00000000..2b5bebfe --- /dev/null +++ b/upgrade/definitions/0.0.6_to_0.0.7.inc.php @@ -0,0 +1,19 @@ +getValue('DB_VERSION'); // Our actual version installed + + // Upgrade specific variables + $aSql[] = "ALTER TABLE `blocks` CHANGE `share_id` `share_id` BIGINT( 30 ) NULL DEFAULT NULL"; + $aSql[] = "INSERT INTO `settings` (`name`, `value`) VALUES ('DB_VERSION', '0.0.7') ON DUPLICATE KEY UPDATE `value` = '0.0.7'"; + + if ($db_version_now == $db_version_old && version_compare($db_version_now, DB_VERSION, '<')) { + execute_db_upgrade($aSql); + } +} +?> diff --git a/upgrade/run_upgrades.php b/upgrade/run_upgrades.php index dd949c8a..c0d02298 100755 --- a/upgrade/run_upgrades.php +++ b/upgrade/run_upgrades.php @@ -11,7 +11,7 @@ require_once('shared.inc.php'); // Fetch current version $db_version_now = $setting->getValue('DB_VERSION'); -// Helper function +// Helper functions function run_db_upgrade($db_version_now) { // Find upgrades $files = glob(dirname(__FILE__) . "/definitions/${db_version_now}_to_*"); @@ -27,6 +27,21 @@ function run_db_upgrade($db_version_now) { run_db_upgrade($db_version_to); } } +function execute_db_upgrade($aSql) { + global $mysqli; + // 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); + } + } +} // Initial caller run_db_upgrade($db_version_now);