fluent-migrator-command-runner 0.0.5 → 0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ OGRkZWNiZDk2YjAwYjhjZWJkMzBmODE4NTMxZGVjOGI1MzUyNmExMA==
5
+ data.tar.gz: !binary |-
6
+ ODhjODg1NzhiMzc4MDg5MDAyYTVhNmZhNWQyYTAwNWJlYWFlNTI5OA==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ MzU0MmFiYzdmYjMxYmQxYThlOWQ3ZDFkNjIzMzlmOWY1YTU0YzNiYWYwYTY3
10
+ YWM0NzMyYzcyNmRmZmIyYTIwOWM0MzZjOWEyZDRmNzNkMGQwZTdiYzI3ZDg1
11
+ Zjk3MDk5NDJmNzc1MGExNGQ2NTVjNDY0NjJjZDJmMTZlZWIyZDE=
12
+ data.tar.gz: !binary |-
13
+ ZmM3OTZlNGIwMDE3ZmQwMTg1NTFkM2Y5N2ZkOGVhZjQyODhlMWZhNTAyMzIw
14
+ NjYwOGIxZTNjNGQ0NzdiNGJkNDc0ZTBjZmRlM2Y2ZTIwZDQyYmZkZDdiN2E1
15
+ MmYzMDM5OTUwMmVhM2FkZTRhNDdhMDU5Y2NlNWM4YTNmZTFkNDQ=
@@ -0,0 +1,2 @@
1
+ .idea
2
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'rake'
4
+ gem 'rspec'
5
+ gem 'rspec-mocks'
6
+
7
+ gemspec
@@ -0,0 +1,29 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.2.5)
5
+ fig_newton (0.10)
6
+ yml_reader (>= 0.3)
7
+ rake (10.3.2)
8
+ rspec (3.1.0)
9
+ rspec-core (~> 3.1.0)
10
+ rspec-expectations (~> 3.1.0)
11
+ rspec-mocks (~> 3.1.0)
12
+ rspec-core (3.1.4)
13
+ rspec-support (~> 3.1.0)
14
+ rspec-expectations (3.1.1)
15
+ diff-lcs (>= 1.2.0, < 2.0)
16
+ rspec-support (~> 3.1.0)
17
+ rspec-mocks (3.1.1)
18
+ rspec-support (~> 3.1.0)
19
+ rspec-support (3.1.0)
20
+ yml_reader (0.4)
21
+
22
+ PLATFORMS
23
+ x86-mingw32
24
+
25
+ DEPENDENCIES
26
+ fig_newton
27
+ rake
28
+ rspec
29
+ rspec-mocks
@@ -0,0 +1,49 @@
1
+ #Fluent-Migrator-Command-Runner
2
+
3
+ Build and run fluent migrator commands from ruby with ease.
4
+
5
+ #Installation
6
+
7
+ gem install fluent-migrator-command-runner
8
+
9
+ #Setup
10
+
11
+ FigNewton file (ex. local.yml) should be loaded before use.
12
+ [FigNewton will automatically load file if ENV['FIG_NEWTOW_FILE'] is set]
13
+
14
+ The FigNewton file should have atleast the following nodes.
15
+
16
+ ````
17
+ path_to_migration_assembly: ../Path/To/Migrations.dll
18
+ path_to_migrator_exe: ../Path/to/migrate.exe
19
+
20
+ database:
21
+ adapter: oracle_enhanced
22
+ database: "TNS.world"
23
+ username: "SCHEMA_USER_NAME"
24
+ password: "p4ssw0rd"
25
+ ````
26
+
27
+ #Using exposed rake task
28
+
29
+ Migrate with no tags or profiles
30
+
31
+ ````ruby
32
+ FluentMigratorCommandRunner::Rake::Task.new(:migrate)
33
+ ````
34
+
35
+ Migrate with profile, tag, and select a fig newton file
36
+
37
+ ````ruby
38
+ FluentMigratorCommandRunner::Rake::Task.new(:migrate) do |t|
39
+ t.fig_newton_file = 'local.yml'
40
+ t.profile = 'TestData'
41
+ t.tag = 'Tag'
42
+ end
43
+ ````
44
+
45
+ #Future Enhancements
46
+ - be able to run with multiple tags
47
+
48
+ #Notes
49
+ Has only been tested with FluentMigrator.Tools.1.1.2.1
@@ -0,0 +1,8 @@
1
+ require 'rspec/core/rake_task'
2
+ require "bundler/gem_tasks"
3
+
4
+ RSpec::Core::RakeTask.new(:spec) do |spec|
5
+ spec.pattern = ['spec/**/*_spec.rb']
6
+ end
7
+
8
+ task :spec
@@ -0,0 +1,18 @@
1
+ require File.expand_path('../lib/fluent-migrator-command-runner/version', __FILE__)
2
+
3
+ Gem::Specification.new do |gem|
4
+ gem.name = 'fluent-migrator-command-runner'
5
+ gem.date = '2014-11-11'
6
+ gem.description = "Build and Execute Fluent Migrator Commands"
7
+ gem.authors = ["Mosaic"]
8
+ gem.email = 'mosaic.development@sherwin.com'
9
+ gem.homepage = 'Internal @ SherwinWilliams'
10
+ gem.summary = "Rake Tasks For Fluent Migrator"
11
+ gem.files = `git ls-files`.split("\n")
12
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
13
+ gem.require_paths = ['lib']
14
+ gem.version = FluentMigratorCommandRunner::VERSION
15
+ gem.homepage = ''
16
+ gem.license = 'MIT'
17
+ gem.add_dependency 'fig_newton'
18
+ end
@@ -1,8 +1,8 @@
1
+ require 'fluent-migrator-command-runner/version'
1
2
  require 'fluent-migrator-command-runner/runner'
