therat/branching

This package is abandoned and no longer maintained. The author suggests using the octava/branching package instead.

Symfony BranchingBundle. Auto change database depends on еру current git branch.

2.7.0 2015-08-15 19:14 UTC

This package is auto-updated.

Last update: 2022-02-01 12:48:09 UTC


README

Symfony BranchingBundle. Auto change mysql database depends on current git branch.

SensioLabsInsight

Bundle version is connected with supported symfony version.

Installation

Download bundle by composer

composer require therat/branching

Then, enable the bundle by adding the following line in the app/AppKernel.php file of your project:

<?php
// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        if (in_array($this->getEnvironment(), ['dev', 'test'])) {
            $bundles[] = new TheRat\BranchingBundle\TheRatBranchingBundle();

        // ...
    }

    // ...
}

Create new branch git branch feature or git checkout -b feature.

After that run 'app/console' command, and bundle create and copy new database automatically.

Be sure, that your mysql connect has privileges to create new scheme. Bundle use default symfony connection params 'database_host' etc.

Configuration

# Default configuration for "BranchingBundle"

the_rat_branching:
    switch_db: false     #enable or disable auto switch db
    copy_db_data: false  #copy db from root db

Nginx example

Obviously, you're hosting must support dns name like this *.test.my.project.com. There is an example of nginx config for different branches:

server {
    #...
    
    if ($branch = "") {
        set $branch "master";
    }
    server_name ~^(www\.)?(?<branch>.+)\.test\.my\.project\.com$;
    root /www/test.my.project.com/project/$branch/web;
    
    #...

Twig extensions

Current branch

  • Get current branch, useful for generating project title
#your twig template file

{{ current_branch() }}

For master branch return master (dev) string.