percona_migrator 0.1.0.rc.6 → 0.1.0.rc.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7c92cf9bc3f2fd48fbe1277d9196037bb9d92fec
4
- data.tar.gz: 8df8aceabfb8822fe30c3c1cae0d9055b58e2834
3
+ metadata.gz: bda957042f0b8003133ed8fddcc2b0e1dd227f75
4
+ data.tar.gz: 733e11a6c52f6354b353f9866796a431e2045188
5
5
  SHA512:
6
- metadata.gz: a1ee2cb57ce1d7062f34d6a3c604081f2c7c7863c76e2acccf7cdadb010239e4eb94350e0c28a17eb44a90f61c7c940239682dbec5e5d2bddcd18239386b1259
7
- data.tar.gz: e9fb460fb9eaaecee4ef5a6e5d424a23da11b9717522fd4e4914fa01d27230c5c813dac1160c460f161414077e41f64f4348a94619f0c7e43f8071abc6a57100
6
+ metadata.gz: 76f26f49d302c27433b1ff95f3ea277e431b1da805f139f2ed1ec57839978d907e6f8d719c5897183a71c7049fe9b81e354ceebd511fe52613f7fd2cab3fbc8e
7
+ data.tar.gz: 01233203b600ee1f851a4bc2d0820ebd618f4018286fdda856db53fad1ae7e83673edb81126759a62d796f290d76359eb3797f995d6cf2db924c17fc1681700a
@@ -6,6 +6,18 @@ Please follow the format in [Keep a Changelog](http://keepachangelog.com/)
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.1.0.rc.7] - 2016-09-15
10
+
11
+ ### Added
12
+
13
+ - Toggle pt-online-schema-change's output as well when toggling the migration's
14
+ verbose option.
15
+
16
+ ### Changed
17
+
18
+ - Enabled pt-online-schema-change's output while running the migration, that got
19
+ broken in v0.1.0.rc.2
20
+
9
21
  ## [0.1.0.rc.6] - 2016-04-07
10
22
 