2
3
  require 'fluent-migrator-command-runner/command_builder'
3
4
  require 'fluent-migrator-command-runner/oracle_migration_command'
4
5
  require 'fluent-migrator-command-runner/task'
5
-
6
6
  require 'fig_newton'
7
7
 
8
8
  module FluentMigratorCommandRunner
@@ -1,15 +1,23 @@
1
1
  module FluentMigratorCommandRunner
2
2
  class OracleMigrationCommand
3
- attr_accessor :path_to_migrator,
4
- :path_to_migration_assembly,
3
+ attr_reader :path_to_migrator,
4
+ :path_to_migration_assembly,
5
5
  :connection_information,
6
6
  :profile,
7
- :tag
7
+ :tag,
8
+ :provider
9
+
10
+ PARAMETER_PREFIX = '--'
11
+ SPACE_CHAR = "\s"
12
+
13
+ MIGRATOR_DELIMITER = "#{SPACE_CHAR + PARAMETER_PREFIX}"
14
+ CONNECTION_STRING_DELIMITER = ';'
8
15
 
9
16
  def initialize(options = {})
10
17
  @profile = options[:profile] unless options[:profile].nil?
11
18
  @tag = options[:tag] unless options[:tag].nil?
12
- @path_to_migrator = FigNewton.path_to_migrator_exe
19
+ @provider = FigNewton.migration_provider('oracle')
20
+ @path_to_migrator = FigNewton.path_to_migrator_exe
13
21
  @path_to_migration_assembly = FigNewton.path_to_migration_assembly
14
22
  @connection_information = FigNewton.database.to_hash
15
23
  @connection_information['password'] = options[:db_password] unless options[:db_password].nil?
@@ -20,22 +28,23 @@ module FluentMigratorCommandRunner
20
28
 
21
29
  command_sections = []
22
30
  command_sections.push(@path_to_migrator)
23
- command_sections.push("--conn \"#{connection_string}\"")
24
- command_sections.push("/provider oracle --assembly \"#{@path_to_migration_assembly}\"")
25
- command_sections.push("/task migrate")
26
- command_sections.push("--tag #{@tag}") if @tag
27
- command_sections.push("--profile=#{@profile}") if @profile
28
- command_sections.join(' ')
31
+ command_sections.push("provider #{@provider}")
32
+ command_sections.push("conn \"#{connection_string}\"")
33
+ command_sections.push('task migrate')
34
+ command_sections.push("assembly \"#{@path_to_migration_assembly}\"")
35
+ command_sections.push("tag #{@tag}") if @tag
36
+ command_sections.push("profile=#{@profile}") if @profile
37
+ command_sections.join(MIGRATOR_DELIMITER)
29
38
  end
30
39
 
31
40
  private
32
41
 
33
42
  def build_connection_string(connection_information)
34
43
  connection = []
35
- connection.push("DATA SOURCE=#{connection_information['database']};")
36
- connection.push("user id=#{connection_information['username']};")
44
+ connection.push("DATA SOURCE=#{connection_information['database']}")
45
+ connection.push("user id=#{connection_information['username']}")
37
46
  connection.push("password=#{connection_information['password']}")
38
- return connection.join('')
47
+ connection.join(CONNECTION_STRING_DELIMITER)
39
48
  end
40
49
 
41
50
  end
