departure-next 6.7.1.pre.pre
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 +7 -0
- data/.github/workflows/test.yml +54 -0
- data/.gitignore +14 -0
- data/.pryrc +11 -0
- data/.rspec +2 -0
- data/.rubocop.yml +66 -0
- data/.rubocop_todo.yml +238 -0
- data/20250312235906_add_deleted_reason_to_newsfeed_activities.rb +5 -0
- data/Appraisals +15 -0
- data/CHANGELOG.md +224 -0
- data/CODE_OF_CONDUCT.md +50 -0
- data/Dockerfile +32 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +206 -0
- data/LICENSE.txt +22 -0
- data/README.md +246 -0
- data/RELEASING.md +17 -0
- data/Rakefile +25 -0
- data/bin/console +14 -0
- data/bin/rails +24 -0
- data/bin/rspec +16 -0
- data/bin/setup +7 -0
- data/config.yml.erb +5 -0
- data/configuration.rb +16 -0
- data/departure-next.gemspec +34 -0
- data/docker-compose.yml +23 -0
- data/gemfiles/rails_6_1.gemfile +10 -0
- data/gemfiles/rails_6_1.gemfile.lock +243 -0
- data/gemfiles/rails_7_0.gemfile +10 -0
- data/gemfiles/rails_7_0.gemfile.lock +242 -0
- data/gemfiles/rails_7_1.gemfile +10 -0
- data/gemfiles/rails_7_1.gemfile.lock +274 -0
- data/gemfiles/rails_7_2.gemfile +10 -0
- data/gemfiles/rails_7_2.gemfile.lock +274 -0
- data/lib/active_record/connection_adapters/for_alter.rb +103 -0
- data/lib/active_record/connection_adapters/patch_connection_handling.rb +18 -0
- data/lib/active_record/connection_adapters/percona_adapter.rb +187 -0
- data/lib/active_record/connection_adapters/rails_7_2_departure_adapter.rb +218 -0
- data/lib/departure/alter_argument.rb +49 -0
- data/lib/departure/cli_generator.rb +84 -0
- data/lib/departure/command.rb +105 -0
- data/lib/departure/configuration.rb +21 -0
- data/lib/departure/connection_base.rb +11 -0
- data/lib/departure/connection_details.rb +121 -0
- data/lib/departure/dsn.rb +25 -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 +104 -0
- data/lib/departure/null_logger.rb +15 -0
- data/lib/departure/option.rb +75 -0
- data/lib/departure/rails_adapter.rb +97 -0
- data/lib/departure/railtie.rb +21 -0
- data/lib/departure/runner.rb +75 -0
- data/lib/departure/user_options.rb +44 -0
- data/lib/departure/version.rb +3 -0
- data/lib/departure.rb +40 -0
- data/lib/lhm/adapter.rb +107 -0
- data/lib/lhm/column_with_sql.rb +89 -0
- data/lib/lhm/column_with_type.rb +29 -0
- data/lib/lhm.rb +23 -0
- data/test_database.rb +76 -0
- metadata +282 -0
data/Dockerfile
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
FROM ruby:3.0
|
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
@@ -0,0 +1,11 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gemspec
|
4
|
+
|
5
|
+
gem 'base64'
|
6
|
+
gem 'codeclimate-test-reporter', '~> 1.0.3', group: :test, require: nil
|
7
|
+
gem 'lhm'
|
8
|
+
gem 'logger'
|
9
|
+
gem 'mutex_m', require: false
|
10
|
+
gem 'rubocop', '~> 1.60.2', require: false
|
11
|
+
gem 'rubocop-performance', '~> 1.20.2', require: false
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,206 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
departure-next (6.7.1.pre.pre)
|
5
|
+
activerecord (>= 6.0.0, < 7.3.0, != 7.0.0)
|
6
|
+
mysql2 (>= 0.4.0, < 0.6.0)
|
7
|
+
railties (>= 6.0.0, < 7.3.0, != 7.0.0)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
actionpack (7.1.3)
|
13
|
+
actionview (= 7.1.3)
|
14
|
+
activesupport (= 7.1.3)
|
15
|
+
nokogiri (>= 1.8.5)
|
16
|
+
racc
|
17
|
+
rack (>= 2.2.4)
|
18
|
+
rack-session (>= 1.0.1)
|
19
|
+
rack-test (>= 0.6.3)
|
20
|
+
rails-dom-testing (~> 2.2)
|
21
|
+
rails-html-sanitizer (~> 1.6)
|
22
|
+
actionview (7.1.3)
|
23
|
+
activesupport (= 7.1.3)
|
24
|
+
builder (~> 3.1)
|
25
|
+
erubi (~> 1.11)
|
26
|
+
rails-dom-testing (~> 2.2)
|
27
|
+
rails-html-sanitizer (~> 1.6)
|
28
|
+
activemodel (7.1.3)
|
29
|
+
activesupport (= 7.1.3)
|
30
|
+
activerecord (7.1.3)
|
31
|
+
activemodel (= 7.1.3)
|
32
|
+
activesupport (= 7.1.3)
|
33
|
+
timeout (>= 0.4.0)
|
34
|
+
activesupport (7.1.3)
|
35
|
+
base64
|
36
|
+
bigdecimal
|
37
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
38
|
+
connection_pool (>= 2.2.5)
|
39
|
+
drb
|
40
|
+
i18n (>= 1.6, < 2)
|
41
|
+
minitest (>= 5.1)
|
42
|
+
mutex_m
|
43
|
+
tzinfo (~> 2.0)
|
44
|
+
appraisal (2.4.1)
|
45
|
+
bundler
|
46
|
+
rake
|
47
|
+
thor (>= 0.14.0)
|
48
|
+
ast (2.4.2)
|
49
|
+
base64 (0.2.0)
|
50
|
+
bigdecimal (3.1.6)
|
51
|
+
builder (3.3.0)
|
52
|
+
byebug (11.1.3)
|
53
|
+
climate_control (0.0.4)
|
54
|
+
activesupport (>= 3.0)
|
55
|
+
codeclimate-test-reporter (1.0.9)
|
56
|
+
simplecov (<= 0.13)
|
57
|
+
coderay (1.1.3)
|
58
|
+
concurrent-ruby (1.2.3)
|
59
|
+
connection_pool (2.4.1)
|
60
|
+
crass (1.0.6)
|
61
|
+
date (3.4.1)
|
62
|
+
diff-lcs (1.5.1)
|
63
|
+
docile (1.1.5)
|
64
|
+
drb (2.2.0)
|
65
|
+
ruby2_keywords
|
66
|
+
erubi (1.13.1)
|
67
|
+
i18n (1.14.1)
|
68
|
+
concurrent-ruby (~> 1.0)
|
69
|
+
io-console (0.8.0)
|
70
|
+
irb (1.15.1)
|
71
|
+
pp (>= 0.6.0)
|
72
|
+
rdoc (>= 4.0.0)
|
73
|
+
reline (>= 0.4.2)
|
74
|
+
json (2.7.1)
|
75
|
+
language_server-protocol (3.17.0.3)
|
76
|
+
lhm (2.2.0)
|
77
|
+
logger (1.6.6)
|
78
|
+
loofah (2.24.0)
|
79
|
+
crass (~> 1.0.2)
|
80
|
+
nokogiri (>= 1.12.0)
|
81
|
+
method_source (1.0.0)
|
82
|
+
minitest (5.22.2)
|
83
|
+
mutex_m (0.2.0)
|
84
|
+
mysql2 (0.5.6)
|
85
|
+
nokogiri (1.18.3-x86_64-linux-gnu)
|
86
|
+
racc (~> 1.4)
|
87
|
+
parallel (1.24.0)
|
88
|
+
parser (3.3.0.5)
|
89
|
+
ast (~> 2.4.1)
|
90
|
+
racc
|
91
|
+
pp (0.6.2)
|
92
|
+
prettyprint
|
93
|
+
prettyprint (0.2.0)
|
94
|
+
pry (0.14.2)
|
95
|
+
coderay (~> 1.1)
|
96
|
+
method_source (~> 1.0)
|
97
|
+
pry-byebug (3.10.1)
|
98
|
+
byebug (~> 11.0)
|
99
|
+
pry (>= 0.13, < 0.15)
|
100
|
+
psych (5.2.3)
|
101
|
+
date
|
102
|
+
stringio
|
103
|
+
racc (1.7.3)
|
104
|
+
rack (3.1.11)
|
105
|
+
rack-session (2.1.0)
|
106
|
+
base64 (>= 0.1.0)
|
107
|
+
rack (>= 3.0.0)
|
108
|
+
rack-test (2.2.0)
|
109
|
+
rack (>= 1.3)
|
110
|
+
rackup (2.2.1)
|
111
|
+
rack (>= 3)
|
112
|
+
rails-dom-testing (2.2.0)
|
113
|
+
activesupport (>= 5.0.0)
|
114
|
+
minitest
|
115
|
+
nokogiri (>= 1.6)
|
116
|
+
rails-html-sanitizer (1.6.2)
|
117
|
+
loofah (~> 2.21)
|
118
|
+
nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
|
119
|
+
railties (7.1.3)
|
120
|
+
actionpack (= 7.1.3)
|
121
|
+
activesupport (= 7.1.3)
|
122
|
+
irb
|
123
|
+
rackup (>= 1.0.0)
|
124
|
+
rake (>= 12.2)
|
125
|
+
thor (~> 1.0, >= 1.2.2)
|
126
|
+
zeitwerk (~> 2.6)
|
127
|
+
rainbow (3.1.1)
|
128
|
+
rake (13.1.0)
|
129
|
+
rdoc (6.12.0)
|
130
|
+
psych (>= 4.0.0)
|
131
|
+
regexp_parser (2.9.0)
|
132
|
+
reline (0.6.0)
|
133
|
+
io-console (~> 0.5)
|
134
|
+
rexml (3.2.6)
|
135
|
+
rspec (3.13.0)
|
136
|
+
rspec-core (~> 3.13.0)
|
137
|
+
rspec-expectations (~> 3.13.0)
|
138
|
+
rspec-mocks (~> 3.13.0)
|
139
|
+
rspec-core (3.13.0)
|
140
|
+
rspec-support (~> 3.13.0)
|
141
|
+
rspec-expectations (3.13.0)
|
142
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
143
|
+
rspec-support (~> 3.13.0)
|
144
|
+
rspec-its (1.3.0)
|
145
|
+
rspec-core (>= 3.0.0)
|
146
|
+
rspec-expectations (>= 3.0.0)
|
147
|
+
rspec-mocks (3.13.0)
|
148
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
149
|
+
rspec-support (~> 3.13.0)
|
150
|
+
rspec-support (3.13.0)
|
151
|
+
rubocop (1.60.2)
|
152
|
+
json (~> 2.3)
|
153
|
+
language_server-protocol (>= 3.17.0)
|
154
|
+
parallel (~> 1.10)
|
155
|
+
parser (>= 3.3.0.2)
|
156
|
+
rainbow (>= 2.2.2, < 4.0)
|
157
|
+
regexp_parser (>= 1.8, < 3.0)
|
158
|
+
rexml (>= 3.2.5, < 4.0)
|
159
|
+
rubocop-ast (>= 1.30.0, < 2.0)
|
160
|
+
ruby-progressbar (~> 1.7)
|
161
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
162
|
+
rubocop-ast (1.30.0)
|
163
|
+
parser (>= 3.2.1.0)
|
164
|
+
rubocop-performance (1.20.2)
|
165
|
+
rubocop (>= 1.48.1, < 2.0)
|
166
|
+
rubocop-ast (>= 1.30.0, < 2.0)
|
167
|
+
ruby-progressbar (1.13.0)
|
168
|
+
ruby2_keywords (0.0.5)
|
169
|
+
simplecov (0.13.0)
|
170
|
+
docile (~> 1.1.0)
|
171
|
+
json (>= 1.8, < 3)
|
172
|
+
simplecov-html (~> 0.10.0)
|
173
|
+
simplecov-html (0.10.2)
|
174
|
+
stringio (3.1.5)
|
175
|
+
thor (1.3.0)
|
176
|
+
timeout (0.4.3)
|
177
|
+
tzinfo (2.0.6)
|
178
|
+
concurrent-ruby (~> 1.0)
|
179
|
+
unicode-display_width (2.5.0)
|
180
|
+
zeitwerk (2.6.18)
|
181
|
+
|
182
|
+
PLATFORMS
|
183
|
+
arm64-darwin-21
|
184
|
+
arm64-darwin-22
|
185
|
+
arm64-darwin-23
|
186
|
+
arm64-darwin-24
|
187
|
+
x86_64-linux
|
188
|
+
|
189
|
+
DEPENDENCIES
|
190
|
+
appraisal (~> 2.4.1)
|
191
|
+
base64
|
192
|
+
climate_control (~> 0.0.3)
|
193
|
+
codeclimate-test-reporter (~> 1.0.3)
|
194
|
+
departure-next!
|
195
|
+
lhm
|
196
|
+
logger
|
197
|
+
mutex_m
|
198
|
+
pry-byebug
|
199
|
+
rake (>= 10.0)
|
200
|
+
rspec (~> 3.4, >= 3.4.0)
|
201
|
+
rspec-its (~> 1.2)
|
202
|
+
rubocop (~> 1.60.2)
|
203
|
+
rubocop-performance (~> 1.20.2)
|
204
|
+
|
205
|
+
BUNDLED WITH
|
206
|
+
2.4.22
|
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,246 @@
|
|
1
|
+
# Departure
|
2
|
+
|
3
|
+
  
|
4
|
+
|
5
|
+
Departure is an **ActiveRecord connection adapter** that allows running
|
6
|
+
**MySQL online and non-blocking DDL** through `ActiveRecord::Migration` without needing
|
7
|
+
to use a different DSL other than Rails' migrations DSL.
|
8
|
+
|
9
|
+
It uses `pt-online-schema-change` command-line tool of
|
10
|
+
[Percona
|
11
|
+
Toolkit](https://www.percona.com/doc/percona-toolkit/2.0/pt-online-schema-change.html)
|
12
|
+
which runs MySQL alter table statements without downtime.
|
13
|
+
|
14
|
+
## Rename from "Percona Migrator"
|
15
|
+
|
16
|
+
This project was formerly known as "Percona Migrator", but this incurs in an
|
17
|
+
infringement of Percona's trade mark policy and thus has to be renamed. Said
|
18
|
+
name is likely to cause confusion as to the source of the wrapper.
|
19
|
+
|
20
|
+
The next major versions will use "Departure" as gem name.
|
21
|
+
|
22
|
+
## Installation
|
23
|
+
|
24
|
+
Departure relies on `pt-online-schema-change` from [Percona
|
25
|
+
Toolkit](https://www.percona.com/doc/percona-toolkit/2.0/pt-online-schema-change.html)
|
26
|
+
|
27
|
+
### Mac
|
28
|
+
|
29
|
+
`brew install percona-toolkit`
|
30
|
+
|
31
|
+
If when running a migration you see an error like:
|
32
|
+
|
33
|
+
```
|
34
|
+
PerconaMigrator::Error: Cannot connect to MySQL: Cannot connect to MySQL because
|
35
|
+
the Perl DBI module is not installed or not found.
|
36
|
+
```
|
37
|
+
|
38
|
+
You also need to install the DBI and DBD::MySQL modules from `cpan`.
|
39
|
+
|
40
|
+
```
|
41
|
+
$ sudo cpan
|
42
|
+
cpan> install DBI
|
43
|
+
cpan> install DBD::mysql
|
44
|
+
```
|
45
|
+
|
46
|
+
### Linux
|
47
|
+
|
48
|
+
#### Ubuntu/Debian based
|
49
|
+
|
50
|
+
`apt-get install percona-toolkit`
|
51
|
+
|
52
|
+
#### Arch Linux
|
53
|
+
|
54
|
+
`pacman -S percona-toolkit perl-dbd-mysql`
|
55
|
+
|
56
|
+
#### Other distros
|
57
|
+
|
58
|
+
For other Linux distributions check out the [Percona Toolkit download
|
59
|
+
page](https://www.percona.com/downloads/percona-toolkit/) to find the package
|
60
|
+
that fits your distribution.
|
61
|
+
|
62
|
+
You can also get it from [Percona's apt repository](https://www.percona.com/doc/percona-xtradb-cluster/5.5/installation/apt_repo.html)
|
63
|
+
|
64
|
+
Once installed, add this line to your application's Gemfile:
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
gem 'departure'
|
68
|
+
```
|
69
|
+
|
70
|
+
And then execute:
|
71
|
+
|
72
|
+
$ bundle
|
73
|
+
|
74
|
+
Or install it yourself as:
|
75
|
+
|
76
|
+
$ gem install departure
|
77
|
+
|
78
|
+
## Usage
|
79
|
+
|
80
|
+
Once you added it to your app's Gemfile, you can create and run Rails migrations
|
81
|
+
as usual.
|
82
|
+
|
83
|
+
All the `ALTER TABLE` statements will be executed with
|
84
|
+
`pt-online-schema-change`, which will provide additional output to the
|
85
|
+
migration.
|
86
|
+
|
87
|
+
### pt-online-schema-change arguments
|
88
|
+
|
89
|
+
#### with environment variable
|
90
|
+
|
91
|
+
You can specify any `pt-online-schema-change` arguments when running the
|
92
|
+
migration. All what you pass in the PERCONA_ARGS env var, will be bypassed to the
|
93
|
+
binary, overwriting any default values. Note the format is the same as in
|
94
|
+
`pt-online-schema-change`. Check the full list in [Percona Toolkit
|
95
|
+
documentation](https://www.percona.com/doc/percona-toolkit/2.2/pt-online-schema-change.html#options)
|
96
|
+
|
97
|
+
```ruby
|
98
|
+
$ PERCONA_ARGS='--chunk-time=1' bundle exec rake db:migrate:up VERSION=xxx
|
99
|
+
```
|
100
|
+
|
101
|
+
or even mulitple arguments
|
102
|
+
|
103
|
+
```ruby
|
104
|
+
$ PERCONA_ARGS='--chunk-time=1 --critical-load Threads_running=55' bundle exec rake db:migrate:up VERSION=xxx
|
105
|
+
```
|
106
|
+
|
107
|
+
Use caution when using PERCONA_ARGS with `db:migrate`, as your args will be applied
|
108
|
+
to every call that Departure makes to pt-osc.
|
109
|
+
|
110
|
+
#### with global configuration
|
111
|
+
|
112
|
+
You can specify any `pt-online-schema-change` arguments in global gem configuration
|
113
|
+
using `global_percona_args` option.
|
114
|
+
|
115
|
+
```ruby
|
116
|
+
Departure.configure do |config|
|
117
|
+
config.global_percona_args = '--chunk-time=1 --critical-load Threads_running=55'
|
118
|
+
end
|
119
|
+
```
|
120
|
+
|
121
|
+
Unlike using `PERCONA_ARGS`, options provided with global configuration will be applied
|
122
|
+
every time sql command is executed via `pt-online-schema-change`.
|
123
|
+
|
124
|
+
Arguments provided in global configuration can be overwritten with `PERCONA_ARGS` env variable.
|
125
|
+
|
126
|
+
We recommend using this option with caution and only when you understand the consequences.
|
127
|
+
|
128
|
+
### LHM support
|
129
|
+
|
130
|
+
If you moved to Soundcloud's [Lhm](https://github.com/soundcloud/lhm) already,
|
131
|
+
we got you covered. Departure overrides Lhm's DSL so that all the alter
|
132
|
+
statements also go through `pt-online-schema-change` as well.
|
133
|
+
|
134
|
+
You can keep your Lhm migrations and start using Rails migration's DSL back
|
135
|
+
again in your next migration.
|
136
|
+
|
137
|
+
## Configuration
|
138
|
+
|
139
|
+
You can override any of the default values from an initializer:
|
140
|
+
|
141
|
+
```ruby
|
142
|
+
Departure.configure do |config|
|
143
|
+
config.tmp_path = '/tmp/'
|
144
|
+
end
|
145
|
+
```
|
146
|
+
|
147
|
+
It's strongly recommended to name it after this gems name, such as
|
148
|
+
`config/initializers/departure.rb`
|
149
|
+
|
150
|
+
### Disable on per-migration basis
|
151
|
+
|
152
|
+
Departure gem is enabled by default.
|
153
|
+
In order to disable it on a particular migration the method `disable_departure!` should be used.
|
154
|
+
|
155
|
+
```ruby
|
156
|
+
class UseDepartureMigration < ActiveRecord::Migration[7.1]
|
157
|
+
disable_departure!
|
158
|
+
|
159
|
+
def up
|
160
|
+
# ...
|
161
|
+
end
|
162
|
+
# ...
|
163
|
+
end
|
164
|
+
```
|
165
|
+
|
166
|
+
### Enable on per-migration basis
|
167
|
+
|
168
|
+
If you wish to only have Departure enabled per-migration, set `config.enabled_by_default = false` in the configure block of your departure initializer.
|
169
|
+
|
170
|
+
Then, add a `uses_departure!` statement in migrations where Departure should be used:
|
171
|
+
|
172
|
+
```ruby
|
173
|
+
class UseDepartureMigration < ActiveRecord::Migration[7.1]
|
174
|
+
uses_departure!
|
175
|
+
|
176
|
+
def up
|
177
|
+
# ...
|
178
|
+
end
|
179
|
+
# ...
|
180
|
+
end
|
181
|
+
```
|
182
|
+
|
183
|
+
## How it works
|
184
|
+
|
185
|
+
When booting your Rails app, Departure extends the
|
186
|
+
`ActiveRecord::Migration#migrate` method to reset the connection and reestablish
|
187
|
+
it using the `DepartureAdapter` instead of the one you defined in your
|
188
|
+
`config/database.yml`.
|
189
|
+
|
190
|
+
Then, when any migration DSL methods such as `add_column` or `create_table` are
|
191
|
+
executed, they all go to the
|
192
|
+
[DepartureAdapter](https://github.com/departurerb/departure/blob/master/lib/active_record/connection_adapters/departure_adapter.rb).
|
193
|
+
There, the methods that require `ALTER TABLE` SQL statements, like `add_column`,
|
194
|
+
are overriden to get executed with
|
195
|
+
[Departure::Runner](https://github.com/departurerb/departure/blob/master/lib/departure/runner.rb),
|
196
|
+
which deals with the `pt-online-schema-change` binary. All the others, like
|
197
|
+
`create_table`, are delegated to the ActiveRecord's built in Mysql2Adapter and
|
198
|
+
so they follow the regular path.
|
199
|
+
|
200
|
+
[Departure::Runner](https://github.com/departurerb/departure/blob/master/lib/departure/runner.rb)
|
201
|
+
spawns a new process that runs the `pt-online-schema-change` binary present in
|
202
|
+
the system, with the appropriate arguments for the generated SQL.
|
203
|
+
|
204
|
+
When any errors occur, an `ActiveRecord::StatementInvalid` exception is
|
205
|
+
raised and the migration is aborted, as all other ActiveRecord connection
|
206
|
+
adapters.
|
207
|
+
|
208
|
+
## Trouleshooting
|
209
|
+
|
210
|
+
### Error creating new table: DBD::mysql::db do failed: Can't write; duplicate key in table (TABLE_NAME)
|
211
|
+
There is a [known bug](https://bugs.launchpad.net/percona-toolkit/+bug/1498128) in percona-toolkit version 2.2.15
|
212
|
+
that prevents schema changes when a table has constraints. You should upgrade to a version later than 2.2.17 to fix the issue.
|
213
|
+
|
214
|
+
## Development
|
215
|
+
|
216
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
217
|
+
`rake spec` to run the tests. You can also run `bin/console` for an interactive
|
218
|
+
prompt that will allow you to experiment.
|
219
|
+
|
220
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To
|
221
|
+
release a new version, update the version number in `version.rb`, and then run
|
222
|
+
`bundle exec rake release`, which will create a git tag for the version, push
|
223
|
+
git commits and tags, and push the `.gem` file to
|
224
|
+
[rubygems.org](https://rubygems.org).
|
225
|
+
|
226
|
+
## Contributing
|
227
|
+
|
228
|
+
Bug reports and pull requests are welcome on GitHub at
|
229
|
+
https://github.com/departurerb/departure.
|
230
|
+
|
231
|
+
Please note that this project is released with a Contributor Code of Conduct. By
|
232
|
+
participating in this project you agree to abide by its terms.
|
233
|
+
|
234
|
+
Check the code of conduct [here](CODE_OF_CONDUCT.md)
|
235
|
+
|
236
|
+
## Changelog
|
237
|
+
|
238
|
+
You can consult the changelog [here](CHANGELOG.md)
|
239
|
+
|
240
|
+
## License
|
241
|
+
|
242
|
+
The gem is available as open source under the terms of the [MIT
|
243
|
+
License](http://opensource.org/licenses/MIT).
|
244
|
+
|
245
|
+

|
246
|
+

|
data/RELEASING.md
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# Releasing Departure
|
2
|
+
|
3
|
+
All releases come from the master branch. All other branches won't be maintained
|
4
|
+
and will receive bug fix releases only.
|
5
|
+
|
6
|
+
In order to give support to a new major Rails version, we'll branch off of
|
7
|
+
master, name it following the Rails repo convention, such as `v4.2`, and
|
8
|
+
we'll keep it open for bug fixes.
|
9
|
+
|
10
|
+
1. Update `lib/departure/version.rb` accordingly
|
11
|
+
2. Review the `CHANGELOG.md` and add a new section following the format
|
12
|
+
`[version] - YYYY-MM-DD`. We conform to the guidelines of
|
13
|
+
http://keepachangelog.com/
|
14
|
+
3. Commit the changes with the message `Prepare release VERSION`
|
15
|
+
4. Execute the release rake task as `bundle exec rake release`. It creates the
|
16
|
+
tag, builds and pushes the gem to Rubygems.
|
17
|
+
5. Announce it! :tada:
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
|
4
|
+
require './configuration'
|
5
|
+
require './test_database'
|
6
|
+
|
7
|
+
RSpec::Core::RakeTask.new(:spec)
|
8
|
+
|
9
|
+
task default: :spec
|
10
|
+
|
11
|
+
namespace :db do
|
12
|
+
desc 'Create the test database'
|
13
|
+
task :create do
|
14
|
+
config = Configuration.new
|
15
|
+
|
16
|
+
ActiveRecord::Base.establish_connection(
|
17
|
+
adapter: 'mysql2',
|
18
|
+
host: config['hostname'],
|
19
|
+
username: config['username'],
|
20
|
+
password: config['password']
|
21
|
+
)
|
22
|
+
|
23
|
+
TestDatabase.new(config).setup_test_database
|
24
|
+
end
|
25
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'departure'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start
|
data/bin/rails
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
ENV['RAILS_ENV'] ||= 'development'
|
4
|
+
|
5
|
+
APP_PATH = File.expand_path('../spec/dummy/config/application', __dir__)
|
6
|
+
require_relative '../spec/dummy/config/boot'
|
7
|
+
require 'rake'
|
8
|
+
require 'departure'
|
9
|
+
|
10
|
+
# Load the rails application
|
11
|
+
require APP_PATH
|
12
|
+
|
13
|
+
begin
|
14
|
+
Rails.application.load_tasks
|
15
|
+
Rake::Task['db:create'].invoke
|
16
|
+
|
17
|
+
ENV['SCHEMA'] = File.expand_path('../spec/dummy/db/base_schema.rb', __dir__)
|
18
|
+
Rake::Task['db:schema:load'].invoke
|
19
|
+
rescue StandardError => e
|
20
|
+
puts "there was an error creating your database #{e}"
|
21
|
+
exit 1
|
22
|
+
end
|
23
|
+
|
24
|
+
require 'rails/commands'
|
data/bin/rspec
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
# This file was generated by Bundler.
|
5
|
+
#
|
6
|
+
# The application 'rspec' is installed as part of a gem, and
|
7
|
+
# this file is here to facilitate running it.
|
8
|
+
#
|
9
|
+
|
10
|
+
require 'pathname'
|
11
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require 'rubygems'
|
14
|
+
require 'bundler/setup'
|
15
|
+
|
16
|
+
load Gem.bin_path('rspec-core', 'rspec')
|
data/bin/setup
ADDED
data/config.yml.erb
ADDED
@@ -0,0 +1,5 @@
|
|
1
|
+
username: <%= ENV['PERCONA_DB_USER'] || 'root' %>
|
2
|
+
password: <%= ENV['PERCONA_DB_PASSWORD'] || 'password' %>
|
3
|
+
database: <%= ENV['PERCONA_DB_NAME'] || 'departure_test' %>
|
4
|
+
hostname: <%= ENV['PERCONA_DB_HOST'] || 'localhost' %>
|
5
|
+
socket: <%= ENV['PERCONA_DB_SOCKET'] || '' %>
|
data/configuration.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'erb'
|
3
|
+
|
4
|
+
class Configuration
|
5
|
+
CONFIG_PATH = 'config.yml.erb'.freeze
|
6
|
+
|
7
|
+
attr_reader :config
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@config = YAML.load(ERB.new(File.read(CONFIG_PATH)).result).freeze
|
11
|
+
end
|
12
|
+
|
13
|
+
def [](key)
|
14
|
+
config[key]
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
|
6
|
+
require 'departure/version'
|
7
|
+
|
8
|
+
Gem::Specification.new do |spec|
|
9
|
+
spec.name = 'departure-next'
|
10
|
+
spec.version = Departure::VERSION
|
11
|
+
spec.authors = ['Ilya Zayats', 'Pau Pérez', 'Fran Casas', 'Jorge Morante', 'Enrico Stano', 'Adrian Serafin', 'Kirk Haines', 'Guillermo Iguaran']
|
12
|
+
spec.email = ['ilya.zayats@redbooth.com', 'pau.perez@redbooth.com', 'nflamel@gmail.com', 'jorge.morante@redbooth.com', 'adrian@softmad.pl', 'wyhaines@gmail.com', 'guilleiguaran@gmail.com']
|
13
|
+
|
14
|
+
spec.summary = %q(pt-online-schema-change runner for ActiveRecord migrations)
|
15
|
+
spec.description = %q(Execute your ActiveRecord migrations with Percona's pt-online-schema-change. Formerly known as Percona Migrator.)
|
16
|
+
spec.homepage = 'https://github.com/departurerb/departure'
|
17
|
+
spec.license = 'MIT'
|
18
|
+
|
19
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
|
22
|
+
spec.required_ruby_version = '>= 2.7.0'
|
23
|
+
|
24
|
+
spec.add_runtime_dependency 'railties', '>= 6.0.0', '!= 7.0.0', '< 7.3.0'
|
25
|
+
spec.add_runtime_dependency 'activerecord', '>= 6.0.0', '!= 7.0.0', '< 7.3.0'
|
26
|
+
spec.add_runtime_dependency 'mysql2', '>= 0.4.0', '< 0.6.0'
|
27
|
+
|
28
|
+
spec.add_development_dependency 'appraisal', '~> 2.4.1'
|
29
|
+
spec.add_development_dependency 'rake', '>= 10.0'
|
30
|
+
spec.add_development_dependency 'rspec', '~> 3.4', '>= 3.4.0'
|
31
|
+
spec.add_development_dependency 'rspec-its', '~> 1.2'
|
32
|
+
spec.add_development_dependency 'pry-byebug'
|
33
|
+
spec.add_development_dependency 'climate_control', '~> 0.0.3'
|
34
|
+
end
|