From da90a3441f1cb437159654a803a0ce87f2a22b45 Mon Sep 17 00:00:00 2001 From: Chuck Hagenbuch Date: Fri, 8 Jan 2010 23:09:31 -0500 Subject: [PATCH] First cut at a Horde migration script runner. It works, but so far all it does is go up. --- horde/bin/db_migrate | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100755 horde/bin/db_migrate diff --git a/horde/bin/db_migrate b/horde/bin/db_migrate new file mode 100755 index 000000000..5937593d7 --- /dev/null +++ b/horde/bin/db_migrate @@ -0,0 +1,54 @@ +#!/usr/bin/env php + + */ + +// 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); +} -- 2.11.0