departure-76c9880 6.2.0
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 +7 -0
- data/.codeclimate.yml +8 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.rubocop.yml +60 -0
- data/.travis.yml +30 -0
- data/CHANGELOG.md +192 -0
- data/CODE_OF_CONDUCT.md +50 -0
- data/Dockerfile +32 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +227 -0
- data/RELEASING.md +17 -0
- data/Rakefile +17 -0
- data/bin/console +14 -0
- data/bin/rspec +16 -0
- data/bin/setup +7 -0
- data/config.yml.erb +4 -0
- data/configuration.rb +16 -0
- data/departure.gemspec +35 -0
- 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 +168 -0
- data/lib/departure.rb +43 -0
- data/lib/departure/alter_argument.rb +49 -0
- data/lib/departure/cli_generator.rb +84 -0
- data/lib/departure/command.rb +96 -0
- data/lib/departure/configuration.rb +20 -0
- data/lib/departure/connection_base.rb +9 -0
- data/lib/departure/connection_details.rb +96 -0
- data/lib/departure/dsn.rb +24 -0
- data/lib/departure/errors.rb +39 -0
- data/lib/departure/log_sanitizers/password_sanitizer.rb +22 -0
- data/lib/departure/logger.rb +42 -0
- data/lib/departure/logger_factory.rb +16 -0
- data/lib/departure/migration.rb +96 -0
- data/lib/departure/null_logger.rb +15 -0
- data/lib/departure/option.rb +75 -0
- data/lib/departure/railtie.rb +21 -0
- data/lib/departure/runner.rb +62 -0
- data/lib/departure/user_options.rb +44 -0
- data/lib/departure/version.rb +3 -0
- data/lib/lhm.rb +23 -0
- data/lib/lhm/adapter.rb +107 -0
- data/lib/lhm/column_with_sql.rb +96 -0
- data/lib/lhm/column_with_type.rb +29 -0
- data/test_database.rb +80 -0
- metadata +245 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: bf36ce3a7bd698221c247f1f71cbcd3a89dbdf06b92f9a2578cf0de97da5645f
|
4
|
+
data.tar.gz: caf6bca450a5c7ac055a15531c05409316aef1ea57f959fc36a88930ca764ec0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 753c451b099a1670d49506922cd6ed732aa05c016b7380d1812ac0d0ff012107335ea882bb64c794ba6bc6e84a218134966c9cc560a62685eb68e7de35186baf
|
7
|
+
data.tar.gz: 65321b556b5099203333836a989cbe4cf93adb0592a6e30d498d5ba75fea3f0798399b049cb2512f58f2007afece7ad0069eb0cba57c8b25d3363d53334dfc31
|
data/.codeclimate.yml
ADDED
data/.gitignore
ADDED
data/.rspec
ADDED
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
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
language: ruby
|
2
|
+
|
3
|
+
rvm:
|
4
|
+
- 2.5.5
|
5
|
+
- 2.6.3
|
6
|
+
- 2.7.0
|
7
|
+
|
8
|
+
env:
|
9
|
+
- RAILS_VERSION="~> 6.0.0"
|
10
|
+
- RAILS_VERSION="~> 5.2.0"
|
11
|
+
|
12
|
+
jobs:
|
13
|
+
include:
|
14
|
+
- rvm: 2.4.6
|
15
|
+
env: RAILS_VERSION="~> 5.2.0"
|
16
|
+
|
17
|
+
services:
|
18
|
+
- mysql
|
19
|
+
|
20
|
+
before_install:
|
21
|
+
- travis_retry sudo apt-key adv --keyserver keys.gnupg.net --recv-keys 8507EFA5
|
22
|
+
- echo "deb http://repo.percona.com/apt `lsb_release -cs` main" | sudo tee -a /etc/apt/sources.list
|
23
|
+
- sudo apt-get update -qq
|
24
|
+
- sudo apt-get install percona-toolkit
|
25
|
+
- gem update bundler
|
26
|
+
|
27
|
+
install: bin/setup
|
28
|
+
|
29
|
+
after_success:
|
30
|
+
- codeclimate-test-reporter
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,192 @@
|
|
1
|
+
# Change Log
|
2
|
+
All notable changes to this project will be documented in this file.
|
3
|
+
This project adheres to [Semantic Versioning](http://semver.org/).
|
4
|
+
|
5
|
+
Please follow the format in [Keep a Changelog](http://keepachangelog.com/)
|
6
|
+
|
7
|
+
## [Unreleased]
|
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
|
+
|
35
|
+
### Added
|
36
|
+
### Changed
|
37
|
+
|
38
|
+
- Permit PERCONA_ARGS to be applied to db:migrate tasks
|
39
|
+
|
40
|
+
### Deprecated
|
41
|
+
### Removed
|
42
|
+
### Fixed
|
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
|
+
|
71
|
+
## [4.0.1] - 2017-08-01
|
72
|
+
|
73
|
+
### Added
|
74
|
+
|
75
|
+
- Support for all pt-osc command-line options, including short forms and array
|
76
|
+
arguments
|
77
|
+
|
78
|
+
### Changed
|
79
|
+
### Deprecated
|
80
|
+
### Removed
|
81
|
+
### Fixed
|
82
|
+
|
83
|
+
## [4.0.0] - 2017-06-12
|
84
|
+
|
85
|
+
### Added
|
86
|
+
### Changed
|
87
|
+
|
88
|
+
- Rename the gem from percona_migrator to departure.
|
89
|
+
|
90
|
+
### Deprecated
|
91
|
+
### Removed
|
92
|
+
|
93
|
+
- Percona_migrator's deprecation warnings when installing and running the gem.
|
94
|
+
|
95
|
+
### Fixed
|
96
|
+
|
97
|
+
## [3.0.0] - 2016-04-07
|
98
|
+
|
99
|
+
### Added
|
100
|
+
|
101
|
+
- Support for ActiveRecord 4.2.x
|
102
|
+
- Support for Mysql2 4.x
|
103
|
+
- Allow passing any `pt-online-schema-change`'s arguments through the
|
104
|
+
`PERCONA_ARGS` env var when executing a migration with `rake db:migrate:up`
|
105
|
+
or `db:migrate:down`.
|
106
|
+
- Allow setting global percona arguments via gem configuration
|
107
|
+
- Filter MySQL's password from logs
|
108
|
+
|
109
|
+
### Changed
|
110
|
+
|
111
|
+
- Enable default pt-online-schema-change replicas discovering mechanism.
|
112
|
+
So far, this was purposely set to `none`. To keep this same behaviour
|
113
|
+
provide the `PERCONA_ARGS=--recursion-method=none` env var when running the
|
114
|
+
migration.
|
115
|
+
|
116
|
+
## [1.0.0] - 2016-11-30
|
117
|
+
|
118
|
+
### Added
|
119
|
+
|
120
|
+
- Show pt-online-schema-change's stdout while the migration is running instead
|
121
|
+
of at then and all at once.
|
122
|
+
- Store pt-online-schema-change's stderr to percona_migrator_error.log in the
|
123
|
+
default Rails tmp folder.
|
124
|
+
- Allow configuring the tmp directory where the error log gets written into,
|
125
|
+
with the `tmp_path` configuration setting.
|
126
|
+
- Support for ActiveRecord 4.0. Adds the following migration methods:
|
127
|
+
- #rename_index, #change_column_null, #add_reference, #remove_reference,
|
128
|
+
#set_field_encoding, #add_timestamps, #remove_timestamps, #rename_table,
|
129
|
+
#rename_column
|
130
|
+
|
131
|
+
## [0.1.0.rc.7] - 2016-09-15
|
132
|
+
|
133
|
+
### Added
|
134
|
+
|
135
|
+
- Toggle pt-online-schema-change's output as well when toggling the migration's
|
136
|
+
verbose option.
|
137
|
+
|
138
|
+
### Changed
|
139
|
+
|
140
|
+
- Enabled pt-online-schema-change's output while running the migration, that got
|
141
|
+
broken in v0.1.0.rc.2
|
142
|
+
|
143
|
+
## [0.1.0.rc.6] - 2016-04-07
|
144
|
+
|
145
|
+
### Added
|
146
|
+
|
147
|
+
- Support non-ddl migrations by implementing the methods for the ActiveRecord
|
148
|
+
quering to work.
|
149
|
+
|
150
|
+
### Changed
|
151
|
+
|
152
|
+
- Refactor the PerconaAdapter to use the Runner as connection client, as all the
|
153
|
+
other adapters.
|
154
|
+
|
155
|
+
## [0.1.0.rc.5] - 2016-03-29
|
156
|
+
|
157
|
+
### Changed
|
158
|
+
|
159
|
+
- Raise a ActiveRecord::StatementInvalid on failed migration. It also provides
|
160
|
+
more detailed error message when possible such as pt-onlin-schema-change
|
161
|
+
being missing.
|
162
|
+
|
163
|
+
## [0.1.0.rc.4] - 2016-03-15
|
164
|
+
|
165
|
+
### Added
|
166
|
+
|
167
|
+
- Support #drop_table
|
168
|
+
- Support for foreing keys in db/schema.rb when using [Foreigner
|
169
|
+
gem](https://github.com/matthuhiggins/foreigner) in Rails 3 apps. This allows to
|
170
|
+
define foreign keys with #execute, but does not provide support for
|
171
|
+
add_foreign_key yet.
|
172
|
+
|
173
|
+
## [0.1.0.rc.3] - 2016-03-10
|
174
|
+
|
175
|
+
### Added
|
176
|
+
|
177
|
+
- Support #execute. Allows to execute raw SQL from the migration
|
178
|
+
|
179
|
+
## [0.1.0.rc.2] - 2016-03-09
|
180
|
+
|
181
|
+
### Added
|
182
|
+
|
183
|
+
- VERBOSE env var in tests. Specially useful for integration tests.
|
184
|
+
- Fix #create_table migration method. Now it does create the table.
|
185
|
+
|
186
|
+
### Changed
|
187
|
+
|
188
|
+
- Use ActiveRecord's logger instead of specifying one in the connection data.
|
189
|
+
|
190
|
+
## [0.1.0.rc.1] - 2016-03-01
|
191
|
+
|
192
|
+
- Initial gem version
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at accounts@redbooth.com. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
|
45
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
46
|
+
version 1.3.0, available at
|
47
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
48
|
+
|
49
|
+
[homepage]: http://contributor-covenant.org
|
50
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
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
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
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.
|
5
|
+
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
8
|
+
in the Software without restriction, including without limitation the rights
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
11
|
+
furnished to do so, subject to the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be included in
|
14
|
+
all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,227 @@
|
|
1
|
+
# Departure [](https://travis-ci.org/departurerb/departure) [](https://codeclimate.com/github/departurerb/departure)
|
2
|
+
|
3
|
+
Departure is an **ActiveRecord connection adapter** that allows running
|
4
|
+
**MySQL online and non-blocking DDL** through `ActiveRecord::Migration` without needing
|
5
|
+
to use a different DSL other than Rails' migrations DSL.
|
6
|
+
|
7
|
+
It uses `pt-online-schema-change` command-line tool of
|
8
|
+
[Percona
|
9
|
+
Toolkit](https://www.percona.com/doc/percona-toolkit/2.0/pt-online-schema-change.html)
|
10
|
+
which runs MySQL alter table statements without downtime.
|
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
|
+
|
20
|
+
## Installation
|
21
|
+
|
22
|
+
Departure relies on `pt-online-schema-change` from [Percona
|
23
|
+
Toolkit](https://www.percona.com/doc/percona-toolkit/2.0/pt-online-schema-change.html)
|
24
|
+
|
25
|
+
### Mac
|
26
|
+
|
27
|
+
`brew install percona-toolkit`
|
28
|
+
|
29
|
+
If when running a migration you see an error like:
|
30
|
+
|
31
|
+
```
|
32
|
+
PerconaMigrator::Error: Cannot connect to MySQL: Cannot connect to MySQL because
|
33
|
+
the Perl DBI module is not installed or not found.
|
34
|
+
```
|
35
|
+
|
36
|
+
You also need to install the DBI and DBD::MySQL modules from `cpan`.
|
37
|
+
|
38
|
+
```
|
39
|
+
$ sudo cpan
|
40
|
+
cpan> install DBI
|
41
|
+
cpan> install DBD::mysql
|
42
|
+
```
|
43
|
+
|
44
|
+
### Linux
|
45
|
+
|
46
|
+
#### Ubuntu/Debian based
|
47
|
+
|
48
|
+
`apt-get install percona-toolkit`
|
49
|
+
|
50
|
+
#### Arch Linux
|
51
|
+
|
52
|
+
`pacman -S percona-toolkit perl-dbd-mysql`
|
53
|
+
|
54
|
+
#### Other distros
|
55
|
+
|
56
|
+
For other Linux distributions check out the [Percona Toolkit download
|
57
|
+
page](https://www.percona.com/downloads/percona-toolkit/) to find the package
|
58
|
+
that fits your distribution.
|
59
|
+
|
60
|
+
You can also get it from [Percona's apt repository](https://www.percona.com/doc/percona-xtradb-cluster/5.5/installation/apt_repo.html)
|
61
|
+
|
62
|
+
Once installed, add this line to your application's Gemfile:
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
gem 'departure'
|
66
|
+
```
|
67
|
+
|
68
|
+
And then execute:
|
69
|
+
|
70
|
+
$ bundle
|
71
|
+
|
72
|
+
Or install it yourself as:
|
73
|
+
|
74
|
+
$ gem install departure
|
75
|
+
|
76
|
+
## Usage
|
77
|
+
|
78
|
+
Once you added it to your app's Gemfile, you can create and run Rails migrations
|
79
|
+
as usual.
|
80
|
+
|
81
|
+
All the `ALTER TABLE` statements will be executed with
|
82
|
+
`pt-online-schema-change`, which will provide additional output to the
|
83
|
+
migration.
|
84
|
+
|
85
|
+
### pt-online-schema-change arguments
|
86
|
+
|
87
|
+
#### with environment variable
|
88
|
+
|
89
|
+
You can specify any `pt-online-schema-change` arguments when running the
|
90
|
+
migration. All what you pass in the PERCONA_ARGS env var, will be bypassed to the
|
91
|
+
binary, overwriting any default values. Note the format is the same as in
|
92
|
+
`pt-online-schema-change`. Check the full list in [Percona Toolkit
|
93
|
+
documentation](https://www.percona.com/doc/percona-toolkit/2.2/pt-online-schema-change.html#options)
|
94
|
+
|
95
|
+
```ruby
|
96
|
+
$ PERCONA_ARGS='--chunk-time=1' bundle exec rake db:migrate:up VERSION=xxx
|
97
|
+
```
|
98
|
+
|
99
|
+
or even mulitple arguments
|
100
|
+
|
101
|
+
```ruby
|
102
|
+
$ PERCONA_ARGS='--chunk-time=1 --critical-load Threads_running=55' bundle exec rake db:migrate:up VERSION=xxx
|
103
|
+
```
|
104
|
+
|
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.
|
107
|
+
|
108
|
+
#### with global configuration
|
109
|
+
|
110
|
+
You can specify any `pt-online-schema-change` arguments in global gem configuration
|
111
|
+
using `global_percona_args` option.
|
112
|
+
|
113
|
+
```ruby
|
114
|
+
Departure.configure do |config|
|
115
|
+
config.global_percona_args = '--chunk-time=1 --critical-load Threads_running=55'
|
116
|
+
end
|
117
|
+
```
|
118
|
+
|
119
|
+
Unlike using `PERCONA_ARGS`, options provided with global configuration will be applied
|
120
|
+
every time sql command is executed via `pt-online-schema-change`.
|
121
|
+
|
122
|
+
Arguments provided in global configuration can be overwritten with `PERCONA_ARGS` env variable.
|
123
|
+
|
124
|
+
We recommend using this option with caution and only when you understand the consequences.
|
125
|
+
|
126
|
+
### LHM support
|
127
|
+
|
128
|
+
If you moved to Soundcloud's [Lhm](https://github.com/soundcloud/lhm) already,
|
129
|
+
we got you covered. Departure overrides Lhm's DSL so that all the alter
|
130
|
+
statements also go through `pt-online-schema-change` as well.
|
131
|
+
|
132
|
+
You can keep your Lhm migrations and start using Rails migration's DSL back
|
133
|
+
again in your next migration.
|
134
|
+
|
135
|
+
## Configuration
|
136
|
+
|
137
|
+
You can override any of the default values from an initializer:
|
138
|
+
|
139
|
+
```ruby
|
140
|
+
Departure.configure do |config|
|
141
|
+
config.tmp_path = '/tmp/'
|
142
|
+
end
|
143
|
+
```
|
144
|
+
|
145
|
+
It's strongly recommended to name it after this gems name, such as
|
146
|
+
`config/initializers/departure.rb`
|
147
|
+
|
148
|
+
### Only enabled on a per-migration basis
|
149
|
+
|
150
|
+
If you wish to only have Departure enabled per-migration, set `config.enabled_by_default = false` in the configure block of your departure initializer.
|
151
|
+
|
152
|
+
Then, add a `uses_departure!` statement in migrations where Departure should be used:
|
153
|
+
|
154
|
+
```ruby
|
155
|
+
class UseDepartureMigration < ActiveRecord::Migration[5.2]
|
156
|
+
uses_departure!
|
157
|
+
|
158
|
+
def up
|
159
|
+
# ...
|
160
|
+
end
|
161
|
+
# ...
|
162
|
+
end
|
163
|
+
```
|
164
|
+
|
165
|
+
## How it works
|
166
|
+
|
167
|
+
When booting your Rails app, Departure extends the
|
168
|
+
`ActiveRecord::Migration#migrate` method to reset the connection and reestablish
|
169
|
+
it using the `DepartureAdapter` instead of the one you defined in your
|
170
|
+
`config/database.yml`.
|
171
|
+
|
172
|
+
Then, when any migration DSL methods such as `add_column` or `create_table` are
|
173
|
+
executed, they all go to the
|
174
|
+
[DepartureAdapter](https://github.com/departurerb/departure/blob/master/lib/active_record/connection_adapters/departure_adapter.rb).
|
175
|
+
There, the methods that require `ALTER TABLE` SQL statements, like `add_column`,
|
176
|
+
are overriden to get executed with
|
177
|
+
[Departure::Runner](https://github.com/departurerb/departure/blob/master/lib/departure/runner.rb),
|
178
|
+
which deals with the `pt-online-schema-change` binary. All the others, like
|
179
|
+
`create_table`, are delegated to the ActiveRecord's built in Mysql2Adapter and
|
180
|
+
so they follow the regular path.
|
181
|
+
|
182
|
+
[Departure::Runner](https://github.com/departurerb/departure/blob/master/lib/departure/runner.rb)
|
183
|
+
spawns a new process that runs the `pt-online-schema-change` binary present in
|
184
|
+
the system, with the appropriate arguments for the generated SQL.
|
185
|
+
|
186
|
+
When any errors occur, an `ActiveRecord::StatementInvalid` exception is
|
187
|
+
raised and the migration is aborted, as all other ActiveRecord connection
|
188
|
+
adapters.
|
189
|
+
|
190
|
+
## Trouleshooting
|
191
|
+
|
192
|
+
### Error creating new table: DBD::mysql::db do failed: Can't write; duplicate key in table (TABLE_NAME)
|
193
|
+
There is a [known bug](https://bugs.launchpad.net/percona-toolkit/+bug/1498128) in percona-toolkit version 2.2.15
|
194
|
+
that prevents schema changes when a table has constraints. You should upgrade to a version later than 2.2.17 to fix the issue.
|
195
|
+
|
196
|
+
## Development
|
197
|
+
|
198
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
199
|
+
`rake spec` to run the tests. You can also run `bin/console` for an interactive
|
200
|
+
prompt that will allow you to experiment.
|
201
|
+
|
202
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To
|
203
|
+
release a new version, update the version number in `version.rb`, and then run
|
204
|
+
`bundle exec rake release`, which will create a git tag for the version, push
|
205
|
+
git commits and tags, and push the `.gem` file to
|
206
|
+
[rubygems.org](https://rubygems.org).
|
207
|
+
|
208
|
+
## Contributing
|
209
|
+
|
210
|
+
Bug reports and pull requests are welcome on GitHub at
|
211
|
+
https://github.com/departurerb/departure. They need to be opened against
|
212
|
+
`master` or `v3.2` only if the changes fix a bug in Rails 3.2 apps.
|
213
|
+
|
214
|
+
Please note that this project is released with a Contributor Code of Conduct. By
|
215
|
+
participating in this project you agree to abide by its terms.
|
216
|
+
|
217
|
+
Check the code of conduct [here](CODE_OF_CONDUCT.md)
|
218
|
+
|
219
|
+
## Changelog
|
220
|
+
|
221
|
+
You can consult the changelog [here](CHANGELOG.md)
|
222
|
+
|
223
|
+
## License
|
224
|
+
|
225
|
+
The gem is available as open source under the terms of the [MIT
|
226
|
+
License](http://opensource.org/licenses/MIT).
|
227
|
+
|