percona_migrator 0.1.0.rc.7 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bda957042f0b8003133ed8fddcc2b0e1dd227f75
4
- data.tar.gz: 733e11a6c52f6354b353f9866796a431e2045188
3
+ metadata.gz: 59ecf09f58f8aa46d64cf996a2a91a8acfa6dc8b
4
+ data.tar.gz: 24daf3f8ba0bd51f1804b23857a0a94d4d345bfc
5
5
  SHA512:
6
- metadata.gz: 76f26f49d302c27433b1ff95f3ea277e431b1da805f139f2ed1ec57839978d907e6f8d719c5897183a71c7049fe9b81e354ceebd511fe52613f7fd2cab3fbc8e
7
- data.tar.gz: 01233203b600ee1f851a4bc2d0820ebd618f4018286fdda856db53fad1ae7e83673edb81126759a62d796f290d76359eb3797f995d6cf2db924c17fc1681700a
6
+ metadata.gz: 1b1e0e1b42bcf64cd145a34882de830b572e9aabfcd3616a03bf7f81d1545864ca91951b1217f0bbf78191d41aeaa1b29761e3542fa7c110abff1823e4c845ff
7
+ data.tar.gz: 02eae12611279a35d0cfaf243c1cda0a883c8ad91c792fea9ae11826b1b49e208eb6fa0da434f68706560fcc5ecf7535c5e9b3e366c406d010b53766aded8e27
data/.gitignore CHANGED
@@ -9,3 +9,4 @@
9
9
  /tmp/
10
10
  .byebug_history
11
11
  tags
12
+ percona_migrator_error.log
data/.travis.yml CHANGED
@@ -2,12 +2,14 @@ language: ruby
2
2
  rvm:
3
3
  - 2.1.2
4
4
  before_install:
5
- - gpg --keyserver hkp://keys.gnupg.net --recv-keys 1C4CBDCDCD2EFD2A && gpg -a --export CD2EFD2A | sudo apt-key add -
5
+ - sudo apt-key adv --keyserver keys.gnupg.net --recv-keys 8507EFA5
6
6
  - echo "deb http://repo.percona.com/apt `lsb_release -cs` main" | sudo tee -a /etc/apt/sources.list
7
7
  - sudo apt-get update -qq
8
8
  - sudo apt-get install percona-toolkit
9
9
  - gem update bundler
10
10
  - bin/setup
11
+ after_success:
12
+ - codeclimate-test-reporter
11
13
 
12
14
  branches:
13
15
  only:
data/CHANGELOG.md CHANGED
@@ -6,6 +6,31 @@ Please follow the format in [Keep a Changelog](http://keepachangelog.com/)
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ### Added
10
+ ### Changed
11
+ ### Removed
12
+ ### Fixed
13
+
14
+ ## [0.1.1] - 2017-03-10
15
+
16
+ ### Added
17
+
18
+ - Store pt-online-schema-change's stderr to percona_migrator_error.log in the
19
+ default Rails tmp folder.
20
+ - Allow configuring the tmp directory where the error log gets written into.
21
+ - Output a deprecation warning when installing and running the gem. It will be
22
+ replaced by Departure soon.
23
+
24
+ ### Changed
25
+
26
+ - No longer a hard dependency on mysql2 0.3.20. Will accept 0.3.20 or any
27
+ higher patch revisions.
28
+
29
+ ### Fixed
30
+
31
+ - Output pt-online-schema-change's stdout while the migration is running instead
32
+ of all of it at the end.
33
+
9
34
  ## [0.1.0.rc.7] - 2016-09-15
10
35
 
11
36
  ### Added
data/Gemfile CHANGED
@@ -2,4 +2,4 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
- gem "codeclimate-test-reporter", group: :test, require: nil
5
+ gem "codeclimate-test-reporter", '~> 1.0.3', group: :test, require: nil
data/README.md CHANGED
@@ -1,6 +1,6 @@
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)
1
+ # Departure [![Build Status](https://travis-ci.org/redbooth/departure.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
- Percona Migrator is an **ActiveRecord connection adapter** that allows running
3
+ Departure is an **ActiveRecord connection adapter** that allows running
4
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
 
