Created
May 6, 2011 07:44
-
-
Save MrTrick/958572 to your computer and use it in GitHub Desktop.
The code that produces https://gist.github.com/958570
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
.... | |
//Build and load the design into an object | |
echo "Building staging design..."; | |
chdir('../install/couchapp'); | |
$ddocstr = shell_exec('couchapp push --export'); | |
$ddoc = json_decode($ddocstr); | |
$ddoc_staging = clone $ddoc; | |
$ddoc_staging->_id = "_design/couchapp_staging"; | |
echo "done.\n"; | |
//Create or overwrite the 'couchapp_staging' design doc. | |
echo "Uploading staging design..."; | |
try { $ddoc_staging->_rev = $cc->getDoc("_design/couchapp_staging")->_rev; } catch (couchNotFoundException $e) {} | |
$ddoc_staging->_rev = $cc->storeDoc($ddoc_staging)->rev; | |
echo "done.\n"; | |
//Trigger a rebuild | |
$t = time(); | |
echo "Rebuilding all views (this may take a long time, you can track progress in the futon status window) ... "; | |
$cc->getView('couchapp_staging', 'by_type'); | |
echo "done. Elapsed time: ".(time()-$t)." seconds\n"; | |
//Trigger a rebuild of the lucene views, too | |
echo "Rebuilding lucene views (this may take a long time, too) ... "; | |
$cc->getView('couchapp_staging', 'by_type'); | |
$cc->getLuceneView('couchapp_staging', 'user', 'mark'); | |
echo "done. Elapsed time: ".(time()-$t)." seconds\n"; | |
//Push the new ddoc over the original 'couchapp' doc. | |
echo "Uploading production design..."; | |
try { $ddoc->_rev = $cc->getDoc("_design/couchapp")->_rev; } catch (couchNotFoundException $e) {} | |
$ddoc->_rev = $cc->storeDoc($ddoc)->rev; | |
echo "done.\n"; | |
//Verify that the production ddoc now follows the staging ddoc | |
echo "Checking view signatures..."; | |
$info_staging = $cc->getDesignDocInfo('couchapp_staging'); | |
$info = $cc->getDesignDocInfo('couchapp'); | |
if ($info_staging->view_index->signature == $info->view_index->signature) { | |
echo "done. Both signatures are: ".$info->view_index->signature."\n"; | |
} else { | |
echo "\nERROR! Staging signature (".$info_staging->view_index->signature.") does not match production signature (".$info->view_index->signature.")\n"; | |
echo "You may need to manually test and fix the production design document.\n"; die; | |
} | |
//Check that the production views build immediately. | |
$t = time(); | |
echo "Testing a production view (this should be immediate) ..."; | |
$cc->getView('couchapp', 'by_type'); | |
echo "done. Elapsed time: ".(time()-$t)." seconds\n"; | |
$t = time(); | |
echo "Testing a production lucene view (this should be immediate) ..."; | |
$cc->getLuceneView('couchapp', 'user', 'mark'); | |
echo "done. Elapsed time: ".(time()-$t)." seconds\n"; | |
$t = time(); | |
echo "[DEBUGGING] Testing a production lucene view again (this should be immediate) ..."; | |
$cc->getLuceneView('couchapp', 'user', 'mark'); | |
echo "done. Elapsed time: ".(time()-$t)." seconds\n"; | |
//Cleanup | |
echo "Removing staging design..."; | |
$cc->deleteDoc($ddoc_staging); | |
echo "done.\n"; | |
echo "Removing unused view output..."; | |
$cc->cleanupDatabaseViews(); | |
echo "done.\n"; | |
echo "Operation complete:\n"; | |
echo " The db design has been updated to CGM API Version v".$ddoc->cgm_api_version.".\n"; | |
echo " The db design doc rev is ".$ddoc->_rev."\n"; | |
echo "\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment