brancher 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +16 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +35 -0
- data/Rakefile +7 -0
- data/brancher.gemspec +26 -0
- data/lib/brancher.rb +5 -0
- data/lib/brancher/database_tasks.rb +20 -0
- data/lib/brancher/railtie.rb +14 -0
- data/lib/brancher/version.rb +3 -0
- data/spec/brancher/database_tasks_spec.rb +57 -0
- data/spec/spec_helper.rb +2 -0
- metadata +129 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 794bc618c2113fb24eaf33499b55323ebc7425f6
|
4
|
+
data.tar.gz: 9eb12e1cef212d3d532b35829bd4114f7f4b1611
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3b00f8e1c87e437aece432eecf274846293a5c5b70ed04702737a8bae8ff8b8049230cf8fac657acfa78254672109e33d6b7f0b92c6177c90c7b9bdc6bb077a3
|
7
|
+
data.tar.gz: 901c925cfabb113446def2523c338a0daf78c2a272dc4881aff76777d72c5e3dd78e09174c943bb03680a276db4fbbb1e84b712ec87d97ed66516ec28b9bb646
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Naoto Kaneko
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Brancher
|
2
|
+
|
3
|
+
A rubygem to switch databases connected with ActiveRecord by Git branch
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
group :development do
|
11
|
+
gem "brancher"
|
12
|
+
end
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
```
|
18
|
+
$ bundle
|
19
|
+
```
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
For example, if the name of a database is `sample_app_dev`, Brancher will switch the database to `sample_app_dev_master` at `master` branch, and `sample_app_dev_some_feature` at `some_feature` branch.
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it ( https://github.com/[my-github-username]/brancher/fork )
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create a new Pull Request
|
32
|
+
|
33
|
+
## Author
|
34
|
+
|
35
|
+
[naoty](https://github.com/naoty)
|
data/Rakefile
ADDED
data/brancher.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'brancher/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "brancher"
|
8
|
+
spec.version = Brancher::VERSION
|
9
|
+
spec.authors = ["Naoto Kaneko"]
|
10
|
+
spec.email = ["naoty.k@gmail.com"]
|
11
|
+
spec.summary = %q{Switching databases connected with ActiveRecord by Git branch}
|
12
|
+
spec.homepage = "https://github.com/naoty/brancher"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_dependency "activerecord"
|
21
|
+
spec.add_dependency "railties"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "rspec"
|
26
|
+
end
|
data/lib/brancher.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require "active_record"
|
2
|
+
|
3
|
+
module Brancher
|
4
|
+
module DatabaseTasks
|
5
|
+
extend self
|
6
|
+
|
7
|
+
def rename_database(branch_name)
|
8
|
+
database_extname = File.extname(current_configuration["database"])
|
9
|
+
database_name = current_configuration["database"].gsub(%r{#{database_extname}$}) { "" }
|
10
|
+
database_name += "_#{branch_name}"
|
11
|
+
current_configuration["database"] = database_name + database_extname
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def current_configuration
|
17
|
+
ActiveRecord::Base.configurations[Rails.env]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require "rails"
|
2
|
+
|
3
|
+
module Brancher
|
4
|
+
class Railtie < Rails::Railtie
|
5
|
+
rake_tasks do
|
6
|
+
namespace :db do
|
7
|
+
task :load_config do
|
8
|
+
current_branch_name = `git rev-parse --abbrev-ref HEAD`.chomp
|
9
|
+
DatabaseTasks.rename_database(current_branch_name)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Brancher::DatabaseTasks do
|
4
|
+
describe ".rename_database" do
|
5
|
+
before do
|
6
|
+
allow(Brancher::DatabaseTasks).to receive(:current_configuration)
|
7
|
+
.and_return(configuration)
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:configuration) do
|
11
|
+
{
|
12
|
+
adapter: adapter,
|
13
|
+
pool: 5,
|
14
|
+
timeout: 5000,
|
15
|
+
database: database_name
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
let(:adapter) do
|
20
|
+
"sqlite3"
|
21
|
+
end
|
22
|
+
|
23
|
+
let(:database_name) do
|
24
|
+
"db/sample_app_development.sqlite3"
|
25
|
+
end
|
26
|
+
|
27
|
+
let(:branch) do
|
28
|
+
"master"
|
29
|
+
end
|
30
|
+
|
31
|
+
let(:new_database_name) do
|
32
|
+
"db/sample_app_development_#{branch}.sqlite3"
|
33
|
+
end
|
34
|
+
|
35
|
+
subject do
|
36
|
+
Brancher::DatabaseTasks.rename_database(branch)
|
37
|
+
end
|
38
|
+
|
39
|
+
it { is_expected.to eq new_database_name }
|
40
|
+
|
41
|
+
context "when the adapter is mysql2" do
|
42
|
+
let(:adapter) do
|
43
|
+
"mysql2"
|
44
|
+
end
|
45
|
+
|
46
|
+
let(:database_name) do
|
47
|
+
"sample_app_development"
|
48
|
+
end
|
49
|
+
|
50
|
+
let(:new_database_name) do
|
51
|
+
"#{database_name}_#{branch}"
|
52
|
+
end
|
53
|
+
|
54
|
+
it { is_expected.to eq new_database_name }
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: brancher
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Naoto Kaneko
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-01-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: railties
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.7'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.7'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description:
|
84
|
+
email:
|
85
|
+
- naoty.k@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".travis.yml"
|
92
|
+
- Gemfile
|
93
|
+
- LICENSE.txt
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- brancher.gemspec
|
97
|
+
- lib/brancher.rb
|
98
|
+
- lib/brancher/database_tasks.rb
|
99
|
+
- lib/brancher/railtie.rb
|
100
|
+
- lib/brancher/version.rb
|
101
|
+
- spec/brancher/database_tasks_spec.rb
|
102
|
+
- spec/spec_helper.rb
|
103
|
+
homepage: https://github.com/naoty/brancher
|
104
|
+
licenses:
|
105
|
+
- MIT
|
106
|
+
metadata: {}
|
107
|
+
post_install_message:
|
108
|
+
rdoc_options: []
|
109
|
+
require_paths:
|
110
|
+
- lib
|
111
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
requirements: []
|
122
|
+
rubyforge_project:
|
123
|
+
rubygems_version: 2.4.5
|
124
|
+
signing_key:
|
125
|
+
specification_version: 4
|
126
|
+
summary: Switching databases connected with ActiveRecord by Git branch
|
127
|
+
test_files:
|
128
|
+
- spec/brancher/database_tasks_spec.rb
|
129
|
+
- spec/spec_helper.rb
|