@@ -0,0 +1,3 @@
1
+ module FluentMigratorCommandRunner
2
+ VERSION = "0.6"
3
+ end
@@ -0,0 +1,31 @@
1
+
2
+ require 'spec_helper'
3
+
4
+ describe FluentMigratorCommandRunner::CommandBuilder do
5
+
6
+ let(:builder){FluentMigratorCommandRunner::CommandBuilder}
7
+ let(:oracle_command){FluentMigratorCommandRunner::OracleMigrationCommand}
8
+ let(:command_stub){double(FluentMigratorCommandRunner::OracleMigrationCommand)}
9
+
10
+ before { allow(oracle_command).to receive(:new).and_return(command_stub)}
11
+ before { allow(command_stub).to receive(:build)}
12
+
13
+ it 'should create new oracle migration command with options' do
14
+ expected_options = {}
15
+ builder.build(expected_options)
16
+ expect(oracle_command).to have_received(:new).with(expected_options)
17
+ end
18
+
19
+ it 'should build oracle migration command ' do
20
+ builder.build
21
+ expect(command_stub).to have_received(:build)
22
+ end
23
+
24
+ it 'should return built oracle migration command ' do
25
+ expected_command = "command string"
26
+ allow(command_stub).to receive(:build).and_return(expected_command)
27
+ actual = builder.build
28
+ expect(actual).to be(expected_command)
29
+ end
30
+
31
+ end
@@ -0,0 +1,116 @@
1
+ require 'spec_helper'
2
+ require 'socket'
3
+
4
+ describe FluentMigratorCommandRunner::OracleMigrationCommand do
5
+
6
+ before do
7
+ @connection_information = {
8
+ 'database' => '',
9
+ 'username' => '',
10
+ 'password' => ''
11
+ }
12
+ allow(FigNewton).to receive(:database).and_return(@connection_information)
13
+ allow(FigNewton).to receive(:path_to_migration_assembly)
14
+ allow(FigNewton).to receive(:path_to_migrator_exe)
15
+ allow(FigNewton).to receive(:migration_provider)
16
+ end
17
+
18
+ describe 'initialize' do
19
+
20
+ it "should include profile when provided" do
21
+ expected_profile = "--profile=TestData"
22
+ command = FluentMigratorCommandRunner::OracleMigrationCommand.new({:profile => 'TestData'}).build
23
+ expect(command).to include(expected_profile)
24
+ end
25
+
26
+ it "should not include profile when not provided" do
27
+ command = FluentMigratorCommandRunner::OracleMigrationCommand.new.build
28
+ expect(command).to_not include('--profile')
29
+ end
30
+
31
+ it "should include tag when provided" do
32
+ expected_tag = "--tag Data"
33
+ command = FluentMigratorCommandRunner::OracleMigrationCommand.new({:tag => 'Data'}).build
34
+ expect(command).to include(expected_tag)
35
+ end
36
+
37
+ it "should not include tag when not provided" do
38
+ command = FluentMigratorCommandRunner::OracleMigrationCommand.new.build
39
+ expect(command).to_not include('--tag')
40
+ end
41
+
42
+ it 'should override password' do
43
+ expected_password = 'my_new_password'
44
+ command = FluentMigratorCommandRunner::OracleMigrationCommand.new({:db_password => expected_password}).build
45
+ expect(command).to include(expected_password)
46
+ end
47
+
48
+ it "should allow overriding of default provider" do
49
+ expected_provider = 'mynewprovider'
50
+ allow(FigNewton).to receive(:migration_provider).and_return(expected_provider)
51
+ command = FluentMigratorCommandRunner::OracleMigrationCommand.new.build
52
+ expect(command).to include("--provider #{expected_provider}")
53
+ end
54
+ end
55
+
56
+ describe "build" do
57
+ let(:oracle_command) { FluentMigratorCommandRunner::OracleMigrationCommand.new }
58
+
59
+ it "should include path to migrator" do
60
+ expected = "/My/Path/To/Migrator"
61
+ allow(FigNewton).to receive(:path_to_migrator_exe).and_return(expected)
62
+
63
+ command = oracle_command.build
64
+ expect(command).to include(expected)
65
+ end
66
+
67
+ it "should include default provider" do
68
+ oracle_command.build
69
+ expect(FigNewton).to have_received(:migration_provider).with('oracle')
70
+ end
71
+
72
+ it "should include path to assembly" do
73
+ expected = "--assembly \"/My/Path/To/Assembly\""
74
+ allow(FigNewton).to receive(:path_to_migration_assembly).and_return('/My/Path/To/Assembly')
75
+
76
+ command = oracle_command.build
77
+ expect(command).to include(expected)
78
+ end
79
+
80
+ it "should include task" do
81
+ expected_task = "--task migrate"
82
+ command = oracle_command.build
83
+ expect(command).to include(expected_task)
84
+ end
85
+
86
+ it "should include connection string" do
87
+ command = oracle_command.build()
88
+ expect(command).to include('--conn ')
89
+ end
90
+
91
+ describe "database connection string" do
92
+
93
+ it "should include DATA SOURCE in connection string" do
94
+ expected = 'MYDATA.world'
95
+ @connection_information['database'] = expected
96
+ command = oracle_command.build
97
+ expect(command).to include "DATA SOURCE=#{expected}"
98
+ end
99
+
100
+ it "should include user name in connection string" do
101
+ expected = 'user'
102
+ @connection_information['username'] = expected
103
+ command = oracle_command.build
104
+ expect(command).to include "user id=#{expected}"
105
+ end
106
+
107
+ it "should include password in connection string" do
108
+ expected = 'MyPassword'
109
+ @connection_information['password'] = expected
110
+ command = oracle_command.build
111
+ expect(command).to include "password=#{expected}"
112
+ end
113
+ end
114
+
115
+ end
116
+ end
@@ -0,0 +1,117 @@
1
+ require 'spec_helper'
2
+
3
+ describe FluentMigratorCommandRunner::Rake::Task do
4
+
5
+ after{ Rake.application.clear}
6
+
7
+ context 'defining task' do
8
+ it 'should define rake task named' do
9
+ expected_task_name = 'my_rake_task'
10
+ FluentMigratorCommandRunner::Rake::Task.new(expected_task_name)
11
+ expect(::Rake::Task[expected_task_name]).to_not equal(nil)
12
+ end
13
+ end
14
+
15
+ context 'invoking task' do
16
+ let(:builder){FluentMigratorCommandRunner::CommandBuilder}
17
+ let(:runner){FluentMigratorCommandRunner::Runner}
18
+ before { allow(builder).to receive(:build)}
19
+ before { allow(runner).to receive(:execute)}
20
+ before { allow(FigNewton).to receive(:load)}
21
+ let(:default_task_name){'my_rake_task'}
22
+
23
+
24
+ it 'should migrate the database' do
25
+ FluentMigratorCommandRunner::Rake::Task.new(default_task_name)
26
+ invoke_rake_task
27
+
28
+ expect(builder).to have_received(:build)
29
+ end
30
+
31
+ it 'should execute command' do
32
+ command = "BuildCommmand"
33
+ allow(builder).to receive(:build).and_return(command)
34
+ FluentMigratorCommandRunner::Rake::Task.new(default_task_name)
35
+ invoke_rake_task
36
+
37
+ expect(runner).to have_received(:execute).with(command)
38
+ end
39
+
40
+ it 'should accept profile option' do
41
+ expected_profile = 'my_profile'
42
+ FluentMigratorCommandRunner::Rake::Task.new(default_task_name) do |task|
43
+ task.profile = expected_profile
44
+ end
45
+ invoke_rake_task
46
+
47
+ expect(builder).to have_received(:build).with(hash_including(:profile => expected_profile))
48
+ end
49
+
50
+ it 'should not pass profile option when nil' do
51
+ FluentMigratorCommandRunner::Rake::Task.new(default_task_name)
52
+ invoke_rake_task
53
+
54
+ expect(builder).to_not have_received(:build).with(hash_including(:profile => nil))
55
+ end
56
+
57
+ it 'should accept tag option' do
58
+ expected_tag = 'tag'
59
+ FluentMigratorCommandRunner::Rake::Task.new(default_task_name) do |task|
60
+ task.tag = expected_tag
61
+ end
62
+ invoke_rake_task
63
+
64
+ expect(builder).to have_received(:build).with(hash_including(:tag => expected_tag))
65
+ end
66
+
67
+ it 'should not pass tag option when nil' do
68
+ FluentMigratorCommandRunner::Rake::Task.new(default_task_name)
69
+ invoke_rake_task
70
+
71
+ expect(builder).to_not have_received(:build).with(hash_including(:tag => nil))
72
+ end
73
+
74
+ it 'should accept password argument' do
75
+ expected_password = 'my_password'
76
+ FluentMigratorCommandRunner::Rake::Task.new(default_task_name)
77
+ invoke_rake_task_with_password(expected_password)
78
+
79
+ expect(builder).to have_received(:build).with(hash_including(:db_password => expected_password))
80
+ end
81
+
82
+ it 'should not pass password option when rake is invoked with out password' do
83
+ FluentMigratorCommandRunner::Rake::Task.new(default_task_name)
84
+ invoke_rake_task
85
+
86
+ expect(builder).to_not have_received(:build).with(hash_including(:db_password => nil))
87
+ end
88
+
89
+ it 'should load the fig newton file when option given' do
90
+ FluentMigratorCommandRunner::Rake::Task.new(default_task_name) do |task|
91
+ task.fig_newton_file ='fignewton.yml'
92
+ end
93
+
94
+ invoke_rake_task
95
+ expect(FigNewton).to have_received(:load).with("fignewton.yml")
96
+ end
97
+
98
+ it 'should not load fignewton file' do
99
+ FluentMigratorCommandRunner::Rake::Task.new(default_task_name)
100
+
101
+ invoke_rake_task
102
+ expect(FigNewton).to_not have_received(:load)
103
+ end
104
+
105
+ end
106
+
107
+ private
108
+
109
+ def invoke_rake_task
110
+ ::Rake::Task[default_task_name].invoke
111
+ end
112
+
113
+
114
+ def invoke_rake_task_with_password(password)
115
+ ::Rake::Task[default_task_name].invoke(password)
116
+ end
117
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe FluentMigratorCommandRunner::CommandBuilder do
4
+
5
+ let(:runner){FluentMigratorCommandRunner::Runner}
6
+ let(:kernel){Kernel}
7
+ let(:system_error){$?}
8
+
9
+ before { allow(kernel).to receive(:system).and_return(true)}
10
+
11
+ it "should execute command" do
12
+ allow(system_error).to receive(:exitstatus).and_return(0)
13
+ expected_command = "echo Bravo"
14
+ runner.execute(expected_command)
15
+ expect(kernel).to have_received(:system).with(expected_command)
16
+ end
17
+
18
+ context 'fluent migrator failure' do
19
+ it "should raise exception " do
20
+ allow(kernel).to receive(:system)
21
+ allow(system_error).to receive(:exitstatus).and_return(1)
22
+
23
+ expect{runner.execute('')}.to raise_error()
24
+ end
25
+
26
+ it "should raise exception when command is invalid" do
27
+ allow(kernel).to receive(:system)
28
+ allow(system_error).to receive(:exitstatus).and_return(127)
29
+ expect{runner.execute('')}.to raise_error()
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,7 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+
4
+ require 'rspec/mocks'
5
+ require 'rspec'
6
+ require 'fluent-migrator-command-runner'
7
+ require 'rake'
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-migrator-command-runner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
5
- prerelease:
4
+ version: '0.6'
6
5
  platform: ruby
7
6
  authors:
8
7
  - Mosaic
@@ -14,7 +13,6 @@ dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: fig_newton
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ! '>='
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ! '>='
28
25
  - !ruby/object:Gem::Version
@@ -33,34 +30,45 @@ executables: []
33
30
  extensions: []
34
31
  extra_rdoc_files: []
35
32
  files:
33
+ - .gitignore
34
+ - Gemfile
35
+ - Gemfile.lock
36
+ - README.md
37
+ - Rakefile
38
+ - fluent-migrator-command-runner.gemspec
36
39
  - lib/fluent-migrator-command-runner.rb
37
- - lib/fluent-migrator-command-runner/runner.rb
38
40
  - lib/fluent-migrator-command-runner/command_builder.rb
39
- - lib/fluent-migrator-command-runner/task.rb
40
41
  - lib/fluent-migrator-command-runner/oracle_migration_command.rb
42
+ - lib/fluent-migrator-command-runner/runner.rb
43
+ - lib/fluent-migrator-command-runner/task.rb
44
+ - lib/fluent-migrator-command-runner/version.rb
45
+ - spec/fluent-migrator-command-runner/command_builder_spec.rb
46
+ - spec/fluent-migrator-command-runner/oracle_migration_command_spec.rb
47
+ - spec/fluent-migrator-command-runner/rake_task_spec.rb
48
+ - spec/fluent-migrator-command-runner/runner_spec.rb
49
+ - spec/spec_helper.rb
41
50
  homepage: ''
42
51
  licenses:
43
52
  - MIT
53
+ metadata: {}
44
54
  post_install_message:
45
55
  rdoc_options: []
46
56
  require_paths:
47
57
  - lib
48
58
  required_ruby_version: !ruby/object:Gem::Requirement
49
- none: false
50
59
  requirements:
51
60
  - - ! '>='
52
61
  - !ruby/object:Gem::Version
53
62
  version: '0'
54
63
  required_rubygems_version: !ruby/object:Gem::Requirement
55
- none: false
56
64
  requirements:
57
65
  - - ! '>='
58
66
  - !ruby/object:Gem::Version
59
67
  version: '0'
60
68
  requirements: []
61
69
  rubyforge_project:
62
- rubygems_version: 1.8.28
70
+ rubygems_version: 2.4.5
63
71
  signing_key:
64
- specification_version: 3
65
- summary: ''
72
+ specification_version: 4
73
+ summary: Rake Tasks For Fluent Migrator
66
74
  test_files: []