Skip to content

Instantly share code, notes, and snippets.

@ncherro
Created October 2, 2012 15:36
Show Gist options
  • Save ncherro/3820222 to your computer and use it in GitHub Desktop.
Save ncherro/3820222 to your computer and use it in GitHub Desktop.
Drupal branch-specific database settings
<?php
// full path to project root (you'll need to edit this)
$root = dirname(dirname(dirname(__DIR__)));
// project name here (full db name will be my_project_[current git branch])
$project_name = 'my_project';
// base connection info
$base_conn = array(
'driver' => 'mysql',
'username' => 'USERNAME',
'password' => 'PASSWORD',
'host' => 'localhost',
'prefix' => '',
);
// set the database name based on which git branch we're in
$branch = file($root . '/.git/HEAD');
$branch = reset($branch);
$branch = explode('/', $branch);
$branch = trim($branch[2]);
$databases['default']['default'] = $base_conn + array(
'database' => $project_name . '_' . $branch,
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment