示例#1
0
 protected function _initDb()
 {
     $dbConfig = $this->_options['couchdb'];
     Geves_Model_Object::setDbConfig($dbConfig);
     if ($dbConfig['validate']) {
         // Make sure the DB exists
         try {
             $db = Sopha_Db::createDb($dbConfig['dbname'], $dbConfig['hostname'], $dbConfig['port']);
         } catch (Sopha_Db_Exception $ex) {
             if ($ex->getCode() != 412) {
                 throw $ex;
             }
             $db = Geves_Model_Object::getDb();
         }
         // Load design documents and create them
         $views = (require APPLICATION_PATH . '/configs/couchdb-views.php');
         if (!is_array($views)) {
             throw new ErrorException("Unable to configure database views: \$views is not properly defined");
         }
         foreach ($views as $view => $viewData) {
             try {
                 $db->create($viewData, array('_design', $view));
             } catch (Sopha_Db_Exception $ex) {
                 if ($ex->getCode() == 409) {
                     // document already exists
                     if ($dbConfig['replaceViews']) {
                         $view = $db->retrieve(array('_design', $view));
                         $view->fromArray($viewData);
                         $db->update($view);
                     }
                 } else {
                     throw $ex;
                 }
             }
         }
     }
 }
示例#2
0
文件: DbTest.php 项目: shevron/sopha
 /**
  * Create a clean test DB before a test and return it 
  *
  * @return Sopha_Db
  */
 protected function _setupDb()
 {
     // First, delete the DB if it exists
     $this->_teardownDb();
     // Then, set up a clean new DB and return it
     list($host, $port, $db) = $this->_getUrlParts();
     $db = trim($db, '/');
     return Sopha_Db::createDb($db, $host, $port);
 }