octava / branching
Auto change database depends on current git branch.
Installs: 57 029
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 5
Forks: 2
Open Issues: 1
Requires
- php: ^7.1.3
- ext-pdo: *
- ext-zlib: *
- doctrine/doctrine-bundle: ~2.0
- symfony/dependency-injection: ~4.4
- symfony/monolog-bundle: ^3.3
- symfony/process: ~4.4
- symfony/yaml: ~4.4
- twig/twig: ^3.3
README
Symfony BranchingBundle. Auto change mysql database depends on current git branch.
Bundle version is connected with supported symfony version.
Installation
Download bundle by composer
composer require octava/branching
Then, enable the bundle by adding the following line in the app/AppKernel.php file of your project:
<?php // config/bundles.php return [ // ... Octava\Bundle\BranchingBundle\OctavaBranchingBundle::class => ['all' => true], // ... }
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"
# config/packages/octava_branching.yaml octava_branching: switch_db: enabled: true connection_urls: - '%env(resolve:DATABASE_URL)%' - '%env(resolve:BACKEND_DATABASE_URL)%' ignore_tables: - error_log - resend_log alter_increment_map: default: 'UserBundle:User': test: start: 50000000 step: 1000 dev: start: 8000000 step: 1000 'BalanceBundle:BalanceOperation': ~ 'partner': ~
Configuration for dev
#config/packages/dev/octava_branching.yaml octava_branching: switch_db: enabled: true
Nginx example
Obviously, you're hosting must support dns name like this *.test.project.com
.
There is an example of nginx config for different branches:
server {
#...
if ($branch = "") {
set $branch "master";
}
server_name ~^(www\.)?(?<branch>.+)\.test\.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
{{ octava_current_branch() }}
For master branch return master (dev)
string.