From 9096b091b23df1e486cfac0ebcbe3a710260629a Mon Sep 17 00:00:00 2001 From: Marcus Hill Date: Sat, 2 Apr 2022 19:39:55 +0100 Subject: [PATCH] Add database updater --- database_updates.php | 48 ++++++++++++++++++ database_version.php | 8 +++ db.sql | 1 + get_settings.php | 3 ++ post.php | 20 ++------ settings-update.php | 114 ++++++++++++++++++++----------------------- setup.php | 5 +- 7 files changed, 120 insertions(+), 79 deletions(-) create mode 100644 database_updates.php create mode 100644 database_version.php diff --git a/database_updates.php b/database_updates.php new file mode 100644 index 00000000..28949d9a --- /dev/null +++ b/database_updates.php @@ -0,0 +1,48 @@ + CURRENT_DATABASE_VERSION){ + + // We need updates! + + + if(CURRENT_DATABASE_VERSION == '0.0.1'){ + // Insert queries here required to update to DB version 0.0.2 + // mysqli_query($mysqli, "ALTER TABLE ....."); + + + // Then, update the database to the next sequential version + //mysqli_query($mysqli, "UPDATE settings SET config_current_database_version = '0.0.2' WHERE company_id = '1'"); + + } + + + if(CURRENT_DATABASE_VERSION == '0.0.2'){ + // Insert queries here required to update to DB version 0.0.3 + // mysqli_query($mysqli, "ALTER TABLE ....."); + + + // Then, update the database to the next sequential version + //mysqli_query($mysqli, "UPDATE settings SET config_current_database_version = '0.0.3' WHERE company_id = '1'"); + + } + + // etc + +} +else{ + // Up-to-date +} \ No newline at end of file diff --git a/database_version.php b/database_version.php new file mode 100644 index 00000000..290242b2 --- /dev/null +++ b/database_version.php @@ -0,0 +1,8 @@ + + %h%ar%s'"); ?> -
+
-

Update

+

Update

-
- -
Update App
- -
Update Database
-

Latest version

- - -
- - - - - - - - - - - - - -
CommitWhenDescription
- + + +
Update App
+ CURRENT_DATABASE_VERSION){ ?> +
Update Database
+
+ Current DB Version: +
+ Latest DB Version: + +

Latest version!

+ Current DB Version: + + $tmp_path/current-structure.sql"); - - // Get the new structure from db.sql - exec("egrep -v 'MariaDB dump|Host:|Server version|Dump completed' db.sql > $tmp_path/new-structure.sql"); - - // Compare - exec("diff $tmp_path/current-structure.sql $tmp_path/new-structure.sql > $tmp_path/diff.txt"); - $diff = file_get_contents("$tmp_path/diff.txt"); - - // Display, if there is a difference - if(!empty($diff)){ - echo "

Diff between your database structure and db.sql

"; - echo "
$diff
"; - } - - } - ?> + + + + + + + + + + + + + + +
CommitWhenDescription
+
-
+