# Connect to the database
db_connect(WFPL_DB, WFPL_DB_USER, WFPL_DB_PASS);
+
+# upgrade db (only) on special trigger (assures only one upgrade at a time)
+if (isset($_SERVER['HTTP_X_UPGRADE_DB_NOW'])) {
+ require_once(DOCROOT . 'inc/db_upgrade.php');
+ db_upgrade();
+}
--- /dev/null
+<?php
+
+require_once(DOCROOT . 'inc/wfpl/persistent.php');
+
+# instructions:
+#
+# 1. Write the next db_upgrade_to_XX() at the bottom of this file
+#
+# 2. curl -H "X-UPGRADE-DB-NOW: y" http://this-site.com/
+
+function db_upgrade() {
+ header("Content-Type: text/plain");
+ ini_set('display_errors', '1');
+ ini_set('html_errors', '0');
+
+ # initialize where we store the current db schema version
+ db_send_query('create table if not exists persistent ( k varchar(30) binary not null default "", v varchar(255) binary not null default "", primary key (k)) CHARSET=utf8;');
+
+ # now we can just do the needed upgrades
+ $cur = persistent_get('db_schema_version');
+ if ($cur === null) {
+ $cur = 0;
+ }
+
+ echo "db schema at version $cur\n\n";
+
+ $upgraded = false;
+ for ($next = $cur + 1; function_exists("db_upgrade_$next"); $next += 1) {
+ echo "upgrading DB to version $next...\n";
+ flush();
+ call_user_func("db_upgrade_$next");
+ persistent_set('db_schema_version', $next);
+ echo "done\n\n";
+ flush();
+ $upgraded = true;
+ }
+
+ if ($upgraded) {
+ echo "Upgrades complete\n";
+ } else {
+ echo "No upgrades needed\n";
+ }
+
+ exit();
+}
+
+#function db_upgrade_1() {
+# db_send_query("alter table foo add bar int(11) not null default 0");
+#}