First cut at a Horde migration script runner. It works, but so far all it does
authorChuck Hagenbuch <chuck@horde.org>
Sat, 9 Jan 2010 04:09:31 +0000 (23:09 -0500)
committerChuck Hagenbuch <chuck@horde.org>
Sat, 9 Jan 2010 04:10:44 +0000 (23:10 -0500)
is go up.

horde/bin/db_migrate [new file with mode: 0755]

diff --git a/horde/bin/db_migrate b/horde/bin/db_migrate
new file mode 100755 (executable)
index 0000000..5937593
--- /dev/null
@@ -0,0 +1,54 @@
+#!/usr/bin/env php
+<?php
+/**
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @author Chuck Hagenbuch <chuck@horde.org>
+ */
+
+// Do CLI checks and environment setup first.
+require_once dirname(__FILE__) . '/../lib/core.php';
+
+// Make sure no one runs this from the web.
+if (!Horde_Cli::runningFromCLI()) {
+    exit("Must be run from the command line\n");
+}
+
+// Load the CLI environment - make sure there's no time limit, init some
+// variables, etc.
+Horde_Cli::init();
+
+// Include needed libraries.
+new Horde_Application(array('authentication' => 'none'));
+
+// Get a database connection
+$GLOBALS['conf']['sql']['adapter'] = $GLOBALS['conf']['sql']['phptype'] == 'mysqli' ? 'mysqli' : 'pdo_' . $GLOBALS['conf']['sql']['phptype'];
+$db = Horde_Db_Adapter::factory($GLOBALS['conf']['sql']);
+
+// Parse command line arguments
+$parser = new Horde_Argv_Parser();
+$parser->addOption('-a', '--app', array('type' => 'string'));
+$parser->addOption('-v', '--version', array('type' => 'int'));
+
+list($options, $positionalArgs) = $parser->parseArgs();
+
+if (empty($options->app)) {
+    $parser->parserError("The -a/--app argument is required");
+}
+$app = $options->app;
+if (!in_array($app, $GLOBALS['registry']->listApps())) {
+    $parser->parserError("$app is not a configured Horde application");
+}
+
+// Run
+$dir = $GLOBALS['registry']->get('fileroot', $app) . '/migrations/';
+$migrator = new Horde_Db_Migration_Migrator($db, $dir);
+try {
+    $migrator->up();
+} catch (Exception $e) {
+    echo $e->getMessage();
+    exit(1);
+}