11
23
  ### Added
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Percona Migrator [![Build Status](https://travis-ci.org/redbooth/percona_migrator.svg?branch=master)](https://travis-ci.org/redbooth/percona_migrator) [![Code Climate](https://codeclimate.com/github/redbooth/percona_migrator/badges/gpa.svg)](https://codeclimate.com/github/redbooth/percona_migrator)
2
2
 
3
3
  Percona Migrator is an **ActiveRecord connection adapter** that allows running
4
- **MySQL online and non-blocking DDL** `ActiveRecord::Migration` without needing
4
+ **MySQL online and non-blocking DDL** through `ActiveRecord::Migration` without needing
5
5
  to use a different DSL other than Rails' migrations DSL.
6
6
 
7
7
  It uses `pt-online-schema-change` command-line tool of
@@ -11,9 +11,12 @@ module ActiveRecord
11
11
  def self.percona_connection(config)
12
12
  mysql2_connection = mysql2_connection(config)
13
13
 
14
+ verbose = ActiveRecord::Migration.verbose
15
+ percona_logger = PerconaMigrator::LoggerFactory.build(verbose: verbose)
14
16
  cli_generator = PerconaMigrator::CliGenerator.new(config)
17
+
15
18
  runner = PerconaMigrator::Runner.new(
16
- logger,
19
+ percona_logger,
17
20
  cli_generator,
18
21
  mysql2_connection
19
22
  )
@@ -4,6 +4,9 @@ require 'active_support/all'
4
4
  require 'percona_migrator/version'
5
5
  require 'percona_migrator/runner'
6
6
  require 'percona_migrator/cli_generator'
7
+ require 'percona_migrator/logger'
8
+ require 'percona_migrator/null_logger'
9
+ require 'percona_migrator/logger_factory'
7
10
 
8
11
  require 'percona_migrator/railtie' if defined?(Rails)
9
12
 
@@ -0,0 +1,23 @@
1
+ module PerconaMigrator
2
+ # Copies the ActiveRecord::Migration #say and #write to log the migration's
3
+ # status. It's not possible to reuse the from ActiveRecord::Migration because
4
+ # the migration's instance can't be seen from the connection adapter.
5
+ class Logger
6
+
7
+ # Outputs the message through the stdout, following the
8
+ # ActiveRecord::Migration log format
9
+ #
10
+ # @param message [String]
11
+ # @param subitem [Boolean] whether to show message as a nested log item
12
+ def say(message, subitem = false)
13
+ write "#{subitem ? " ->" : "--"} #{message}"
14
+ end
15
+
16
+ # Outputs the text through the stdout
17
+ #
18
+ # @param text [String]
19
+ def write(text = '')
20
+ puts(text)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,17 @@
1
+ module PerconaMigrator
2
+ module LoggerFactory
3
+
4
+ # Returns the appropriate logger instance for the given configuration. Use
5
+ # :verbose option to log to the stdout
6
+ #
7
+ # @param verbose [Boolean]
8
+ # @return [#say, #write]
9
+ def self.build(verbose: true)
10
+ if verbose
11
+ PerconaMigrator::Logger.new
12
+ else
13
+ PerconaMigrator::NullLogger.new
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,11 @@
1
+ module PerconaMigrator
2
+ class NullLogger
3
+ def say(_message, _subitem = false)
4
+ # noop
5
+ end
6
+
7
+ def write(_text)
8
+ # noop
9
+ end
10
+ end
11
+ end
@@ -40,13 +40,12 @@ module PerconaMigrator
40
40
  class Runner
41
41
  COMMAND_NOT_FOUND = 127
42
42
 
43
- NONE = "\e[0m"
44
- CYAN = "\e[38;5;86m"
45
- GREEN = "\e[32m"
46
-
47
43
  # Constructor
48
44
  #
49
- # @param logger [IO]
45
+ # @param logger [#say, #write]
46
+ # @param cli_generator [CliGenerator]
47
+ # @param mysql_adapter [ActiveRecord::ConnectionAdapter] it must implement
48
+ # #execute and #raw_connection
50
49
  def initialize(logger, cli_generator, mysql_adapter)
51
50
  @logger = logger
52
51
  @cli_generator = cli_generator
@@ -83,12 +82,14 @@ module PerconaMigrator
83
82
  def execute(command)
84
83
  @command = command
85
84
  logging { run_command }
85
+ validate_status
86
86
  status
87
87
  end
88
88
 
89
89
  private
90
90
 
91
- attr_reader :command, :logger, :status, :cli_generator, :mysql_adapter
91
+ attr_reader :command, :logger, :status, :error_message, :cli_generator,
92
+ :mysql_adapter
92
93
 
93
94
  # Checks whether the sql statement is an ALTER TABLE
94
95
  #
@@ -107,37 +108,37 @@ module PerconaMigrator
107
108
  log_finished
108
109
  end
109
110
 
110
- # TODO: log as a migration logger subitem
111
- #
112
111
  # Logs when the execution started
113
112
  def log_started
114
- logger.info "\n#{CYAN}-- #{command}#{NONE}\n\n"
113
+ logger.write("\n")
114
+ logger.say("Running #{command}\n\n", true)
115
115
  end
116
116
 
117
- # Executes the command outputing any errors
118
- #
119
- # @raise [NoStatusError] if the spawned process' status can't be retrieved
120
- # @raise [SignalError] if the spawned process receives a signal
121
- # @raise [CommandNotFoundError] if pt-online-schema-change can't be found
117
+ # Executes the command and prints its output to the stdout
122
118
  def run_command
123
- message = nil
124
119
  Open3.popen3(command) do |_stdin, stdout, stderr, waith_thr|
125
120
  @status = waith_thr.value
126
- message = stderr.read
127
- logger.info(stdout.read)
121
+ @error_message = stderr.read
122
+ logger.write(stdout.read)
128
123
  end
124
+ end
129
125
 
126
+ # Validates the status of the execution
127
+ #
128
+ # @raise [NoStatusError] if the spawned process' status can't be retrieved
129
+ # @raise [SignalError] if the spawned process received a signal
130
+ # @raise [CommandNotFoundError] if pt-online-schema-change can't be found
131
+ def validate_status
130
132
  raise NoStatusError if status.nil?
131
133
  raise SignalError.new(status) if status.signaled?
132
134
  raise CommandNotFoundError if status.exitstatus == COMMAND_NOT_FOUND
133
-
134
- raise Error, message unless status.success?
135
+ raise Error, error_message unless status.success?
135
136
  end
136
137
 
137
- # Logs the status of the execution once it's finished. At this point we
138
- # know it's a success
138
+ # Prints a line break to keep the logs separate from the execution time
139
+ # print by the migration
139
140
  def log_finished
140
- logger.info("\n#{GREEN}Done!#{NONE}")
141
+ logger.write("\n")
141
142
  end
142
143
  end
143
144
  end
@@ -1,3 +1,3 @@
1
1
  module PerconaMigrator
2
- VERSION = '0.1.0.rc.6'.freeze
2
+ VERSION = '0.1.0.rc.7'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: percona_migrator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.rc.6
4
+ version: 0.1.0.rc.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ilya Zayats
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2016-04-07 00:00:00.000000000 Z
14
+ date: 2016-09-15 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rails
@@ -154,6 +154,9 @@ files:
154
154
  - lib/percona_migrator.rb
155
155
  - lib/percona_migrator/alter_argument.rb
156
156
  - lib/percona_migrator/cli_generator.rb
157
+ - lib/percona_migrator/logger.rb
158
+ - lib/percona_migrator/logger_factory.rb
159
+ - lib/percona_migrator/null_logger.rb
157
160
  - lib/percona_migrator/railtie.rb
158
161
  - lib/percona_migrator/runner.rb
159
162
  - lib/percona_migrator/version.rb
@@ -179,7 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
179
182
  version: 1.3.1
180
183
  requirements: []
181
184
  rubyforge_project:
182
- rubygems_version: 2.2.2
185
+ rubygems_version: 2.4.5.1
183
186
  signing_key:
184
187
  specification_version: 4
185
188
  summary: pt-online-schema-change runner for ActiveRecord migrations