fluent-migrator-command-runner 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,8 @@
1
1
  require 'fluent-migrator-command-runner/runner'
2
+ require 'fluent-migrator-command-runner/command_builder'
3
+ require 'fluent-migrator-command-runner/oracle_migration_command'
4
+ require 'fluent-migrator-command-runner/task'
5
+
2
6
  require 'fig_newton'
3
7
 
4
8
  module FluentMigratorCommandRunner
@@ -1,21 +1,11 @@
1
-
2
1
  module FluentMigratorCommandRunner
3
2
 
4
3
  class CommandBuilder
5
4
 
6
- def self.build (configuration, task, profile = nil, tag=nil)
7
- connection_string = build_connection_string(configuration[:connection_information])
8
- command = "#{configuration[:path_to_migrator]} --conn \"#{connection_string}\" /provider oracle --assembly \"#{configuration[:path_to_migration_assembly]}\" /task #{task}"
9
- command += " --tag #{tag}" if tag
10
- command += " --profile=#{profile}" if profile
11
- command
12
- end
13
-
14
- private
15
-
16
- def self.build_connection_string(configuration)
17
- "DATA SOURCE=#{configuration['database']};user id=#{configuration['username']};password=#{configuration['password']}"
18
- end
5
+ def self.build(migration_options = {})
6
+ command = OracleMigrationCommand.new(migration_options)
7
+ command.build
8
+ end
19
9
 
20
10
  end
21
11
  end
@@ -0,0 +1,42 @@
1
+ module FluentMigratorCommandRunner
2
+ class OracleMigrationCommand
3
+ attr_accessor :path_to_migrator,
4
+ :path_to_migration_assembly,
5
+ :connection_information,
6
+ :profile,
7
+ :tag
8
+
9
+ def initialize(options = {})
10
+ @profile = options[:profile] unless options[:profile].nil?
11
+ @tag = options[:tag] unless options[:tag].nil?
12
+ @path_to_migrator = FigNewton.path_to_migrator_exe
13
+ @path_to_migration_assembly = FigNewton.path_to_migration_assembly
14
+ @connection_information = FigNewton.database.to_hash
15
+ @connection_information['password'] = options[:db_password] unless options[:db_password].nil?
16
+ end
17
+
18
+ def build
19
+ connection_string = build_connection_string(@connection_information)
20
+
21
+ command_sections = []
22
+ 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(' ')
29
+ end
30
+
31
+ private
32
+
33
+ def build_connection_string(connection_information)
34
+ connection = []
35
+ connection.push("DATA SOURCE=#{connection_information['database']};")
36
+ connection.push("user id=#{connection_information['username']};")
37
+ connection.push("password=#{connection_information['password']}")
38
+ return connection.join('')
39
+ end
40
+
41
+ end
42
+ end
@@ -1,21 +1,15 @@
1
- require_relative 'command_builder'
2
-
3
1
  module FluentMigratorCommandRunner
4
2
  class Runner
5
3
 
6
- def initialize(overrides = {})
7
- defaults = {
8
- :path_to_migrator => FigNewton.path_to_migrator_exe,
9
- :path_to_migration_assembly => FigNewton.path_to_migration_assembly,
10
- :connection_information => FigNewton.database.to_hash
11
- }
12
- @configuration = defaults.merge(overrides)
4
+ def self.execute(command)
5
+ fluent_migrator_result = Kernel.system(command)
6
+ raise 'Fluent Migrator Failed' if fluent_migrator_run_failed?(fluent_migrator_result)
13
7
  end
14
8
 
15
- def migrate_database(profile = nil, tag = nil)
16
- command = CommandBuilder.build(@configuration, 'migrate', profile, tag)
17
- val = Kernel.system command
18
- raise 'Fluent Migrator Failed' if val == false
9
+ private
10
+
11
+ def self.fluent_migrator_run_failed?(fluent_migrator_result)
12
+ fluent_migrator_result == false
19
13
  end
20
14
 
21
15
  end
@@ -0,0 +1,44 @@
1
+ require 'fig_newton'
2
+ require 'rake'
3
+
4
+ require File.dirname(__FILE__) + "/runner"
5
+ require File.dirname(__FILE__) + "/command_builder"
6
+
7
+
8
+ module FluentMigratorCommandRunner
9
+ module Rake
10
+ class Task
11
+ include ::Rake::DSL
12
+
13
+ attr_accessor :fig_newton_file
14
+ attr_accessor :profile
15
+ attr_accessor :tag
16
+
17
+ def initialize(task_name)
18
+ @task_name = task_name
19
+
20
+ yield self if block_given?
21
+
22
+ define_task
23
+ end
24
+
25
+ def define_task
26
+ task @task_name, [:password] do |t, params|
27
+ FigNewton.load(@fig_newton_file) unless @fig_newton_file.nil?
28
+ options = migration_options
29
+ options[:db_password] = params[:password] unless params[:password].nil?
30
+ command = CommandBuilder.build(options)
31
+ Runner.execute(command)
32
+ end
33
+ end
34
+
35
+ def migration_options
36
+ options = {}
37
+ options[:profile] = profile unless profile.nil?
38
+ options[:tag] = tag unless tag.nil?
39
+ return options
40
+ end
41
+
42
+ end
43
+ end
44
+ end
metadata CHANGED
@@ -1,7 +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.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -36,6 +36,8 @@ files:
36
36
  - lib/fluent-migrator-command-runner.rb
37
37
  - lib/fluent-migrator-command-runner/runner.rb
38
38
  - lib/fluent-migrator-command-runner/command_builder.rb
39
+ - lib/fluent-migrator-command-runner/task.rb
40
+ - lib/fluent-migrator-command-runner/oracle_migration_command.rb
39
41
  homepage: ''
40
42
  licenses:
41
43
  - MIT
@@ -62,4 +64,3 @@ signing_key:
62
64
  specification_version: 3
63
65
  summary: ''
64
66
  test_files: []
65
- has_rdoc: