diff --git a/conf/default.conf.php b/conf/default.conf.php index 98b7d9ca7f..2d5f697122 100644 --- a/conf/default.conf.php +++ b/conf/default.conf.php @@ -719,6 +719,13 @@ return array( // fits within configured limits. 'storage.engine-selector' => 'PhabricatorDefaultFileStorageEngineSelector', + // Phabricator puts databases in a namespace, which defualts to "phabricator" + // -- for instance, the Differential database is named + // "phabricator_differential" by default. You can change this namespace if you + // want. Normally, you should not do this unless you are developing + // Phabricator and using namespaces to separate multiple sandbox datasets. + 'storage.default-namespace' => 'phabricator', + // -- Search ---------------------------------------------------------------- // diff --git a/scripts/sql/manage_storage.php b/scripts/sql/manage_storage.php index e2ed32cc02..ab547c38b5 100755 --- a/scripts/sql/manage_storage.php +++ b/scripts/sql/manage_storage.php @@ -40,7 +40,7 @@ $conf = PhabricatorEnv::newObjectFromConfig('mysql.configuration-provider'); $default_user = $conf->getUser(); $default_password = $conf->getPassword(); $default_host = $conf->getHost(); -$default_namespace = 'phabricator'; +$default_namespace = PhabricatorLiskDAO::getDefaultStorageNamespace(); try { $args->parsePartial( diff --git a/src/applications/base/storage/lisk/PhabricatorLiskDAO.php b/src/applications/base/storage/lisk/PhabricatorLiskDAO.php index c6324fc4ff..ce978b0a34 100644 --- a/src/applications/base/storage/lisk/PhabricatorLiskDAO.php +++ b/src/applications/base/storage/lisk/PhabricatorLiskDAO.php @@ -23,7 +23,7 @@ abstract class PhabricatorLiskDAO extends LiskDAO { private $edges = array(); - private static $namespace = 'phabricator'; + private static $namespaceStack = array(); /* -( Managing Edges )----------------------------------------------------- */ @@ -65,18 +65,39 @@ abstract class PhabricatorLiskDAO extends LiskDAO { /** * @task config */ - public static function setApplicationNamespace($namespace) { - self::$namespace = $namespace; + public static function pushStorageNamespace($namespace) { + self::$namespaceStack[] = $namespace; } + /** + * @task config + */ + public static function popStorageNamespace($namespace) { + array_pop(self::$namespaceStack); + } + + /** + * @task config + */ + public static function getDefaultStorageNamespace() { + return PhabricatorEnv::getEnvConfig('storage.default-namespace'); + } /** * @task config */ public function establishLiveConnection($mode) { + $namespace = end(self::$namespaceStack); + if (!strlen($namespace)) { + $namespace = self::getDefaultStorageNamespace(); + } + if (!strlen($namespace)) { + throw new Exception("No storage namespace configured!"); + } + $conf = PhabricatorEnv::newObjectFromConfig( 'mysql.configuration-provider', - array($this, $mode, self::$namespace)); + array($this, $mode, $namespace)); return PhabricatorEnv::newObjectFromConfig( 'mysql.implementation', diff --git a/src/infrastructure/setup/storage/management/PhabricatorStorageManagementAPI.php b/src/infrastructure/setup/storage/management/PhabricatorStorageManagementAPI.php index 2b7ea1c140..9d838a546e 100644 --- a/src/infrastructure/setup/storage/management/PhabricatorStorageManagementAPI.php +++ b/src/infrastructure/setup/storage/management/PhabricatorStorageManagementAPI.php @@ -25,7 +25,7 @@ final class PhabricatorStorageManagementAPI { public function setNamespace($namespace) { $this->namespace = $namespace; - PhabricatorLiskDAO::setApplicationNamespace($namespace); + PhabricatorLiskDAO::pushStorageNamespace($namespace); return $this; }