db_supplier 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +2 -0
- data/.travis.yml +7 -0
- data/README.md +4 -0
- data/db_supplier.gemspec +5 -1
- data/lib/db_supplier/migrator.rb +4 -2
- data/spec/migrator_spec.rb +123 -0
- data/spec/spec_helper.rb +24 -0
- metadata +65 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 533c11b3bc295ab99df5d77dc9a4bcc67bcb7bc4
|
4
|
+
data.tar.gz: f5794c726b53c1c61cc95625c11051a79a27e035
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3aba1be43ec02176b3d8290228710bd0d010d4048a381315003092001b50714766880fa1a3a1b30af1a2fbdada1a4d5b534cdd9fa942a87371118ffb0311623b
|
7
|
+
data.tar.gz: c45c45bc2f540801088cd548372802fa9ad4e271b3a7a8578faa183a5d7e1c517ffc3240dce9b1161ce389f92f4c6a2e2fe79059a6b97442a769e5b7a2192f54
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,7 +1,11 @@
|
|
1
1
|
# DBSupplier
|
2
|
+
[![Build Status](https://travis-ci.org/ryopeko/db_supplier.svg?branch=master)](https://travis-ci.org/ryopeko/db_supplier)
|
3
|
+
|
2
4
|
Migration tool from external database's DDL.
|
3
5
|
Fetch sql from GitHub repository and migrate local database.
|
4
6
|
|
7
|
+
![demo](https://cloud.githubusercontent.com/assets/192008/4487362/3443a748-49fa-11e4-87ef-88661b00fcc5.gif)
|
8
|
+
|
5
9
|
## Installation
|
6
10
|
|
7
11
|
Add this line to your application's Gemfile:
|
data/db_supplier.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "db_supplier"
|
7
|
-
spec.version = '0.0
|
7
|
+
spec.version = '0.1.0'
|
8
8
|
spec.authors = ["ryopeko"]
|
9
9
|
spec.email = ["ryopeko@gmail.com"]
|
10
10
|
spec.summary = %q{Migration tool from external database's DDL}
|
@@ -23,4 +23,8 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_development_dependency "rake", "~> 10.0"
|
24
24
|
spec.add_development_dependency "sqlite3"
|
25
25
|
spec.add_development_dependency "pry"
|
26
|
+
spec.add_development_dependency "rspec"
|
27
|
+
spec.add_development_dependency "rspec-mocks"
|
28
|
+
spec.add_development_dependency "simplecov"
|
29
|
+
spec.add_development_dependency "tapp"
|
26
30
|
end
|
data/lib/db_supplier/migrator.rb
CHANGED
@@ -14,6 +14,7 @@ module DBSupplier
|
|
14
14
|
@configurations = config
|
15
15
|
|
16
16
|
@schema_repository = config[:schema_repository]
|
17
|
+
@schema_ref = config[:schema_ref] || 'master'
|
17
18
|
@schema_files = config[:schema_files].symbolize_keys
|
18
19
|
@access_token = config[:access_token]
|
19
20
|
|
@@ -57,12 +58,13 @@ module DBSupplier
|
|
57
58
|
end
|
58
59
|
|
59
60
|
def fetch_sql(db_name)
|
60
|
-
migration_file_paths =
|
61
|
+
migration_file_paths = @schema_files.try(:fetch, db_name.to_sym) || (raise RuntimeError, "undefined #{db_name} schemat")
|
61
62
|
repository = @schema_repository || (raise RuntimeError, 'undefined schema repository')
|
62
63
|
|
63
|
-
migration_file_paths.map do |path|
|
64
|
+
Array(migration_file_paths).map do |path|
|
64
65
|
client.contents(
|
65
66
|
repository,
|
67
|
+
ref: @schema_ref,
|
66
68
|
path: path,
|
67
69
|
headers: {
|
68
70
|
accept: 'application/vnd.github.VERSION.raw'
|
@@ -0,0 +1,123 @@
|
|
1
|
+
require 'spec_helper.rb'
|
2
|
+
require 'db_supplier/migrator'
|
3
|
+
require 'active_record'
|
4
|
+
require 'logger'
|
5
|
+
|
6
|
+
def migrate_class
|
7
|
+
DBSupplier::Migrator.dup
|
8
|
+
end
|
9
|
+
|
10
|
+
describe DBSupplier::Migrator do
|
11
|
+
describe ".client" do
|
12
|
+
context "when access_token is not present" do
|
13
|
+
it { expect { migrate_class.client }.to raise_error(RuntimeError) }
|
14
|
+
end
|
15
|
+
|
16
|
+
context "when access_token is present" do
|
17
|
+
let (:set_access_token) {
|
18
|
+
migrate_class.tap {|s|
|
19
|
+
s.configurations = {
|
20
|
+
access_token: 'access_token',
|
21
|
+
schema_files: { foo: 'bar' }
|
22
|
+
}
|
23
|
+
}
|
24
|
+
}
|
25
|
+
|
26
|
+
it { expect(set_access_token.client).to be_a_kind_of(Octokit::Client) }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe ".databases" do
|
31
|
+
context "when schema_files is not present" do
|
32
|
+
it { expect(migrate_class.databases).to be_empty }
|
33
|
+
end
|
34
|
+
|
35
|
+
context "when schema_files is present" do
|
36
|
+
let (:database_name) { :foo }
|
37
|
+
let (:databases) { { database_name => 'bar' } }
|
38
|
+
let (:set_databases) {
|
39
|
+
migrate_class.tap {|s|
|
40
|
+
s.configurations = {
|
41
|
+
access_token: 'access_token',
|
42
|
+
schema_files: databases
|
43
|
+
}
|
44
|
+
}
|
45
|
+
}
|
46
|
+
|
47
|
+
it { expect(set_databases.databases).to eq [database_name] }
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe ".fetch_sql" do
|
52
|
+
context "when schema_repository is not present" do
|
53
|
+
it { expect { migrate_class.fetch_sql(:db_name) }.to raise_error(RuntimeError) }
|
54
|
+
end
|
55
|
+
|
56
|
+
context "when repository is not present" do
|
57
|
+
let (:set_schema_files) {
|
58
|
+
migrate_class.tap {|s|
|
59
|
+
s.configurations = {
|
60
|
+
access_token: 'access_token',
|
61
|
+
schema_files: { foo: 'bar' }
|
62
|
+
}
|
63
|
+
}
|
64
|
+
}
|
65
|
+
|
66
|
+
it { expect { set_schema_files.fetch_sql(:foo) }.to raise_error(RuntimeError) }
|
67
|
+
end
|
68
|
+
|
69
|
+
context "when schema_repository and repository are present" do
|
70
|
+
let (:db_name) { :foo }
|
71
|
+
let (:set_all_args) {
|
72
|
+
migrate_class.tap {|s|
|
73
|
+
s.configurations = {
|
74
|
+
schema_repository: 'repo_name',
|
75
|
+
access_token: 'access_token',
|
76
|
+
schema_files: { db_name => 'bar' }
|
77
|
+
}
|
78
|
+
}
|
79
|
+
}
|
80
|
+
|
81
|
+
allow_any_instance_of(Octokit::Client).to receive(:contents).and_return('sql')
|
82
|
+
|
83
|
+
it { expect(set_all_args.fetch_sql(db_name)).to eq ['sql'] }
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe ".migrate" do
|
88
|
+
context "when migrator can execute query" do
|
89
|
+
before do
|
90
|
+
@db_name = 'external_db_test.sqlite3'
|
91
|
+
|
92
|
+
ActiveRecord::Base.configurations = {
|
93
|
+
'external_database_test' => {
|
94
|
+
adapter: 'sqlite3',
|
95
|
+
database: @db_name
|
96
|
+
}
|
97
|
+
}
|
98
|
+
|
99
|
+
migrator = migrate_class.tap {|s|
|
100
|
+
s.configurations = {
|
101
|
+
schema_repository: 'repo_name',
|
102
|
+
access_token: 'access_token',
|
103
|
+
schema_files: { external_database_test: 'foo.sql' },
|
104
|
+
logger: Logger.new('/dev/null')
|
105
|
+
}
|
106
|
+
}
|
107
|
+
@table_name = 'foo_table'
|
108
|
+
|
109
|
+
allow(migrator.client).to receive(:contents).and_return(
|
110
|
+
"CREATE TABLE \"#{@table_name}\" (\"id\" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, \"name\" varchar(255) NOT NULL)"
|
111
|
+
)
|
112
|
+
|
113
|
+
migrator.migrate
|
114
|
+
end
|
115
|
+
|
116
|
+
after do
|
117
|
+
FileUtils.rm @db_name
|
118
|
+
end
|
119
|
+
|
120
|
+
it { expect(ActiveRecord::Base.connection.tables).to include(@table_name) }
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'rspec/mocks/standalone'
|
2
|
+
require 'simplecov'
|
3
|
+
require 'tapp'
|
4
|
+
|
5
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
6
|
+
SimpleCov::Formatter::HTMLFormatter
|
7
|
+
]
|
8
|
+
|
9
|
+
SimpleCov.start do
|
10
|
+
add_filter 'spec'
|
11
|
+
end
|
12
|
+
|
13
|
+
RSpec.configure do |config|
|
14
|
+
config.filter_run :focus
|
15
|
+
config.run_all_when_everything_filtered = true
|
16
|
+
|
17
|
+
if config.files_to_run.one?
|
18
|
+
config.full_backtrace = true
|
19
|
+
config.default_formatter = 'doc'
|
20
|
+
end
|
21
|
+
|
22
|
+
config.order = :random
|
23
|
+
Kernel.srand config.seed
|
24
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: db_supplier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ryopeko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-11-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -94,6 +94,62 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rspec-mocks
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: simplecov
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: tapp
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
97
153
|
description:
|
98
154
|
email:
|
99
155
|
- ryopeko@gmail.com
|
@@ -102,6 +158,8 @@ extensions: []
|
|
102
158
|
extra_rdoc_files: []
|
103
159
|
files:
|
104
160
|
- ".gitignore"
|
161
|
+
- ".rspec"
|
162
|
+
- ".travis.yml"
|
105
163
|
- Gemfile
|
106
164
|
- LICENSE.txt
|
107
165
|
- README.md
|
@@ -112,6 +170,8 @@ files:
|
|
112
170
|
- lib/db_supplier/rails/railtie.rb
|
113
171
|
- lib/db_supplier/rails/tasks.rake
|
114
172
|
- sample.rb
|
173
|
+
- spec/migrator_spec.rb
|
174
|
+
- spec/spec_helper.rb
|
115
175
|
homepage: https://github.com/ryopeko/db_supplier
|
116
176
|
licenses:
|
117
177
|
- MIT
|
@@ -136,5 +196,6 @@ rubygems_version: 2.2.2
|
|
136
196
|
signing_key:
|
137
197
|
specification_version: 4
|
138
198
|
summary: Migration tool from external database's DDL
|
139
|
-
test_files:
|
140
|
-
|
199
|
+
test_files:
|
200
|
+
- spec/migrator_spec.rb
|
201
|
+
- spec/spec_helper.rb
|