Skip to content

Commit 570feee

Browse files
author
epriestley
committedApr 30, 2012
Make default database namespace configurable
Summary: Allow the default namespace to be set in configuration, so you can juggle multiple copies of sandbox test data or whatever. Test Plan: Changed default namespace, verified web UI and "storage" script respect it. Reviewers: btrahan, vrana, jungejason Reviewed By: vrana CC: aran Maniphest Tasks: T345 Differential Revision: https://secure.phabricator.com/D2341
1 parent c974cb3 commit 570feee

File tree

4 files changed

+34
-6
lines changed

4 files changed

+34
-6
lines changed
 

‎conf/default.conf.php

+7
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,13 @@
719719
// fits within configured limits.
720720
'storage.engine-selector' => 'PhabricatorDefaultFileStorageEngineSelector',
721721

722+
// Phabricator puts databases in a namespace, which defualts to "phabricator"
723+
// -- for instance, the Differential database is named
724+
// "phabricator_differential" by default. You can change this namespace if you
725+
// want. Normally, you should not do this unless you are developing
726+
// Phabricator and using namespaces to separate multiple sandbox datasets.
727+
'storage.default-namespace' => 'phabricator',
728+
722729

723730
// -- Search ---------------------------------------------------------------- //
724731

‎scripts/sql/manage_storage.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
$default_user = $conf->getUser();
4141
$default_password = $conf->getPassword();
4242
$default_host = $conf->getHost();
43-
$default_namespace = 'phabricator';
43+
$default_namespace = PhabricatorLiskDAO::getDefaultStorageNamespace();
4444

4545
try {
4646
$args->parsePartial(

‎src/applications/base/storage/lisk/PhabricatorLiskDAO.php

+25-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
abstract class PhabricatorLiskDAO extends LiskDAO {
2424

2525
private $edges = array();
26-
private static $namespace = 'phabricator';
26+
private static $namespaceStack = array();
2727

2828

2929
/* -( Managing Edges )----------------------------------------------------- */
@@ -65,18 +65,39 @@ public function getEdgePHIDs($type) {
6565
/**
6666
* @task config
6767
*/
68-
public static function setApplicationNamespace($namespace) {
69-
self::$namespace = $namespace;
68+
public static function pushStorageNamespace($namespace) {
69+
self::$namespaceStack[] = $namespace;
7070
}
7171

72+
/**
73+
* @task config
74+
*/
75+
public static function popStorageNamespace($namespace) {
76+
array_pop(self::$namespaceStack);
77+
}
78+
79+
/**
80+
* @task config
81+
*/
82+
public static function getDefaultStorageNamespace() {
83+
return PhabricatorEnv::getEnvConfig('storage.default-namespace');
84+
}
7285

7386
/**
7487
* @task config
7588
*/
7689
public function establishLiveConnection($mode) {
90+
$namespace = end(self::$namespaceStack);
91+
if (!strlen($namespace)) {
92+
$namespace = self::getDefaultStorageNamespace();
93+
}
94+
if (!strlen($namespace)) {
95+
throw new Exception("No storage namespace configured!");
96+
}
97+
7798
$conf = PhabricatorEnv::newObjectFromConfig(
7899
'mysql.configuration-provider',
79-
array($this, $mode, self::$namespace));
100+
array($this, $mode, $namespace));
80101

81102
return PhabricatorEnv::newObjectFromConfig(
82103
'mysql.implementation',

‎src/infrastructure/setup/storage/management/PhabricatorStorageManagementAPI.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ final class PhabricatorStorageManagementAPI {
2525

2626
public function setNamespace($namespace) {
2727
$this->namespace = $namespace;
28-
PhabricatorLiskDAO::setApplicationNamespace($namespace);
28+
PhabricatorLiskDAO::pushStorageNamespace($namespace);
2929
return $this;
3030
}
3131

0 commit comments

Comments
 (0)
Failed to load comments.