@@ -9,9 +9,17 @@ It uses `pt-online-schema-change` command-line tool of
9
9
  Toolkit](https://www.percona.com/doc/percona-toolkit/2.0/pt-online-schema-change.html)
10
10
  which runs MySQL alter table statements without downtime.
11
11
 
12
+ ## Rename from "Percona Migrator"
13
+
14
+ This project was formerly known as "Percona Migrator", but this incurs in an
15
+ infringement of Percona's trade mark policy and thus has to be renamed. Said
16
+ name is likely to cause confusion as to the source of the wrapper.
17
+
18
+ The next major versions will use "Departure" as gem name.
19
+
12
20
  ## Installation
13
21
 
14
- Percona Migrator relies on `pt-online-schema-change` from [Percona
22
+ Departure relies on `pt-online-schema-change` from [Percona
15
23
  Toolkit](https://www.percona.com/doc/percona-toolkit/2.0/pt-online-schema-change.html)
16
24
 
17
25
  ### Mac
@@ -62,15 +70,28 @@ migration.
62
70
  ### LHM support
63
71
 
64
72
  If you moved to Soundcloud's [Lhm](https://github.com/soundcloud/lhm) already,
65
- we got you covered. Percona Migrator overrides Lhm's DSL so that all the alter
73
+ we got you covered. Departure overrides Lhm's DSL so that all the alter
66
74
  statements also go through `pt-online-schema-change` as well.
67
75
 
68
76
  You can keep your Lhm migrations and start using Rails migration's DSL back
69
77
  again in your next migration.
70
78
 
79
+ ## Configuration
80
+
81
+ You can override any of the default values from an initializer:
82
+
83
+ ```ruby
84
+ PerconaMigrator.configure do |config|
85
+ config.tmp_path = '/tmp/'
86
+ end
87
+ ```
88
+
89
+ It's strongly recommended to name it after this gems name, such as
90
+ `config/initializers/percona_migrator.rb`
91
+
71
92
  ## How it works
72
93
 
73
- When booting your Rails app, Percona Migrator extends the
94
+ When booting your Rails app, Departure extends the
74
95
  `ActiveRecord::Migration#migrate` method to reset the connection and reestablish
75
96
  it using the `PerconaAdapter` instead of the one you defined in your
76
97
  `config/database.yml`.
@@ -0,0 +1,18 @@
1
+ module PerconaMigrator
2
+ class Configuration
3
+ attr_accessor :tmp_path
4
+
5
+ def initialize
6
+ @tmp_path = '.'.freeze
7
+ @error_log_filename = 'percona_migrator_error.log'.freeze
8
+ end
9
+
10
+ def error_log_path
11
+ File.join(tmp_path, error_log_filename)
12
+ end
13
+
14
+ private
15
+
16
+ attr_reader :error_log_filename
17
+ end
18
+ end
@@ -0,0 +1,35 @@
1
+ module PerconaMigrator
2
+ class Error < StandardError; end
3
+
4
+ # Used when for whatever reason we couldn't get the spawned process'
5
+ # status.
6
+ class NoStatusError < Error
7
+ def message
8
+ 'Status could not be retrieved'.freeze
9
+ end
10
+ end
11
+
12
+ # Used when the spawned process failed by receiving a signal.
13
+ # pt-online-schema-change returns "SIGSEGV (signal 11)" on failures.
14
+ class SignalError < Error
15
+ attr_reader :status
16
+
17
+ # Constructor
18
+ #
19
+ # @param status [Process::Status]
20
+ def initialize(status)
21
+ super
22
+ @status = status
23
+ end
24
+
25
+ def message
26
+ status.to_s
27
+ end
28
+ end
29
+
30
+ class CommandNotFoundError < Error
31
+ def message
32
+ 'Please install pt-online-schema-change. Check: https://www.percona.com/doc/percona-toolkit for further details'
33
+ end
34
+ end
35
+ end
@@ -1,7 +1,8 @@
1
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.
2
+ # Copies the ActiveRecord::Migration #say and #write plus a new
3
+ # #write_no_newline to log the migration's status. It's not possible to reuse
4
+ # the from ActiveRecord::Migration because the migration's instance can't be
5
+ # seen from the connection adapter.
5
6
  class Logger
6
7
 
7
8
  # Outputs the message through the stdout, following the
@@ -13,11 +14,18 @@ module PerconaMigrator
13
14
  write "#{subitem ? " ->" : "--"} #{message}"
14
15
  end
15
16
 
16
- # Outputs the text through the stdout
17
+ # Outputs the text through the stdout adding a new line at the end
17
18
  #
18
19
  # @param text [String]
19
20
  def write(text = '')
20
21
  puts(text)
21
22
  end
23
+
24
+ # Outputs the text through the stdout without adding a new line at the end
25
+ #
26
+ # @param text [String]
27
+ def write_no_newline(text)
28
+ print(text)
29
+ end
22
30
  end
23
31
  end
@@ -7,5 +7,9 @@ module PerconaMigrator
7
7
  def write(_text)
8
8
  # noop
9
9
  end
10
+
11
+ def write_no_newline(_text)
12
+ # noop
13
+ end
10
14
  end
11
15
  end
@@ -15,40 +15,13 @@ module PerconaMigrator
15
15
  # regular Rails Migration DSL.
16
16
  initializer 'percona_migrator.configure_rails_initialization' do
17
17
  ActiveSupport.on_load(:active_record) do
18
+ PerconaMigrator.load
19
+ end
20
+ end
18
21
 
19
- ActiveRecord::Migration.class_eval do
20
- alias_method :original_migrate, :migrate
21
-
22
- # Replaces the current connection adapter with the PerconaAdapter and
23
- # patches LHM, then it continues with the regular migration process.
24
- #
25
- # @param direction [Symbol] :up or :down
26
- def migrate(direction)
27
- reconnect_with_percona
28
- include_foreigner if defined?(Foreigner)
29
-
30
- ::Lhm.migration = self
31
- original_migrate(direction)
32
- end
33
-
34
- # Includes the Foreigner's Mysql2Adapter implemention in
35
- # PerconaMigratorAdapter to support foreign keys
36
- def include_foreigner
37
- Foreigner::Adapter.safe_include(
38
- :PerconaMigratorAdapter,
39
- Foreigner::ConnectionAdapters::Mysql2Adapter
40
- )
41
- end
42
-
43
- # Make all connections in the connection pool to use PerconaAdapter
44
- # instead of the current adapter.
45
- def reconnect_with_percona
46
- connection_config = ActiveRecord::Base.connection_config
47
- ActiveRecord::Base.establish_connection(
48
- connection_config.merge(adapter: 'percona')
49
- )
50
- end
51
- end
22
+ initializer 'percona_migrator.configure' do |app|
23
+ PerconaMigrator.configure do |config|
24
+ config.tmp_path = app.paths['tmp'].first
52
25
  end
53
26
  end
54
27
  end
@@ -1,39 +1,6 @@
1
1
  require 'open3'
2
2
 
3
3
  module PerconaMigrator
4
- class Error < StandardError; end
5
-
6
- # Used when for whatever reason we couldn't get the spawned process'
7
- # status.
8
- class NoStatusError < Error
9
- def message
10
- 'Status could not be retrieved'.freeze
11
- end
12
- end
13
-
14
- # Used when the spawned process failed by receiving a signal.
15
- # pt-online-schema-change returns "SIGSEGV (signal 11)" on failures.
16
- class SignalError < Error
17
- attr_reader :status
18
-
19
- # Constructor
20
- #
21
- # @param status [Process::Status]
22
- def initialize(status)
23
- super
24
- @status = status
25
- end
26
-
27
- def message
28
- status.to_s
29
- end
30
- end
31
-
32
- class CommandNotFoundError < Error
33
- def message
34
- 'Please install pt-online-schema-change. Check: https://www.percona.com/doc/percona-toolkit for further details'
35
- end
36
- end
37
4
 
38
5
  # It executes pt-online-schema-change commands in a new process and gets its
39
6
  # output and status
@@ -46,11 +13,12 @@ module PerconaMigrator
46
13
  # @param cli_generator [CliGenerator]
47
14
  # @param mysql_adapter [ActiveRecord::ConnectionAdapter] it must implement
48
15
  # #execute and #raw_connection
49
- def initialize(logger, cli_generator, mysql_adapter)
16
+ def initialize(logger, cli_generator, mysql_adapter, config = PerconaMigrator.configuration)
50
17
  @logger = logger
51
18
  @cli_generator = cli_generator
52
19
  @mysql_adapter = mysql_adapter
53
20
  @status = nil
21
+ @config = config
54
22
  end
55
23
 
56
24
  # Executes the passed sql statement using pt-online-schema-change for ALTER
@@ -88,8 +56,7 @@ module PerconaMigrator
88
56
 
89
57
  private
90
58
 
91
- attr_reader :command, :logger, :status, :error_message, :cli_generator,
92
- :mysql_adapter
59
+ attr_reader :command, :logger, :status, :cli_generator, :mysql_adapter, :config
93
60
 
94
61
  # Checks whether the sql statement is an ALTER TABLE
95
62
  #
@@ -103,11 +70,17 @@ module PerconaMigrator
103
70
  #
104
71
  # @yield
105
72
  def logging
73
+ log_deprecations
106
74
  log_started
107
75
  yield
108
76
  log_finished
109
77
  end
110
78
 
79
+ def log_deprecations
80
+ logger.write("\n")
81
+ logger.write("[DEPRECATION] This gem has been renamed to Departure and will no longer be supported. Please switch to Departure as soon as possible.")
82
+ end
83
+
111
84
  # Logs when the execution started
112
85
  def log_started
113
86
  logger.write("\n")
@@ -116,10 +89,18 @@ module PerconaMigrator
116
89
 
117
90
  # Executes the command and prints its output to the stdout
118
91
  def run_command
119
- Open3.popen3(command) do |_stdin, stdout, stderr, waith_thr|
120
- @status = waith_thr.value
121
- @error_message = stderr.read
122
- logger.write(stdout.read)
92
+ Open3.popen3("#{command} 2> #{error_log_path}") do |_stdin, stdout, _stderr, waith_thr|
93
+ begin
94
+ loop do
95
+ IO.select([stdout])
96
+ data = stdout.read_nonblock(8)
97
+ logger.write_no_newline(data)
98
+ end
99
+ rescue EOFError
100
+ # noop
101
+ ensure
102
+ @status = waith_thr.value
103
+ end
123
104
  end
124
105
  end
125
106
 
@@ -129,7 +110,6 @@ module PerconaMigrator
129
110
  # @raise [SignalError] if the spawned process received a signal
130
111
  # @raise [CommandNotFoundError] if pt-online-schema-change can't be found
131
112
  def validate_status
132
- raise NoStatusError if status.nil?
133
113
  raise SignalError.new(status) if status.signaled?
134
114
  raise CommandNotFoundError if status.exitstatus == COMMAND_NOT_FOUND
135
115
  raise Error, error_message unless status.success?
@@ -140,5 +120,17 @@ module PerconaMigrator
140
120
  def log_finished
141
121
  logger.write("\n")
142
122
  end
123
+
124
+ # The path where the percona toolkit stderr will be written
125
+ #
126
+ # @return [String]
127
+ def error_log_path
128
+ config.error_log_path
129
+ end
130
+
131
+ # @return [String]
132
+ def error_message
133
+ File.read(error_log_path)
134
+ end
143
135
  end
144
136
  end
@@ -1,3 +1,3 @@
1
1
  module PerconaMigrator
2
- VERSION = '0.1.0.rc.7'.freeze
2
+ VERSION = '0.1.1'.freeze
3
3
  end
@@ -7,8 +7,59 @@ require 'percona_migrator/cli_generator'
7
7
  require 'percona_migrator/logger'
8
8
  require 'percona_migrator/null_logger'
9
9
  require 'percona_migrator/logger_factory'
10
+ require 'percona_migrator/configuration'
11
+ require 'percona_migrator/errors'
10
12
 
11
13
  require 'percona_migrator/railtie' if defined?(Rails)
12
14
 
15
+ # We need the OS not to buffer the IO to see pt-osc's output while migrating
16
+ $stdout.sync = true
17
+
13
18
  module PerconaMigrator
19
+ class << self
20
+ attr_accessor :configuration
21
+ end
22
+
23
+ def self.configure
24
+ self.configuration ||= Configuration.new
25
+ yield(configuration)
26
+ end
27
+
28
+ # Hooks Percona Migrator into Rails migrations by replacing the configured
29
+ # database adapter
30
+ def self.load
31
+ ActiveRecord::Migration.class_eval do
32
+ alias_method :original_migrate, :migrate
33
+
34
+ # Replaces the current connection adapter with the PerconaAdapter and
35
+ # patches LHM, then it continues with the regular migration process.
36
+ #
37
+ # @param direction [Symbol] :up or :down
38
+ def migrate(direction)
39
+ reconnect_with_percona
40
+ include_foreigner if defined?(Foreigner)
41
+
42
+ ::Lhm.migration = self
43
+ original_migrate(direction)
44
+ end
45
+
46
+ # Includes the Foreigner's Mysql2Adapter implemention in
47
+ # PerconaMigratorAdapter to support foreign keys
48
+ def include_foreigner
49
+ Foreigner::Adapter.safe_include(
50
+ :PerconaMigratorAdapter,
51
+ Foreigner::ConnectionAdapters::Mysql2Adapter
52
+ )
53
+ end
54
+
55
+ # Make all connections in the connection pool to use PerconaAdapter
56
+ # instead of the current adapter.
57
+ def reconnect_with_percona
58
+ connection_config = ActiveRecord::Base.connection_config
59
+ ActiveRecord::Base.establish_connection(
60
+ connection_config.merge(adapter: 'percona')
61
+ )
62
+ end
63
+ end
64
+ end
14
65
  end
@@ -15,12 +15,17 @@ Gem::Specification.new do |spec|
15
15
  spec.homepage = 'http://github.com/redbooth/percona_migrator'
16
16
  spec.license = 'MIT'
17
17
 
18
+ spec.post_install_message = <<-MESSAGE
19
+ ! The Percona_migrator gem has been deprecated and has been replaced by Departure.
20
+ ! See: https://rubygems.org/gems/departure
21
+ ! And: https://github.com/redbooth/departure
22
+ MESSAGE
23
+
18
24
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
25
  spec.require_paths = ['lib']
20
26
 
21
- # TODO: Relax me
22
27
  spec.add_runtime_dependency 'rails', '~>3.2.22'
23
- spec.add_runtime_dependency 'mysql2', '0.3.20'
28
+ spec.add_runtime_dependency 'mysql2', '~>0.3.20'
24
29
 
25
30
  spec.add_development_dependency 'bundler', '~> 1.10'
26
31
  spec.add_development_dependency 'rake', '~> 10.0'
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.7
4
+ version: 0.1.1
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-09-15 00:00:00.000000000 Z
14
+ date: 2017-03-10 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rails
@@ -31,14 +31,14 @@ dependencies:
31
31
  name: mysql2
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  requirements:
34
- - - '='
34
+ - - "~>"
35
35
  - !ruby/object:Gem::Version
36
36
  version: 0.3.20
37
37
  type: :runtime
38
38
  prerelease: false
39
39
  version_requirements: !ruby/object:Gem::Requirement
40
40
  requirements:
41
- - - '='
41
+ - - "~>"
42
42
  - !ruby/object:Gem::Version
43
43
  version: 0.3.20
44
44
  - !ruby/object:Gem::Dependency
@@ -154,6 +154,8 @@ 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/configuration.rb
158
+ - lib/percona_migrator/errors.rb
157
159
  - lib/percona_migrator/logger.rb
158
160
  - lib/percona_migrator/logger_factory.rb
159
161
  - lib/percona_migrator/null_logger.rb
@@ -166,7 +168,10 @@ homepage: http://github.com/redbooth/percona_migrator
166
168
  licenses:
167
169
  - MIT
168
170
  metadata: {}
169
- post_install_message:
171
+ post_install_message: |2
172
+ ! The Percona_migrator gem has been deprecated and has been replaced by Departure.
173
+ ! See: https://rubygems.org/gems/departure
174
+ ! And: https://github.com/redbooth/departure
170
175
  rdoc_options: []
171
176
  require_paths:
172
177
  - lib
@@ -177,12 +182,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
177
182
  version: '0'
178
183
  required_rubygems_version: !ruby/object:Gem::Requirement
179
184
  requirements:
180
- - - ">"
185
+ - - ">="
181
186
  - !ruby/object:Gem::Version
182
- version: 1.3.1
187
+ version: '0'
183
188
  requirements: []
184
189
  rubyforge_project:
185
- rubygems_version: 2.4.5.1
190
+ rubygems_version: 2.6.10
186
191
  signing_key:
187
192
  specification_version: 4
188
193
  summary: pt-online-schema-change runner for ActiveRecord migrations