database_fork 0.0.3 → 0.0.4
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 +4 -4
- data/.rspec +1 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +1 -1
- data/Guardfile +6 -0
- data/Rakefile +6 -1
- data/database_fork.gemspec +12 -9
- data/lib/database_fork.rb +43 -119
- data/lib/database_fork/commands.rb +17 -0
- data/lib/database_fork/db_fork.rb +102 -0
- data/lib/database_fork/load_database_config.rb +13 -0
- data/lib/database_fork/logging.rb +9 -0
- data/lib/database_fork/mysql_connection.rb +26 -0
- data/lib/database_fork/mysql_fork.rb +47 -0
- data/spec/lib/database_fork/mysql_connection_spec.rb +18 -0
- data/spec/lib/database_fork/mysql_fork_spec.rb +59 -0
- data/spec/lib/database_fork_spec.rb +5 -0
- data/spec/spec_helper.rb +28 -0
- metadata +71 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 04574ce63b8ffaee559e658f2dae84d148b7c29e
|
4
|
+
data.tar.gz: db2386f28f81ca972e189c1b9a188dca33f07f08
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f62e70674fd53c2b970e44b6ed59650fd6bf50f59c4518b4e7a1c373cdfaf03a10144549a691bcb96d7d42f1427911100b10aff5ddc9273cb367253aed99dde8
|
7
|
+
data.tar.gz: eae82273430626967731953b465d67a1204a95df624241655e05d431fb145f02d53065109066b89354a0a0e7c255d8770e3db39c029252ae91e25633123afa0f
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
database_fork
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.1.2
|
data/Gemfile
CHANGED
data/Guardfile
ADDED
data/Rakefile
CHANGED
data/database_fork.gemspec
CHANGED
@@ -3,20 +3,23 @@ lib = File.expand_path('../lib', __FILE__)
|
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
|
-
spec.name =
|
7
|
-
spec.version = '0.0.
|
8
|
-
spec.authors = [
|
9
|
-
spec.email = [
|
6
|
+
spec.name = 'database_fork'
|
7
|
+
spec.version = '0.0.4'
|
8
|
+
spec.authors = ['the-architect']
|
9
|
+
spec.email = ['marcel.scherf@epicteams.com']
|
10
10
|
spec.summary = %q{Fork your database}
|
11
11
|
spec.description = %q{Fork your database}
|
12
|
-
spec.homepage =
|
13
|
-
spec.license =
|
12
|
+
spec.homepage = 'http://github.com/'
|
13
|
+
spec.license = 'MIT'
|
14
14
|
|
15
15
|
spec.files = `git ls-files -z`.split("\x0")
|
16
16
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
17
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
-
spec.require_paths = [
|
18
|
+
spec.require_paths = ['lib']
|
19
19
|
|
20
|
-
spec.add_development_dependency
|
21
|
-
spec.add_development_dependency
|
20
|
+
spec.add_development_dependency 'bundler', '~> 1.6'
|
21
|
+
spec.add_development_dependency 'rake'
|
22
|
+
spec.add_development_dependency 'rspec'
|
23
|
+
spec.add_development_dependency 'guard-rspec'
|
24
|
+
spec.add_development_dependency 'ruby_gntp'
|
22
25
|
end
|
data/lib/database_fork.rb
CHANGED
@@ -1,8 +1,16 @@
|
|
1
1
|
require 'yaml'
|
2
|
-
require 'erb'
|
3
2
|
require 'logger'
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
require_relative 'database_fork/logging'
|
6
|
+
require_relative 'database_fork/commands'
|
7
|
+
require_relative 'database_fork/load_database_config'
|
8
|
+
require_relative 'database_fork/mysql_connection'
|
9
|
+
require_relative 'database_fork/mysql_fork'
|
4
10
|
|
5
11
|
class DatabaseFork
|
12
|
+
include Logging
|
13
|
+
include Commands
|
6
14
|
|
7
15
|
class << self
|
8
16
|
# call this at the end of your application.rb file
|
@@ -13,42 +21,50 @@ class DatabaseFork
|
|
13
21
|
ENV[db_fork_var] = open(db_fork_file).read.strip
|
14
22
|
end
|
15
23
|
end
|
24
|
+
|
25
|
+
def reset_all_environments!(root_dir, logger = Logger.new(STDOUT))
|
26
|
+
logger.info 'removing DATABASE_FORK_* files'
|
27
|
+
FileUtils.rm Dir[File.join(root_dir, 'tmp', 'DATABASE_FORK_*')]
|
28
|
+
end
|
29
|
+
|
16
30
|
end
|
17
31
|
|
18
32
|
# use DatabaseFork.new.run in your post-checkout hook
|
19
33
|
def initialize(root_dir, logger = Logger.new(STDOUT))
|
20
|
-
@root_dir
|
21
|
-
@config_file
|
22
|
-
@logger
|
23
|
-
|
34
|
+
@root_dir = root_dir
|
35
|
+
@config_file = File.join(@root_dir, '.db_forks.yml')
|
36
|
+
@logger = logger
|
37
|
+
|
38
|
+
reset_commands!
|
24
39
|
end
|
25
40
|
|
26
|
-
# TODO: simplify this somehow
|
27
41
|
def run
|
28
|
-
if config['
|
29
|
-
log_info 'This branch name is ignored in .db_fork.yml config. Skipping along.'
|
30
|
-
reset_env
|
31
|
-
elsif Regexp.new(config['check_branch_name_regex']).match(current_branch)
|
42
|
+
if Regexp.new(config['check_branch_name_regex']).match(current_branch)
|
32
43
|
log_info 'branch qualified for database forking'
|
33
44
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
45
|
+
config['environments'].each do |env|
|
46
|
+
adapter = MysqlFork.new(@root_dir, app_connection[env], env, current_branch, @logger)
|
47
|
+
|
48
|
+
if adapter.exists?
|
49
|
+
log_info "Database #{adapter.target_name} exists. Skipping."
|
50
|
+
adapter.export_env
|
51
|
+
else
|
52
|
+
case ask_user("Create database: '#{adapter.target_name}'? (y(es), n(no), enter=ignore)")
|
53
|
+
when 'y'
|
54
|
+
adapter.fork
|
55
|
+
adapter.export_env
|
56
|
+
when 'n'
|
57
|
+
adapter.reset_env
|
58
|
+
else
|
59
|
+
config['ignore'] << current_branch
|
60
|
+
adapter.reset_env
|
61
|
+
end
|
48
62
|
end
|
63
|
+
|
49
64
|
end
|
65
|
+
|
50
66
|
else
|
51
|
-
|
67
|
+
self.class.reset_all_environments!(@root_dir)
|
52
68
|
end
|
53
69
|
|
54
70
|
save_config
|
@@ -60,101 +76,9 @@ class DatabaseFork
|
|
60
76
|
IO.new(IO.sysopen('/dev/tty'), 'r').gets.chomp
|
61
77
|
end
|
62
78
|
|
63
|
-
def create_database_fork!
|
64
|
-
config['environments'].each do |env|
|
65
|
-
log_info "creating database fork '#{fork_db_name(env)}' from #{source_db(env)}"
|
66
|
-
|
67
|
-
create_dump(env)
|
68
|
-
create_database(env)
|
69
|
-
import_dump(env)
|
70
|
-
delete_dump_file(env)
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
# TODO: refactor to adapter
|
75
|
-
def create_dump(env = 'development')
|
76
|
-
run_command %Q{mysqldump #{connection_params(env)} --routines --triggers -C #{source_db(env)} > #{dump_file_path(env)}}, "dumping #{source_db(env)}"
|
77
|
-
end
|
78
|
-
|
79
|
-
# TODO: refactor to adapter
|
80
|
-
def create_database(env = 'development')
|
81
|
-
run_command %Q{mysql #{connection_params(env)} -e "CREATE DATABASE IF NOT EXISTS #{fork_db_name(env)} CHARACTER SET '#{character_set}' COLLATE '#{collation}';"}, "create database #{fork_db_name(env)}"
|
82
|
-
end
|
83
|
-
|
84
|
-
# TODO: refactor to adapter
|
85
|
-
def import_dump(env = 'development')
|
86
|
-
run_command %Q{mysql #{connection_params(env)} -C -A -D#{fork_db_name(env)} < #{dump_file_path(env)}}, 'importing dump'
|
87
|
-
end
|
88
|
-
|
89
|
-
def delete_dump_file(env = 'development')
|
90
|
-
run_command "rm #{dump_file_path(env)}", 'cleanup'
|
91
|
-
end
|
92
|
-
|
93
|
-
def reset_env
|
94
|
-
log_info 'Resetting fork information'
|
95
|
-
run_command "rm ./tmp/DATABASE_FORK_DEVELOPMENT", 'rm DATABASE_FORK_DEVELOPMENT'
|
96
|
-
run_command "rm ./tmp/DATABASE_FORK_TEST", 'rm DATABASE_FORK_TEST'
|
97
|
-
end
|
98
|
-
|
99
|
-
def export_env
|
100
|
-
run_command "echo #{fork_db_name('development')} > ./tmp/DATABASE_FORK_DEVELOPMENT", 'setting DATABASE_FORK_DEVELOPMENT'
|
101
|
-
run_command "echo #{fork_db_name('test')} > ./tmp/DATABASE_FORK_TEST", 'setting DATABASE_FORK_TEST'
|
102
|
-
end
|
103
|
-
|
104
|
-
def run_command(command, message, dry_run = false)
|
105
|
-
log_info message
|
106
|
-
log_debug command
|
107
|
-
@commands << [command, message]
|
108
|
-
`#{command}` unless dry_run
|
109
|
-
end
|
110
|
-
|
111
|
-
def dump_file_path(env = 'development')
|
112
|
-
File.join(@root_dir, 'tmp', "dump_#{env}.sql")
|
113
|
-
end
|
114
|
-
|
115
|
-
# could be queried from source_db:
|
116
|
-
def character_set
|
117
|
-
config['character_set'] || 'utf8'
|
118
|
-
end
|
119
|
-
|
120
|
-
# could be queried from source_db:
|
121
|
-
def collation
|
122
|
-
config['collation'] || 'utf8_unicode_ci'
|
123
|
-
end
|
124
|
-
|
125
|
-
def log_info(message)
|
126
|
-
@logger.info message
|
127
|
-
end
|
128
|
-
|
129
|
-
def log_debug(message)
|
130
|
-
@logger.debug message
|
131
|
-
end
|
132
|
-
|
133
|
-
def fork_exists?(env = 'development')
|
134
|
-
command = %Q{mysql #{connection_params[env]} -s -N -e "SHOW DATABASES LIKE '#{fork_db_name(env)}';" }
|
135
|
-
!`#{command}`.empty?
|
136
|
-
end
|
137
|
-
|
138
|
-
# simplify
|
139
|
-
# make framework agnostic
|
140
|
-
def connection_params(env = 'development')
|
141
|
-
@connection_params ||= if ENV['USER'] == 'vagrant'
|
142
|
-
%Q{--user=#{app_connection[env]['username']} --password=#{app_connection[env]['password']} --socket=#{app_connection[env]['socket']}}
|
143
|
-
else
|
144
|
-
%Q{--user=#{app_connection[env]['username']} --password=#{app_connection[env]['password']} --host=#{app_connection[env]['host']} --port=#{app_connection[env]['port']}}
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
def fork_db_name(env = 'development')
|
149
|
-
"#{source_db(env)}_#{current_branch}".strip
|
150
|
-
end
|
151
|
-
|
152
|
-
def source_db(env= 'development')
|
153
|
-
app_connection[env]['database']
|
154
|
-
end
|
155
|
-
|
156
79
|
def app_connection
|
157
|
-
@
|
80
|
+
@database_config ||= LoadDatabaseConfig.new(@root_dir)
|
81
|
+
@database_config.config
|
158
82
|
end
|
159
83
|
|
160
84
|
def current_branch
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Commands
|
2
|
+
def record_command(command, message)
|
3
|
+
@commands << [command, message]
|
4
|
+
end
|
5
|
+
|
6
|
+
def execute_commands
|
7
|
+
@commands.each do |command, message|
|
8
|
+
log_info message
|
9
|
+
log_debug command
|
10
|
+
`#{command}`
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def reset_commands!
|
15
|
+
@commands = []
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
require_relative 'logging'
|
2
|
+
require_relative 'commands'
|
3
|
+
|
4
|
+
class DBFork
|
5
|
+
include Logging
|
6
|
+
include Commands
|
7
|
+
|
8
|
+
# implement this is your adapter:
|
9
|
+
def exists?(dry_run = false)
|
10
|
+
raise NotImplementedError
|
11
|
+
end
|
12
|
+
|
13
|
+
# implement this is your adapter:
|
14
|
+
def connection_parameters
|
15
|
+
raise NotImplementedError
|
16
|
+
end
|
17
|
+
|
18
|
+
def create_dump
|
19
|
+
raise NotImplementedError
|
20
|
+
end
|
21
|
+
|
22
|
+
def create_database
|
23
|
+
raise NotImplementedError
|
24
|
+
end
|
25
|
+
|
26
|
+
def import_dump
|
27
|
+
raise NotImplementedError
|
28
|
+
end
|
29
|
+
|
30
|
+
def query_default_settings(dry_run = false)
|
31
|
+
raise NotImplementedError
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
def initialize(root_dir, connection, env, branch_name, logger)
|
36
|
+
@root_dir = root_dir
|
37
|
+
@connection = connection
|
38
|
+
@env = env
|
39
|
+
@branch_name = branch_name
|
40
|
+
@logger = logger
|
41
|
+
|
42
|
+
@character_set = nil
|
43
|
+
@collation = nil
|
44
|
+
|
45
|
+
reset_commands!
|
46
|
+
end
|
47
|
+
|
48
|
+
attr_accessor :commands
|
49
|
+
|
50
|
+
def fork(dry_run = false)
|
51
|
+
reset_commands!
|
52
|
+
|
53
|
+
log_info "creating database fork '#{target_name}' from #{source_db}"
|
54
|
+
|
55
|
+
create_dump
|
56
|
+
create_database
|
57
|
+
import_dump
|
58
|
+
delete_dump_file
|
59
|
+
|
60
|
+
execute_commands unless dry_run
|
61
|
+
end
|
62
|
+
|
63
|
+
def target_name
|
64
|
+
"#{source_db}_#{@branch_name}"
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
def source_db
|
69
|
+
@connection['database']
|
70
|
+
end
|
71
|
+
|
72
|
+
def reset_env(dry_run = false)
|
73
|
+
reset_commands!
|
74
|
+
filename = File.join(@root_dir, 'tmp', "DATABASE_FORK_#{@env.upcase}")
|
75
|
+
record_command "rm #{filename}", "removing DATABASE_FORK_#{@env.upcase}"
|
76
|
+
execute_commands unless dry_run
|
77
|
+
end
|
78
|
+
|
79
|
+
def export_env(dry_run = false)
|
80
|
+
reset_commands!
|
81
|
+
filename = File.join(@root_dir, 'tmp', "DATABASE_FORK_#{@env.upcase}")
|
82
|
+
record_command "echo #{target_name} > #{filename}", "setting DATABASE_FORK_#{@env.upcase}"
|
83
|
+
execute_commands unless dry_run
|
84
|
+
end
|
85
|
+
|
86
|
+
def delete_dump_file
|
87
|
+
record_command "rm #{dump_file}", 'cleanup'
|
88
|
+
end
|
89
|
+
|
90
|
+
def character_set
|
91
|
+
@character_set || 'utf8'
|
92
|
+
end
|
93
|
+
|
94
|
+
def collation
|
95
|
+
@collation || 'utf8_unicode_ci'
|
96
|
+
end
|
97
|
+
|
98
|
+
def dump_file
|
99
|
+
File.join(@root_dir, 'tmp', "dump_#{source_db}.sql")
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'erb'
|
2
|
+
|
3
|
+
# this is very Rails specific
|
4
|
+
# TODO: make this work with other frameworks too :)
|
5
|
+
class LoadDatabaseConfig
|
6
|
+
def initialize(root_dir)
|
7
|
+
@root_dir = root_dir
|
8
|
+
end
|
9
|
+
|
10
|
+
def config
|
11
|
+
@config ||= YAML.load(ERB.new(open(File.join(@root_dir, 'config', 'database.yml')).read).result)
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class MysqlConnection
|
2
|
+
def initialize(config)
|
3
|
+
@config = config
|
4
|
+
end
|
5
|
+
|
6
|
+
def params
|
7
|
+
key_mapping = {
|
8
|
+
'username' => 'user',
|
9
|
+
'password' => 'password',
|
10
|
+
'socket' => 'socket',
|
11
|
+
'host' => 'host',
|
12
|
+
'port' => 'port'
|
13
|
+
}
|
14
|
+
|
15
|
+
@config.inject(Hash.new) do |akk, tupel|
|
16
|
+
key, value = *tupel
|
17
|
+
|
18
|
+
akk[key_mapping[key.to_s]] = value if key_mapping.key?(key.to_s)
|
19
|
+
akk
|
20
|
+
end.map do |tupel|
|
21
|
+
key, value = *tupel
|
22
|
+
|
23
|
+
"--#{key}=#{value}"
|
24
|
+
end.sort.join(' ')
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require_relative 'db_fork'
|
2
|
+
require_relative 'mysql_connection'
|
3
|
+
|
4
|
+
class MysqlFork < DBFork
|
5
|
+
|
6
|
+
def exists?(dry_run = false)
|
7
|
+
command = %Q{mysql #{connection_parameters} -s -N -e "SHOW DATABASES LIKE '#{target_name}';" }
|
8
|
+
if dry_run
|
9
|
+
reset_commands!
|
10
|
+
record_command command, 'query default character set and collation'
|
11
|
+
else
|
12
|
+
!`#{command}`.empty?
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def connection_parameters
|
17
|
+
@connection_parameters ||= MysqlConnection.new(@connection).params
|
18
|
+
end
|
19
|
+
|
20
|
+
def create_dump
|
21
|
+
record_command %Q{mysqldump #{connection_parameters} --routines --triggers -C #{source_db} > #{dump_file}}, "dumping #{source_db}"
|
22
|
+
end
|
23
|
+
|
24
|
+
def source_db
|
25
|
+
@connection['database']
|
26
|
+
end
|
27
|
+
|
28
|
+
def create_database
|
29
|
+
record_command %Q{mysql #{connection_parameters} -e "CREATE DATABASE IF NOT EXISTS #{target_name} CHARACTER SET '#{character_set}' COLLATE '#{collation}';"}, "create database #{@fork_db_name}"
|
30
|
+
end
|
31
|
+
|
32
|
+
def import_dump
|
33
|
+
record_command %Q{mysql #{connection_parameters} -C -A -D#{target_name} < #{dump_file}}, 'importing dump'
|
34
|
+
end
|
35
|
+
|
36
|
+
def query_default_settings(dry_run = false)
|
37
|
+
command = %Q{mysql #{connection_parameters} -s -N -e "SELECT DEFAULT_CHARACTER_SET_NAME, DEFAULT_COLLATION_NAME FROM information_schema.SCHEMATA S WHERE schema_name = 'papersmart_dev';"}
|
38
|
+
if dry_run
|
39
|
+
reset_commands!
|
40
|
+
record_command command, 'query default character set and collation'
|
41
|
+
else
|
42
|
+
@character_set, @collation = *(`#{command}`.("\t"))
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
require_relative '../../../lib/database_fork/mysql_connection'
|
3
|
+
|
4
|
+
describe MysqlConnection do
|
5
|
+
|
6
|
+
let(:connection) { {
|
7
|
+
'host' => '127.0.0.1',
|
8
|
+
'port' => '3306',
|
9
|
+
'username' => 'root',
|
10
|
+
'password' => '',
|
11
|
+
'database' => 'myapp_development'
|
12
|
+
} }
|
13
|
+
|
14
|
+
subject{ MysqlConnection.new(connection) }
|
15
|
+
|
16
|
+
it { expect(subject.params).to eql '--host=127.0.0.1 --password= --port=3306 --user=root' }
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
require_relative '../../../lib/database_fork/mysql_fork'
|
3
|
+
|
4
|
+
describe MysqlFork do
|
5
|
+
|
6
|
+
let(:connection) { {
|
7
|
+
'host' => '127.0.0.1',
|
8
|
+
'port' => '3306',
|
9
|
+
'username' => 'root',
|
10
|
+
'password' => '',
|
11
|
+
'database' => 'myapp_development'
|
12
|
+
} }
|
13
|
+
|
14
|
+
let(:branch_name){ 'feature_branch' }
|
15
|
+
let(:env){ 'development' }
|
16
|
+
|
17
|
+
it 'loads correctly' do
|
18
|
+
MysqlFork.new(tmp_path, connection, env, branch_name, Logger.new(StringIO.new))
|
19
|
+
end
|
20
|
+
|
21
|
+
describe 'with connection configuration' do
|
22
|
+
let(:dev){ }
|
23
|
+
|
24
|
+
subject{ MysqlFork.new(tmp_path, connection, env, branch_name, Logger.new(StringIO.new))}
|
25
|
+
|
26
|
+
it{ expect(subject.target_name).to eql 'myapp_development_feature_branch' }
|
27
|
+
|
28
|
+
it 'fork commands' do
|
29
|
+
subject.fork(true)
|
30
|
+
expect(subject.commands).to_not be_empty
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'dump_file' do
|
34
|
+
expect(subject.dump_file).to match(%r{tmp/dump_myapp_development.sql$}i)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'create_dump' do
|
38
|
+
subject.create_dump
|
39
|
+
commands = subject.commands
|
40
|
+
expect(commands.size).to eql 1
|
41
|
+
expect(commands[0][0]).to match(%r{--routines --triggers -C #{connection['database']} >})
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'create_database' do
|
45
|
+
subject.create_database
|
46
|
+
commands = subject.commands
|
47
|
+
expect(commands.size).to eql 1
|
48
|
+
expect(commands[0][0]).to match(%r{-e "CREATE DATABASE IF NOT EXISTS #{connection['database']}_#{branch_name} CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci';"})
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'source_db' do
|
52
|
+
expect(subject.source_db).to eql connection['database']
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
require 'logger'
|
4
|
+
require 'fileutils'
|
5
|
+
require 'stringio'
|
6
|
+
|
7
|
+
def tmp_path
|
8
|
+
$tmp_path ||= File.join(File.dirname(__FILE__), 'tmp')
|
9
|
+
end
|
10
|
+
|
11
|
+
def clean_tmp
|
12
|
+
FileUtils.mkdir_p(tmp_path) # just in case it does not exist
|
13
|
+
FileUtils.rm_r tmp_path
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
RSpec.configure do |c|
|
18
|
+
c.mock_with :rspec
|
19
|
+
|
20
|
+
c.treat_symbols_as_metadata_keys_with_true_values = true
|
21
|
+
c.filter_run :focus => true
|
22
|
+
c.run_all_when_everything_filtered = true
|
23
|
+
|
24
|
+
c.before do
|
25
|
+
clean_tmp
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
metadata
CHANGED
@@ -1,41 +1,83 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: database_fork
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- the-architect
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.6'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.6'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: guard-rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: ruby_gntp
|
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
|
+
- - ">="
|
39
81
|
- !ruby/object:Gem::Version
|
40
82
|
version: '0'
|
41
83
|
description: Fork your database
|
@@ -45,13 +87,27 @@ executables: []
|
|
45
87
|
extensions: []
|
46
88
|
extra_rdoc_files: []
|
47
89
|
files:
|
48
|
-
- .gitignore
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- ".ruby-gemset"
|
93
|
+
- ".ruby-version"
|
49
94
|
- Gemfile
|
95
|
+
- Guardfile
|
50
96
|
- LICENSE.txt
|
51
97
|
- README.md
|
52
98
|
- Rakefile
|
53
99
|
- database_fork.gemspec
|
54
100
|
- lib/database_fork.rb
|
101
|
+
- lib/database_fork/commands.rb
|
102
|
+
- lib/database_fork/db_fork.rb
|
103
|
+
- lib/database_fork/load_database_config.rb
|
104
|
+
- lib/database_fork/logging.rb
|
105
|
+
- lib/database_fork/mysql_connection.rb
|
106
|
+
- lib/database_fork/mysql_fork.rb
|
107
|
+
- spec/lib/database_fork/mysql_connection_spec.rb
|
108
|
+
- spec/lib/database_fork/mysql_fork_spec.rb
|
109
|
+
- spec/lib/database_fork_spec.rb
|
110
|
+
- spec/spec_helper.rb
|
55
111
|
homepage: http://github.com/
|
56
112
|
licenses:
|
57
113
|
- MIT
|
@@ -62,18 +118,22 @@ require_paths:
|
|
62
118
|
- lib
|
63
119
|
required_ruby_version: !ruby/object:Gem::Requirement
|
64
120
|
requirements:
|
65
|
-
- -
|
121
|
+
- - ">="
|
66
122
|
- !ruby/object:Gem::Version
|
67
123
|
version: '0'
|
68
124
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
125
|
requirements:
|
70
|
-
- -
|
126
|
+
- - ">="
|
71
127
|
- !ruby/object:Gem::Version
|
72
128
|
version: '0'
|
73
129
|
requirements: []
|
74
130
|
rubyforge_project:
|
75
|
-
rubygems_version: 2.
|
131
|
+
rubygems_version: 2.3.0
|
76
132
|
signing_key:
|
77
133
|
specification_version: 4
|
78
134
|
summary: Fork your database
|
79
|
-
test_files:
|
135
|
+
test_files:
|
136
|
+
- spec/lib/database_fork/mysql_connection_spec.rb
|
137
|
+
- spec/lib/database_fork/mysql_fork_spec.rb
|
138
|
+
- spec/lib/database_fork_spec.rb
|
139
|
+
- spec/spec_helper.rb
|