departure 4.0.1 → 6.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.codeclimate.yml +8 -0
- data/.gitignore +1 -0
- data/.pryrc +11 -0
- data/.rubocop.yml +60 -0
- data/.travis.yml +19 -2
- data/CHANGELOG.md +56 -0
- data/Dockerfile +32 -0
- data/Gemfile +2 -1
- data/LICENSE.txt +2 -1
- data/README.md +56 -15
- data/RELEASING.md +1 -1
- data/bin/console +3 -3
- data/bin/rspec +6 -7
- data/config.yml.erb +4 -0
- data/configuration.rb +3 -2
- data/departure.gemspec +14 -9
- data/docker-compose.yml +23 -0
- data/lib/active_record/connection_adapters/for_alter.rb +91 -0
- data/lib/active_record/connection_adapters/percona_adapter.rb +75 -17
- data/lib/departure.rb +11 -49
- data/lib/departure/alter_argument.rb +10 -4
- data/lib/departure/cli_generator.rb +2 -3
- data/lib/departure/command.rb +3 -3
- data/lib/departure/configuration.rb +2 -1
- data/lib/departure/connection_base.rb +9 -0
- data/lib/departure/connection_details.rb +29 -3
- data/lib/departure/dsn.rb +0 -2
- data/lib/departure/log_sanitizers/password_sanitizer.rb +2 -1
- data/lib/departure/logger.rb +1 -2
- data/lib/departure/logger_factory.rb +0 -1
- data/lib/departure/migration.rb +104 -0
- data/lib/departure/option.rb +4 -4
- data/lib/departure/railtie.rb +6 -13
- data/lib/departure/runner.rb +0 -2
- data/lib/departure/version.rb +1 -1
- data/lib/lhm.rb +1 -3
- data/lib/lhm/adapter.rb +1 -3
- data/lib/lhm/column_with_sql.rb +8 -4
- data/lib/lhm/column_with_type.rb +0 -2
- data/test_database.rb +37 -9
- metadata +55 -33
- data/config.yml +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d491f83699ed0a2a2932822f624162223ba8a3b74c018a56fd352a00378f3368
|
4
|
+
data.tar.gz: 6b6b6f192dab28cc61431e20bc7b0a35ecd76ab36a56edf5a0a59c42ae893e37
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 106fa1f8b21f7ab468d6774147352bb2b631398c04df2eb60b664ae520ea44dd91f76fc084ec0215ab722369ad59b3047d9ff6009767329bf26da708f50e60af
|
7
|
+
data.tar.gz: 66396ee515d0a69e65eb8e39dce53d4eec89a5419886b3482f1b4276be1480cb08adf452585f09f7da48b4683e9f87a1d0b4311c6f9ab05a5801577052feb5cf
|
data/.codeclimate.yml
ADDED
data/.gitignore
CHANGED
data/.pryrc
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
if defined?(PryByebug)
|
2
|
+
Pry.commands.alias_command 'c', 'continue'
|
3
|
+
Pry.commands.alias_command 's', 'step'
|
4
|
+
Pry.commands.alias_command 'n', 'next'
|
5
|
+
Pry.commands.alias_command 'f', 'finish'
|
6
|
+
Pry.commands.alias_command 'w', 'pry-backtrace'
|
7
|
+
|
8
|
+
Pry::Commands.command(/^$/, 'repeat last command') do
|
9
|
+
pry_instance.run_command Pry.history.to_a.last
|
10
|
+
end
|
11
|
+
end
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
---
|
2
|
+
Metrics/AbcSize:
|
3
|
+
Enabled: false
|
4
|
+
|
5
|
+
Metrics/BlockLength:
|
6
|
+
Max: 20
|
7
|
+
Exclude:
|
8
|
+
- 'spec/*'
|
9
|
+
- 'spec/**/*'
|
10
|
+
|
11
|
+
Metrics/BlockNesting:
|
12
|
+
Max: 4
|
13
|
+
|
14
|
+
Metrics/ClassLength:
|
15
|
+
Max: 250
|
16
|
+
|
17
|
+
Metrics/LineLength:
|
18
|
+
Max: 120
|
19
|
+
Exclude:
|
20
|
+
- 'departure.gemspec'
|
21
|
+
- 'test_database.rb'
|
22
|
+
|
23
|
+
Metrics/MethodLength:
|
24
|
+
Max: 30
|
25
|
+
|
26
|
+
Metrics/ModuleLength:
|
27
|
+
Max: 250
|
28
|
+
|
29
|
+
Metrics/ParameterLists:
|
30
|
+
Max: 5
|
31
|
+
|
32
|
+
Performance/Casecmp:
|
33
|
+
Enabled: false
|
34
|
+
|
35
|
+
Style/BracesAroundHashParameters:
|
36
|
+
Exclude:
|
37
|
+
- 'spec/fixtures/migrate/**.rb'
|
38
|
+
- 'spec/integration/**.rb'
|
39
|
+
|
40
|
+
Style/CommandLiteral:
|
41
|
+
Exclude:
|
42
|
+
- 'test_database.rb'
|
43
|
+
|
44
|
+
Style/Documentation:
|
45
|
+
Enabled: false
|
46
|
+
|
47
|
+
Style/MultilineBlockChain:
|
48
|
+
Exclude:
|
49
|
+
- 'spec/integration_spec.rb'
|
50
|
+
|
51
|
+
Layout/MultilineMethodCallIndentation:
|
52
|
+
Enabled: false
|
53
|
+
|
54
|
+
Style/SymbolArray:
|
55
|
+
Enabled: false
|
56
|
+
|
57
|
+
Style/UnneededPercentQ:
|
58
|
+
Exclude:
|
59
|
+
- 'departure.gemspec'
|
60
|
+
|
data/.travis.yml
CHANGED
@@ -1,8 +1,25 @@
|
|
1
1
|
language: ruby
|
2
|
+
|
2
3
|
rvm:
|
3
|
-
- 2.
|
4
|
+
- 2.5.5
|
5
|
+
- 2.6.3
|
6
|
+
- 2.7.0
|
7
|
+
|
8
|
+
env:
|
9
|
+
- RAILS_VERSION="~> 6.1.0"
|
10
|
+
- RAILS_VERSION="~> 6.0.0"
|
11
|
+
- RAILS_VERSION="~> 5.2.0"
|
12
|
+
|
13
|
+
jobs:
|
14
|
+
include:
|
15
|
+
- rvm: 2.4.6
|
16
|
+
env: RAILS_VERSION="~> 5.2.0"
|
17
|
+
|
18
|
+
services:
|
19
|
+
- mysql
|
20
|
+
|
4
21
|
before_install:
|
5
|
-
- sudo apt-key adv --keyserver keys.gnupg.net --recv-keys 8507EFA5
|
22
|
+
- travis_retry sudo apt-key adv --keyserver keys.gnupg.net --recv-keys 8507EFA5
|
6
23
|
- echo "deb http://repo.percona.com/apt `lsb_release -cs` main" | sudo tee -a /etc/apt/sources.list
|
7
24
|
- sudo apt-get update -qq
|
8
25
|
- sudo apt-get install percona-toolkit
|
data/CHANGELOG.md
CHANGED
@@ -6,12 +6,68 @@ Please follow the format in [Keep a Changelog](http://keepachangelog.com/)
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [6.2.0] - 2020-06-23
|
10
|
+
|
11
|
+
### Added
|
12
|
+
|
13
|
+
- Support for ActiveRecord 6.0
|
14
|
+
- Support for ActiveRecord 5.2
|
15
|
+
- Relax mysql2 requirement to allow mysql2 0.5.3
|
16
|
+
- Support to batch multiple changes at once with #change_table
|
17
|
+
- Support for connection to MySQL server over SSL
|
18
|
+
|
19
|
+
### Changed
|
20
|
+
|
21
|
+
- Depend only in railties and activerecord instead of rails gem
|
22
|
+
|
23
|
+
### Deprecated
|
24
|
+
### Removed
|
25
|
+
### Fixed
|
26
|
+
|
27
|
+
- Fix support for removing foreign keys
|
28
|
+
- Fix PERCONA_ARGS syntax for critical-load option
|
29
|
+
- Make sure quotes in ALTER TABLE get correctly escaped
|
30
|
+
- Fixes for regex handling
|
31
|
+
- Fix LHM compatibility
|
32
|
+
|
33
|
+
## [6.1.0] - 2018-02-27
|
34
|
+
|
9
35
|
### Added
|
10
36
|
### Changed
|
37
|
+
|
38
|
+
- Permit PERCONA_ARGS to be applied to db:migrate tasks
|
39
|
+
|
11
40
|
### Deprecated
|
12
41
|
### Removed
|
13
42
|
### Fixed
|
14
43
|
|
44
|
+
- Output lines are no longer wrapped at 8 chars
|
45
|
+
|
46
|
+
## [6.0.0] - 2017-09-25
|
47
|
+
|
48
|
+
### Added
|
49
|
+
|
50
|
+
- Support for ActiveRecord 5.1
|
51
|
+
|
52
|
+
### Changed
|
53
|
+
### Deprecated
|
54
|
+
### Removed
|
55
|
+
### Fixed
|
56
|
+
|
57
|
+
## [5.0.0] - 2017-09-19
|
58
|
+
|
59
|
+
### Added
|
60
|
+
|
61
|
+
- Support for ActiveRecord 5.0
|
62
|
+
- Docker setup to run the spec suite
|
63
|
+
|
64
|
+
### Changed
|
65
|
+
### Deprecated
|
66
|
+
### Removed
|
67
|
+
### Fixed
|
68
|
+
|
69
|
+
- Allow using bash special characters in passwords
|
70
|
+
|
15
71
|
## [4.0.1] - 2017-08-01
|
16
72
|
|
17
73
|
### Added
|
data/Dockerfile
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
FROM ruby:2.3.4
|
2
|
+
MAINTAINER muffinista@gmail.com
|
3
|
+
|
4
|
+
# Install apt based dependencies required to run Rails as
|
5
|
+
# well as RubyGems. As the Ruby image itself is based on a
|
6
|
+
# Debian image, we use apt-get to install those.
|
7
|
+
RUN apt-get update && apt-get install -y \
|
8
|
+
build-essential \
|
9
|
+
percona-toolkit
|
10
|
+
|
11
|
+
# Configure the main working directory. This is the base
|
12
|
+
# directory used in any further RUN, COPY, and ENTRYPOINT
|
13
|
+
# commands.
|
14
|
+
RUN mkdir -p /app /app/lib/departure
|
15
|
+
WORKDIR /app
|
16
|
+
|
17
|
+
# Copy the Gemfile as well as the Gemfile.lock and install
|
18
|
+
# the RubyGems. This is a separate step so the dependencies
|
19
|
+
# will be cached unless changes to one of those two files
|
20
|
+
# are made.
|
21
|
+
COPY departure.gemspec Gemfile ./
|
22
|
+
COPY lib/departure/version.rb ./lib/departure/
|
23
|
+
|
24
|
+
RUN gem install bundler && bundle install --jobs 20 --retry 5
|
25
|
+
|
26
|
+
# Copy the main application.
|
27
|
+
COPY . ./
|
28
|
+
|
29
|
+
# The main command to run when the container starts. Also
|
30
|
+
# tell the Rails dev server to bind to all interfaces by
|
31
|
+
# default.
|
32
|
+
#CMD ["bundle", "exec", "rails", "server", "-b", "0.0.0.0"]
|
data/Gemfile
CHANGED
data/LICENSE.txt
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
The MIT License (MIT)
|
2
2
|
|
3
|
-
Copyright
|
3
|
+
Copyright for portions of Departure are held by Redbooth, Inc., 2015-2017. All
|
4
|
+
other copyright for Departure are held by Pau Pérez, 2017.
|
4
5
|
|
5
6
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
7
|
of this software and associated documentation files (the "Software"), to deal
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Departure [![Build Status](https://travis-ci.org/
|
1
|
+
# Departure [![Build Status](https://travis-ci.org/departurerb/departure.svg?branch=master)](https://travis-ci.org/departurerb/departure) [![Code Climate](https://codeclimate.com/github/departurerb/departure/badges/gpa.svg)](https://codeclimate.com/github/departurerb/departure) ![GitHub commits since latest release (by date)](https://img.shields.io/github/commits-since/departurerb/departure/latest/master?style=plastic)
|
2
2
|
|
3
3
|
Departure is an **ActiveRecord connection adapter** that allows running
|
4
4
|
**MySQL online and non-blocking DDL** through `ActiveRecord::Migration` without needing
|
@@ -99,12 +99,11 @@ $ PERCONA_ARGS='--chunk-time=1' bundle exec rake db:migrate:up VERSION=xxx
|
|
99
99
|
or even mulitple arguments
|
100
100
|
|
101
101
|
```ruby
|
102
|
-
$ PERCONA_ARGS='--chunk-time=1 --critical-load=55' bundle exec rake db:migrate:up VERSION=xxx
|
102
|
+
$ PERCONA_ARGS='--chunk-time=1 --critical-load Threads_running=55' bundle exec rake db:migrate:up VERSION=xxx
|
103
103
|
```
|
104
104
|
|
105
|
-
|
106
|
-
|
107
|
-
vary depending on the database table and the kind of changes you apply.
|
105
|
+
Use caution when using PERCONA_ARGS with `db:migrate`, as your args will be applied
|
106
|
+
to every call that Departure makes to pt-osc.
|
108
107
|
|
109
108
|
#### with global configuration
|
110
109
|
|
@@ -113,14 +112,14 @@ using `global_percona_args` option.
|
|
113
112
|
|
114
113
|
```ruby
|
115
114
|
Departure.configure do |config|
|
116
|
-
config.global_percona_args = '--chunk-time=1 --critical-load=55'
|
115
|
+
config.global_percona_args = '--chunk-time=1 --critical-load Threads_running=55'
|
117
116
|
end
|
118
117
|
```
|
119
118
|
|
120
|
-
Unlike using `PERCONA_ARGS`, options provided with global configuration will be applied
|
119
|
+
Unlike using `PERCONA_ARGS`, options provided with global configuration will be applied
|
121
120
|
every time sql command is executed via `pt-online-schema-change`.
|
122
|
-
|
123
|
-
Arguments provided in global configuration can be overwritten with `PERCONA_ARGS` env variable.
|
121
|
+
|
122
|
+
Arguments provided in global configuration can be overwritten with `PERCONA_ARGS` env variable.
|
124
123
|
|
125
124
|
We recommend using this option with caution and only when you understand the consequences.
|
126
125
|
|
@@ -146,6 +145,39 @@ end
|
|
146
145
|
It's strongly recommended to name it after this gems name, such as
|
147
146
|
`config/initializers/departure.rb`
|
148
147
|
|
148
|
+
### Disable on per-migration basis
|
149
|
+
|
150
|
+
Departure gem is enabled by default.
|
151
|
+
In order to disable it on a particular migration the method `disable_departure!` should be used.
|
152
|
+
|
153
|
+
```ruby
|
154
|
+
class UseDepartureMigration < ActiveRecord::Migration[5.2]
|
155
|
+
disable_departure!
|
156
|
+
|
157
|
+
def up
|
158
|
+
# ...
|
159
|
+
end
|
160
|
+
# ...
|
161
|
+
end
|
162
|
+
```
|
163
|
+
|
164
|
+
### Enable on per-migration basis
|
165
|
+
|
166
|
+
If you wish to only have Departure enabled per-migration, set `config.enabled_by_default = false` in the configure block of your departure initializer.
|
167
|
+
|
168
|
+
Then, add a `uses_departure!` statement in migrations where Departure should be used:
|
169
|
+
|
170
|
+
```ruby
|
171
|
+
class UseDepartureMigration < ActiveRecord::Migration[5.2]
|
172
|
+
uses_departure!
|
173
|
+
|
174
|
+
def up
|
175
|
+
# ...
|
176
|
+
end
|
177
|
+
# ...
|
178
|
+
end
|
179
|
+
```
|
180
|
+
|
149
181
|
## How it works
|
150
182
|
|
151
183
|
When booting your Rails app, Departure extends the
|
@@ -155,22 +187,28 @@ it using the `DepartureAdapter` instead of the one you defined in your
|
|
155
187
|
|
156
188
|
Then, when any migration DSL methods such as `add_column` or `create_table` are
|
157
189
|
executed, they all go to the
|
158
|
-
[DepartureAdapter](https://github.com/
|
190
|
+
[DepartureAdapter](https://github.com/departurerb/departure/blob/master/lib/active_record/connection_adapters/departure_adapter.rb).
|
159
191
|
There, the methods that require `ALTER TABLE` SQL statements, like `add_column`,
|
160
192
|
are overriden to get executed with
|
161
|
-
[Departure::Runner](https://github.com/
|
193
|
+
[Departure::Runner](https://github.com/departurerb/departure/blob/master/lib/departure/runner.rb),
|
162
194
|
which deals with the `pt-online-schema-change` binary. All the others, like
|
163
195
|
`create_table`, are delegated to the ActiveRecord's built in Mysql2Adapter and
|
164
196
|
so they follow the regular path.
|
165
197
|
|
166
|
-
[Departure::Runner](https://github.com/
|
198
|
+
[Departure::Runner](https://github.com/departurerb/departure/blob/master/lib/departure/runner.rb)
|
167
199
|
spawns a new process that runs the `pt-online-schema-change` binary present in
|
168
|
-
the system, with the
|
200
|
+
the system, with the appropriate arguments for the generated SQL.
|
169
201
|
|
170
|
-
When
|
202
|
+
When any errors occur, an `ActiveRecord::StatementInvalid` exception is
|
171
203
|
raised and the migration is aborted, as all other ActiveRecord connection
|
172
204
|
adapters.
|
173
205
|
|
206
|
+
## Trouleshooting
|
207
|
+
|
208
|
+
### Error creating new table: DBD::mysql::db do failed: Can't write; duplicate key in table (TABLE_NAME)
|
209
|
+
There is a [known bug](https://bugs.launchpad.net/percona-toolkit/+bug/1498128) in percona-toolkit version 2.2.15
|
210
|
+
that prevents schema changes when a table has constraints. You should upgrade to a version later than 2.2.17 to fix the issue.
|
211
|
+
|
174
212
|
## Development
|
175
213
|
|
176
214
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
@@ -186,7 +224,7 @@ git commits and tags, and push the `.gem` file to
|
|
186
224
|
## Contributing
|
187
225
|
|
188
226
|
Bug reports and pull requests are welcome on GitHub at
|
189
|
-
https://github.com/
|
227
|
+
https://github.com/departurerb/departure. They need to be opened against
|
190
228
|
`master` or `v3.2` only if the changes fix a bug in Rails 3.2 apps.
|
191
229
|
|
192
230
|
Please note that this project is released with a Contributor Code of Conduct. By
|
@@ -203,3 +241,6 @@ You can consult the changelog [here](CHANGELOG.md)
|
|
203
241
|
The gem is available as open source under the terms of the [MIT
|
204
242
|
License](http://opensource.org/licenses/MIT).
|
205
243
|
|
244
|
+
![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/departurerb/departure?style=for-the-badge)
|
245
|
+
![GitHub issues](https://img.shields.io/github/issues/departurerb/departure?style=for-the-badge)
|
246
|
+
|
data/RELEASING.md
CHANGED
data/bin/console
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'percona_migrator'
|
5
5
|
|
6
6
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +10,5 @@ require "percona_migrator"
|
|
10
10
|
# require "pry"
|
11
11
|
# Pry.start
|
12
12
|
|
13
|
-
require
|
13
|
+
require 'irb'
|
14
14
|
IRB.start
|
data/bin/rspec
CHANGED
@@ -1,17 +1,16 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# frozen_string_literal: true
|
3
|
-
|
3
|
+
|
4
4
|
# This file was generated by Bundler.
|
5
5
|
#
|
6
6
|
# The application 'rspec' is installed as part of a gem, and
|
7
7
|
# this file is here to facilitate running it.
|
8
8
|
#
|
9
9
|
|
10
|
-
require
|
11
|
-
ENV[
|
12
|
-
Pathname.new(__FILE__).realpath)
|
10
|
+
require 'pathname'
|
11
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', Pathname.new(__FILE__).realpath)
|
13
12
|
|
14
|
-
require
|
15
|
-
require
|
13
|
+
require 'rubygems'
|
14
|
+
require 'bundler/setup'
|
16
15
|
|
17
|
-
load Gem.bin_path(
|
16
|
+
load Gem.bin_path('rspec-core', 'rspec')
|
data/config.yml.erb
ADDED
data/configuration.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
require 'yaml'
|
2
|
+
require 'erb'
|
2
3
|
|
3
4
|
class Configuration
|
4
|
-
CONFIG_PATH = 'config.yml'
|
5
|
+
CONFIG_PATH = 'config.yml.erb'.freeze
|
5
6
|
|
6
7
|
attr_reader :config
|
7
8
|
|
8
9
|
def initialize
|
9
|
-
@config = YAML.
|
10
|
+
@config = YAML.load(ERB.new(File.read(CONFIG_PATH)).result).freeze
|
10
11
|
end
|
11
12
|
|
12
13
|
def [](key)
|