departure 7.0.0 → 8.1.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 +4 -4
- data/.github/workflows/test.yml +41 -5
- data/AGENTS.md +75 -0
- data/Appraisals +7 -8
- data/CHANGELOG.md +22 -0
- data/Dockerfile +4 -11
- data/Gemfile.lock +8 -5
- data/README.md +127 -3
- data/config.yml.erb +8 -4
- data/departure.gemspec +5 -6
- data/docker-compose.yml +4 -0
- data/gemfiles/rails_7_2.gemfile +1 -0
- data/gemfiles/rails_7_2.gemfile.lock +78 -53
- data/gemfiles/rails_8_0.gemfile +2 -0
- data/gemfiles/rails_8_0.gemfile.lock +82 -53
- data/gemfiles/{rails_7_1.gemfile → rails_8_1.gemfile} +2 -1
- data/gemfiles/{rails_7_0.gemfile.lock → rails_8_1.gemfile.lock} +138 -111
- data/lib/active_record/connection_adapters/for_alter.rb +0 -6
- data/lib/active_record/connection_adapters/patch_connection_handling.rb +6 -5
- data/lib/active_record/connection_adapters/rails_8_0_departure_adapter.rb +5 -1
- data/lib/active_record/connection_adapters/rails_8_1_adapter_behavior.rb +64 -0
- data/lib/active_record/connection_adapters/rails_8_1_mysql2_adapter.rb +23 -0
- data/lib/active_record/connection_adapters/rails_8_1_trilogy_adapter.rb +21 -0
- data/lib/departure/db_client.rb +52 -0
- data/lib/departure/migration.rb +40 -10
- data/lib/departure/rails_adapter.rb +112 -56
- data/lib/departure/railtie.rb +2 -0
- data/lib/departure/runner.rb +6 -1
- data/lib/departure/version.rb +1 -1
- data/lib/departure.rb +1 -2
- data/lib/lhm/column_with_sql.rb +6 -5
- metadata +20 -14
- data/gemfiles/rails_7_0.gemfile +0 -16
- data/gemfiles/rails_7_1.gemfile.lock +0 -290
- data/lib/active_record/connection_adapters/percona_adapter.rb +0 -173
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7c430a93842e6abdfa3f64de47ae938c782d53bbaba75ba532baee057b25d471
|
|
4
|
+
data.tar.gz: 0eeaaeaa8a9d6cf83885ab94b4ad1aae833d73f1fd1f9da87414476f5eede157
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4e0b56e69008ab1885216db89d106775ef10198819d2da007476820921c8c382c79aba3d63637a99276c321723112796936b03b5b099db3a629bbe80d9da21f4
|
|
7
|
+
data.tar.gz: d9de074bdaa985d016e83ad61745e3c77930e9262bc5dea7e4d7a5b9db75d86c66db9f2929d14f474f91f1ffbb3397a553b6c4e60fc0c5dd2e9800db15a04ee6
|
data/.github/workflows/test.yml
CHANGED
|
@@ -3,7 +3,7 @@ name: Test
|
|
|
3
3
|
on: [push, pull_request]
|
|
4
4
|
|
|
5
5
|
jobs:
|
|
6
|
-
|
|
6
|
+
test_mysql:
|
|
7
7
|
strategy:
|
|
8
8
|
fail-fast: false
|
|
9
9
|
matrix:
|
|
@@ -12,10 +12,9 @@ jobs:
|
|
|
12
12
|
- 3.3
|
|
13
13
|
- 3.4
|
|
14
14
|
gemfile:
|
|
15
|
-
- gemfiles/rails_7_0.gemfile
|
|
16
|
-
- gemfiles/rails_7_1.gemfile
|
|
17
15
|
- gemfiles/rails_7_2.gemfile
|
|
18
16
|
- gemfiles/rails_8_0.gemfile
|
|
17
|
+
- gemfiles/rails_8_1.gemfile
|
|
19
18
|
env:
|
|
20
19
|
PERCONA_DB_USER: root
|
|
21
20
|
PERCONA_DB_PASSWORD: root
|
|
@@ -37,18 +36,55 @@ jobs:
|
|
|
37
36
|
run: sudo systemctl start mysql.service
|
|
38
37
|
- run: bin/setup
|
|
39
38
|
- run: bundle exec rake
|
|
39
|
+
|
|
40
|
+
test_trilogy:
|
|
41
|
+
strategy:
|
|
42
|
+
fail-fast: false
|
|
43
|
+
matrix:
|
|
44
|
+
ruby:
|
|
45
|
+
- 3.2
|
|
46
|
+
- 3.3
|
|
47
|
+
- 3.4
|
|
48
|
+
gemfile:
|
|
49
|
+
- gemfiles/rails_8_1.gemfile
|
|
50
|
+
env:
|
|
51
|
+
DB_ADAPTER: "trilogy"
|
|
52
|
+
PERCONA_DB_USER: root
|
|
53
|
+
PERCONA_DB_PASSWORD: root
|
|
54
|
+
BUNDLE_GEMFILE: ${{ matrix.gemfile }}
|
|
55
|
+
runs-on: ubuntu-latest
|
|
56
|
+
steps:
|
|
57
|
+
- uses: actions/checkout@v4
|
|
58
|
+
- uses: ruby/setup-ruby@v1
|
|
59
|
+
with:
|
|
60
|
+
ruby-version: ${{ matrix.ruby }}
|
|
61
|
+
bundler-cache: true
|
|
62
|
+
- name: "Add Percona GPG key"
|
|
63
|
+
run: sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 9334A25F8507EFA5
|
|
64
|
+
- name: "Add Percona APT repository"
|
|
65
|
+
run: echo "deb http://repo.percona.com/apt `lsb_release -cs` main" | sudo tee -a /etc/apt/sources.list
|
|
66
|
+
- run: sudo apt-get update -qq
|
|
67
|
+
- run: sudo apt-get install percona-toolkit
|
|
68
|
+
- name: Start MySQL server
|
|
69
|
+
run: sudo systemctl start mysql.service
|
|
70
|
+
- name: Configure MySQL for Trilogy
|
|
71
|
+
run: |
|
|
72
|
+
sudo mysql -u root -proot -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root'; FLUSH PRIVILEGES;"
|
|
73
|
+
- run: bin/setup
|
|
74
|
+
- run: bundle exec rake
|
|
75
|
+
|
|
40
76
|
lint:
|
|
41
77
|
strategy:
|
|
42
78
|
fail-fast: false
|
|
43
79
|
env:
|
|
44
80
|
PERCONA_DB_USER: root
|
|
45
81
|
PERCONA_DB_PASSWORD: root
|
|
46
|
-
BUNDLE_GEMFILE: gemfiles/
|
|
82
|
+
BUNDLE_GEMFILE: gemfiles/rails_8_1.gemfile
|
|
47
83
|
runs-on: ubuntu-latest
|
|
48
84
|
steps:
|
|
49
85
|
- uses: actions/checkout@v4
|
|
50
86
|
- uses: ruby/setup-ruby@v1
|
|
51
87
|
with:
|
|
52
|
-
ruby-version: 3.
|
|
88
|
+
ruby-version: 3.4
|
|
53
89
|
bundler-cache: true
|
|
54
90
|
- run: bundle exec rubocop --parallel
|
data/AGENTS.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# Context
|
|
2
|
+
|
|
3
|
+
Departure is a Ruby gem that wraps Rails ActiveRecord migrations using `ALTER TABLE` statements with `pt-online-schema-change` (Percona Toolkit) so DDL runs online and non-blocking.
|
|
4
|
+
|
|
5
|
+
It must stay aware of how the ActiveRecord API changes across versions and supports all currently supported versions of Rails and Ruby.
|
|
6
|
+
|
|
7
|
+
It supports both the `mysql2` and `trilogy` database adapter gems (trilogy on Rails 8.1+).
|
|
8
|
+
|
|
9
|
+
# Project Layout
|
|
10
|
+
|
|
11
|
+
- `lib/active_record/connection_adapters/` — per-Rails-version connection adapters:
|
|
12
|
+
- `rails_7_2_departure_adapter.rb`
|
|
13
|
+
- `rails_8_0_departure_adapter.rb`
|
|
14
|
+
- `rails_8_1_mysql2_adapter.rb`
|
|
15
|
+
- `rails_8_1_trilogy_adapter.rb`
|
|
16
|
+
- `for_alter.rb`, `patch_connection_handling.rb` — shared behavior
|
|
17
|
+
- `lib/departure/rails_adapter.rb` — version dispatch. `Departure::RailsAdapter.for(ar_version, db_connection_adapter:)` selects the right adapter class. New Rails/adapter combinations are wired in here.
|
|
18
|
+
- `lib/departure/railtie.rb` — Rails integration entry point; calls `RailsAdapter.register_integrations`.
|
|
19
|
+
- `lib/departure/runner.rb`, `cli_generator.rb`, `command.rb` — intercept ALTER statements and shell out to `pt-online-schema-change`.
|
|
20
|
+
- `lib/departure/rails_patches/` — targeted patches against ActiveRecord internals.
|
|
21
|
+
- `lib/lhm/` — LHM DSL compatibility shim.
|
|
22
|
+
- `spec/dummy/` — minimal Rails app used by integration specs.
|
|
23
|
+
|
|
24
|
+
# Adapter Selection
|
|
25
|
+
|
|
26
|
+
1. If the database config specifies `trilogy` (Rails 8.1+), use the trilogy adapter.
|
|
27
|
+
2. Otherwise default to `mysql2`.
|
|
28
|
+
|
|
29
|
+
Selection lives in `Departure::RailsAdapter.for`. When adding a new Rails version, add a `V<MAJOR>_<MINOR>_*Adapter` subclass of `BaseAdapter` and update the dispatch logic.
|
|
30
|
+
|
|
31
|
+
# Development
|
|
32
|
+
|
|
33
|
+
- `docker-compose.yml` brings up a MySQL database container and a Rails container with the gem mounted in.
|
|
34
|
+
- The `Appraisal` gem manages Rails version dependencies; configurations live in `Appraisals` and generated gemfiles in `gemfiles/`.
|
|
35
|
+
- Local gems are vendored to `tmp/local_gems` (mounted at `/app/vendor/bundle`) so debugging tools like `pry` can step through ActiveRecord internals.
|
|
36
|
+
|
|
37
|
+
## Required env vars
|
|
38
|
+
Set by `docker-compose.yml`; if running outside Docker, export them yourself:
|
|
39
|
+
|
|
40
|
+
- `PERCONA_DB_USER`
|
|
41
|
+
- `PERCONA_DB_PASSWORD`
|
|
42
|
+
- `PERCONA_DB_HOST`
|
|
43
|
+
- `PERCONA_DB_NAME`
|
|
44
|
+
- `DB_ADAPTER=trilogy` — only when running against trilogy (Rails 8.1)
|
|
45
|
+
|
|
46
|
+
## External dependencies
|
|
47
|
+
|
|
48
|
+
- `pt-online-schema-change` from Percona Toolkit must be on `PATH` — the gem shells out to it. CI installs it from the Percona APT repo.
|
|
49
|
+
- MySQL server. Trilogy requires `mysql_native_password` auth, not `caching_sha2_password`. CI runs `ALTER USER ... IDENTIFIED WITH mysql_native_password` followed by `FLUSH PRIVILEGES` before the trilogy job.
|
|
50
|
+
|
|
51
|
+
# Testing
|
|
52
|
+
|
|
53
|
+
- Be sure that changes are valid against both `rubocop` and the `rspec` suites.
|
|
54
|
+
- The supported test matrix is defined in `.github/workflows/test.yml`:
|
|
55
|
+
- **mysql2:** Ruby 3.2 / 3.3 / 3.4 × Rails 7.2 / 8.0 / 8.1
|
|
56
|
+
- **trilogy:** Ruby 3.2 / 3.3 / 3.4 × Rails 8.1 only
|
|
57
|
+
- **lint:** Ruby 3.4 with the Rails 8.1 gemfile
|
|
58
|
+
- Run inside Docker via `appraisal`:
|
|
59
|
+
- Full suite: `docker compose exec rails bundle exec appraisal rails-8-1 bundle exec rspec spec`
|
|
60
|
+
- Single example: `docker compose exec rails bundle exec appraisal rails-8-1 bundle exec rspec spec/path/to_spec.rb:LINE`
|
|
61
|
+
- Trilogy run: prepend `DB_ADAPTER=trilogy` to the rspec command (rails-8-1 only)
|
|
62
|
+
- Lint: `docker compose exec rails bundle exec appraisal rails-8-1 bundle exec rubocop --parallel`
|
|
63
|
+
|
|
64
|
+
# Adding a Rails version
|
|
65
|
+
|
|
66
|
+
1. Add an `appraise '<rails-x-y>' do ... end` block in `Appraisals`.
|
|
67
|
+
2. `bundle exec appraisal generate && bundle exec appraisal install`
|
|
68
|
+
3. Add a matching `V<X>_<Y>_*Adapter` class in `lib/departure/rails_adapter.rb` and a connection-adapter file under `lib/active_record/connection_adapters/`.
|
|
69
|
+
4. Update the `gemfile:` matrix in `.github/workflows/test.yml`. Add a separate `test_trilogy` entry only if trilogy is supported on that version.
|
|
70
|
+
|
|
71
|
+
# Conventions
|
|
72
|
+
|
|
73
|
+
- Follow the existing adapter naming pattern: `rails_<MAJOR>_<MINOR>_<DRIVER>_adapter.rb` and register through `Departure::RailsAdapter`. Don't introduce a parallel registration path.
|
|
74
|
+
- User-visible changes go in `CHANGELOG.md` (Keep a Changelog format).
|
|
75
|
+
- Release process is documented in `RELEASING.md`.
|
data/Appraisals
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
appraise 'rails-7-0' do
|
|
2
|
-
gem 'rails', '7.0.8'
|
|
3
|
-
end
|
|
4
|
-
|
|
5
|
-
appraise 'rails-7-1' do
|
|
6
|
-
gem 'rails', '7.1.3'
|
|
7
|
-
end
|
|
8
|
-
|
|
9
1
|
appraise 'rails-7-2' do
|
|
2
|
+
gem 'bigdecimal'
|
|
10
3
|
gem 'rails', '7.2.2.1'
|
|
11
4
|
end
|
|
12
5
|
|
|
13
6
|
appraise 'rails-8-0' do
|
|
7
|
+
gem 'bigdecimal'
|
|
14
8
|
gem 'rails', '8.0.2.1'
|
|
15
9
|
end
|
|
10
|
+
|
|
11
|
+
appraise 'rails-8-1' do
|
|
12
|
+
gem 'rails', '8.1.1'
|
|
13
|
+
gem 'trilogy'
|
|
14
|
+
end
|
data/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,28 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|
|
4
4
|
|
|
5
5
|
Please follow the format in [Keep a Changelog](http://keepachangelog.com/)
|
|
6
6
|
|
|
7
|
+
## [NEXT]
|
|
8
|
+
|
|
9
|
+
## [8.1.0] - 2026-05-28
|
|
10
|
+
|
|
11
|
+
- [Add Rails 8.1 Trilogy adapter support](https://github.com/departurerb/departure/pull/132)
|
|
12
|
+
|
|
13
|
+
## [8.0.2] - 2026-04-30
|
|
14
|
+
|
|
15
|
+
- [Fix Rails multi-database migrations](https://github.com/departurerb/departure/pull/138)
|
|
16
|
+
|
|
17
|
+
## [8.0.1] - 2025-12-12
|
|
18
|
+
|
|
19
|
+
- [Remove stderr message "Including for_alter statements"](https://github.com/departurerb/departure/pull/136)
|
|
20
|
+
|
|
21
|
+
## [8.0.0] - 2025-11-24
|
|
22
|
+
|
|
23
|
+
- Bump [appraisal to 2.5.0](https://github.com/departurerb/departure/pull/129)
|
|
24
|
+
- Add support for [Rails 8.1](https://github.com/departurerb/departure/pull/128)
|
|
25
|
+
- Skinnify Departure [to remove most non pt-online-schema-change](https://github.com/departurerb/departure/pull/131) responsibility from departure
|
|
26
|
+
- Inherit from [Mysql2 Adapter instead of AbstractMysqlAdapter](https://github.com/departurerb/departure/pull/130)
|
|
27
|
+
- Remove Support for [Rails 7.0 and Rails 7.1](https://github.com/departurerb/departure/pull/135)
|
|
28
|
+
|
|
7
29
|
## [7.0.0] - 2025-08-21
|
|
8
30
|
|
|
9
31
|
- Drop Ruby 3.1 support. Add >= 3.2 ruby support in gemspec. EOL for 3.1.0 was 2025-03-31
|
data/Dockerfile
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
FROM ruby:3.
|
|
1
|
+
FROM ruby:3.4
|
|
2
2
|
MAINTAINER muffinista@gmail.com
|
|
3
3
|
|
|
4
4
|
# Install apt based dependencies required to run Rails as
|
|
@@ -14,17 +14,10 @@ RUN apt-get update && apt-get install -y \
|
|
|
14
14
|
RUN mkdir -p /app /app/lib/departure
|
|
15
15
|
WORKDIR /app
|
|
16
16
|
|
|
17
|
-
#
|
|
18
|
-
|
|
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/
|
|
17
|
+
# Install bundler - dependencies will be installed via volume mount
|
|
18
|
+
RUN gem install bundler
|
|
23
19
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
# Copy the main application.
|
|
27
|
-
COPY . ./
|
|
20
|
+
# Project root will be mounted as volume for live development
|
|
28
21
|
|
|
29
22
|
# The main command to run when the container starts. Also
|
|
30
23
|
# tell the Rails dev server to bind to all interfaces by
|
data/Gemfile.lock
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
departure (
|
|
5
|
-
activerecord (>= 7.0
|
|
4
|
+
departure (8.1.0)
|
|
5
|
+
activerecord (>= 7.2.0)
|
|
6
6
|
mysql2 (>= 0.4.0, < 0.6.0)
|
|
7
|
-
railties (>= 7.0
|
|
7
|
+
railties (>= 7.2.0)
|
|
8
8
|
|
|
9
9
|
GEM
|
|
10
10
|
remote: https://rubygems.org/
|
|
@@ -44,7 +44,7 @@ GEM
|
|
|
44
44
|
securerandom (>= 0.3)
|
|
45
45
|
tzinfo (~> 2.0, >= 2.0.5)
|
|
46
46
|
uri (>= 0.13.1)
|
|
47
|
-
appraisal (2.
|
|
47
|
+
appraisal (2.5.0)
|
|
48
48
|
bundler
|
|
49
49
|
rake
|
|
50
50
|
thor (>= 0.14.0)
|
|
@@ -86,6 +86,8 @@ GEM
|
|
|
86
86
|
minitest (5.25.5)
|
|
87
87
|
mutex_m (0.3.0)
|
|
88
88
|
mysql2 (0.5.6)
|
|
89
|
+
nokogiri (1.18.7-aarch64-linux-gnu)
|
|
90
|
+
racc (~> 1.4)
|
|
89
91
|
nokogiri (1.18.7-arm64-darwin)
|
|
90
92
|
racc (~> 1.4)
|
|
91
93
|
nokogiri (1.18.7-x86_64-linux-gnu)
|
|
@@ -191,6 +193,7 @@ GEM
|
|
|
191
193
|
zeitwerk (2.6.18)
|
|
192
194
|
|
|
193
195
|
PLATFORMS
|
|
196
|
+
aarch64-linux
|
|
194
197
|
arm64-darwin-21
|
|
195
198
|
arm64-darwin-22
|
|
196
199
|
arm64-darwin-23
|
|
@@ -198,7 +201,7 @@ PLATFORMS
|
|
|
198
201
|
x86_64-linux
|
|
199
202
|
|
|
200
203
|
DEPENDENCIES
|
|
201
|
-
appraisal (~> 2.
|
|
204
|
+
appraisal (~> 2.5.0)
|
|
202
205
|
base64
|
|
203
206
|
climate_control (~> 0.0.3)
|
|
204
207
|
codeclimate-test-reporter (~> 1.0.3)
|
data/README.md
CHANGED
|
@@ -151,9 +151,16 @@ It's strongly recommended to name it after this gems name, such as
|
|
|
151
151
|
|
|
152
152
|
All configuration options are configurable from the `Departure.configure` block example below
|
|
153
153
|
|
|
154
|
-
|Option|Default|What it Controls|
|
|
155
|
-
|
|
156
|
-
|disable_rails_advisory_lock_patch|false|When truthy, disables a patch in at least rails 7.1 and 7.2 where rails throws ConcurrentMigrationErrors due to the inability to release the advisory lock in migrations|
|
|
154
|
+
| Option | Default | What it Controls |
|
|
155
|
+
|-----------------------------------|---------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
156
|
+
| disable_rails_advisory_lock_patch | false | When truthy, disables a patch in at least rails 7.1 and 7.2 where rails throws ConcurrentMigrationErrors due to the inability to release the advisory lock in migrations |
|
|
157
|
+
|
|
158
|
+
### Trilogy Adapter Support
|
|
159
|
+
|
|
160
|
+
Starting in Rails 8.1 we add support for the use of the trilogy database adapter gem. Logic for selecting an adapter follows this logic
|
|
161
|
+
|
|
162
|
+
1. If the database configuration specifies 'trilogy' use the trilogy adapter
|
|
163
|
+
2. Default to mysql2
|
|
157
164
|
|
|
158
165
|
### Disable on per-migration basis
|
|
159
166
|
|
|
@@ -213,6 +220,85 @@ When any errors occur, an `ActiveRecord::StatementInvalid` exception is
|
|
|
213
220
|
raised and the migration is aborted, as all other ActiveRecord connection
|
|
214
221
|
adapters.
|
|
215
222
|
|
|
223
|
+
### Rails multi-database applications
|
|
224
|
+
|
|
225
|
+
Rails multi-database applications expect `bin/rails db:migrate` to run
|
|
226
|
+
migrations for every configured database. Rails 8.1 does this through
|
|
227
|
+
`ActiveRecord::Tasks::DatabaseTasks.migrate_all`, which temporarily switches the
|
|
228
|
+
migration connection to each database configuration before running that
|
|
229
|
+
database's migrations.
|
|
230
|
+
|
|
231
|
+
Departure supports that flow by restoring Rails' migration connection identity
|
|
232
|
+
after each migration. During the migration body, Departure can still reconnect
|
|
233
|
+
with the Percona adapter so `ALTER TABLE` statements go through
|
|
234
|
+
`pt-online-schema-change`. After the migration finishes, Rails gets back the
|
|
235
|
+
same `ActiveRecord::Base.connection_specification_name` it had before Departure
|
|
236
|
+
swapped adapters, so the next configured database can be migrated normally.
|
|
237
|
+
|
|
238
|
+
### Diagram
|
|
239
|
+
|
|
240
|
+
```mermaid
|
|
241
|
+
flowchart TB
|
|
242
|
+
%% User Level
|
|
243
|
+
subgraph "Rails Application"
|
|
244
|
+
Migration["Rails Migration<br/>(ActiveRecord::Migration)"]
|
|
245
|
+
DSL["Migration DSL<br/>(add_column, create_table, etc.)"]
|
|
246
|
+
end
|
|
247
|
+
|
|
248
|
+
%% Core Departure Components
|
|
249
|
+
subgraph "Departure System"
|
|
250
|
+
RailsAdapter["RailsAdapter<br/>(Version Detection)"]
|
|
251
|
+
DepartureAdapter["Rails81Mysql2Adapter<br/>(Connection Adapter)"]
|
|
252
|
+
Runner["Runner<br/>(Query Interceptor)"]
|
|
253
|
+
Command["Command<br/>(Process Executor)"]
|
|
254
|
+
CliGenerator["CliGenerator<br/>(Command Builder)"]
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
%% External Components
|
|
258
|
+
subgraph "External Tools"
|
|
259
|
+
PTOSC["pt-online-schema-change<br/>(Percona Toolkit)"]
|
|
260
|
+
MySQL["MySQL Database"]
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
%% LHM Integration
|
|
264
|
+
subgraph "LHM Integration"
|
|
265
|
+
LhmAdapter["Lhm::Adapter<br/>(DSL Translator)"]
|
|
266
|
+
LhmMigration["LHM Migration"]
|
|
267
|
+
end
|
|
268
|
+
|
|
269
|
+
%% Flow connections
|
|
270
|
+
Migration --> DSL
|
|
271
|
+
DSL --> DepartureAdapter
|
|
272
|
+
DepartureAdapter --> Runner
|
|
273
|
+
Runner --> |"Non-ALTER statements"| MySQL
|
|
274
|
+
CliGenerator --> Command
|
|
275
|
+
Command --> PTOSC
|
|
276
|
+
PTOSC --> MySQL
|
|
277
|
+
|
|
278
|
+
%% LHM Flow
|
|
279
|
+
LhmMigration --> LhmAdapter
|
|
280
|
+
LhmAdapter --> DSL
|
|
281
|
+
|
|
282
|
+
%% Configuration Flow
|
|
283
|
+
RailsAdapter --> |"Registers"| DepartureAdapter
|
|
284
|
+
|
|
285
|
+
%% Decision Points
|
|
286
|
+
Runner --> |"Check: ALTER TABLE?"| DecisionNode{{"ALTER TABLE<br/>Statement?"}}
|
|
287
|
+
DecisionNode --> |"Yes"| CliGenerator
|
|
288
|
+
DecisionNode --> |"No"| MySQL
|
|
289
|
+
|
|
290
|
+
%% Styling
|
|
291
|
+
classDef departure fill:#e1f5fe
|
|
292
|
+
classDef external fill:#fff3e0
|
|
293
|
+
classDef rails fill:#e8f5e8
|
|
294
|
+
classDef lhm fill:#fce4ec
|
|
295
|
+
|
|
296
|
+
class RailsAdapter,DepartureAdapter,Runner,Command,CliGenerator departure
|
|
297
|
+
class PTOSC,MySQL external
|
|
298
|
+
class Migration,DSL rails
|
|
299
|
+
class LhmAdapter,LhmMigration lhm
|
|
300
|
+
```
|
|
301
|
+
|
|
216
302
|
## Trouleshooting
|
|
217
303
|
|
|
218
304
|
### Error creating new table: DBD::mysql::db do failed: Can't write; duplicate key in table (TABLE_NAME)
|
|
@@ -221,6 +307,24 @@ that prevents schema changes when a table has constraints. You should upgrade to
|
|
|
221
307
|
|
|
222
308
|
## Development
|
|
223
309
|
|
|
310
|
+
### Setup
|
|
311
|
+
|
|
312
|
+
#### Docker Compose
|
|
313
|
+
|
|
314
|
+
You can bring up the docker-compose setup and bash into rails in order to not install dependencies on your system
|
|
315
|
+
|
|
316
|
+
Gems are available on your local file system from tmp/local_gems directory. We need this due to changes in
|
|
317
|
+
internals of ActiveRecord and needing to run things like pry to debug how they work.
|
|
318
|
+
|
|
319
|
+
```
|
|
320
|
+
docker compose up
|
|
321
|
+
docker compose exec rails bash
|
|
322
|
+
bundle install
|
|
323
|
+
# off to the races
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
#### Manual
|
|
327
|
+
|
|
224
328
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
|
225
329
|
`rake spec` to run the tests. You can also run `bin/console` for an interactive
|
|
226
330
|
prompt that will allow you to experiment.
|
|
@@ -231,6 +335,26 @@ release a new version, update the version number in `version.rb`, and then run
|
|
|
231
335
|
git commits and tags, and push the `.gem` file to
|
|
232
336
|
[rubygems.org](https://rubygems.org).
|
|
233
337
|
|
|
338
|
+
### Appraisal
|
|
339
|
+
|
|
340
|
+
All versions of supported rails are defined in the [Appraisals file](./Appraisals) in project root
|
|
341
|
+
|
|
342
|
+
#### Usage
|
|
343
|
+
|
|
344
|
+
Say you want to run a specific test under a version of rails defined in Appraisal `rails-8-0`
|
|
345
|
+
|
|
346
|
+
```
|
|
347
|
+
bundle exec appraisal rails-8-0 bundle install
|
|
348
|
+
bundle exec appraisal rails-8-0 bundle exec rspec spec/lhm/column_with_sql_spec.rb:50
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
#### Adding Versions
|
|
352
|
+
|
|
353
|
+
- Add the version to [Appraisals file](./Appraisals)
|
|
354
|
+
- Run `bundle exec appraisal generate`
|
|
355
|
+
- Run `bundle exec appraisal install`
|
|
356
|
+
- updates ci [test.yml](./.github/workflows/test.yml) in the `gemfile:` section
|
|
357
|
+
|
|
234
358
|
## Contributing
|
|
235
359
|
|
|
236
360
|
Bug reports and pull requests are welcome on GitHub at
|
data/config.yml.erb
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
username: <%= ENV['PERCONA_DB_USER'] || 'root' %>
|
|
2
|
-
password: <%= ENV['PERCONA_DB_PASSWORD'] || '' %>
|
|
3
|
-
database: <%= ENV['PERCONA_DB_NAME'] || 'departure_test' %>
|
|
4
|
-
|
|
5
|
-
socket: <%= ENV['PERCONA_DB_SOCKET']
|
|
2
|
+
password: <%= ENV['PERCONA_DB_PASSWORD'] || '' %>
|
|
3
|
+
database: <%= ENV['PERCONA_DB_NAME'] || 'departure_test' %>
|
|
4
|
+
<% if ENV['PERCONA_DB_SOCKET'] && !ENV['PERCONA_DB_SOCKET'].empty? %>
|
|
5
|
+
socket: <%= ENV['PERCONA_DB_SOCKET'] %>
|
|
6
|
+
<% else %>
|
|
7
|
+
host: <%= ENV['PERCONA_DB_HOST'] || 'localhost' %>
|
|
8
|
+
port: <%= ENV['PERCONA_DB_PORT'] || 3306 %>
|
|
9
|
+
<% end %>
|
data/departure.gemspec
CHANGED
|
@@ -8,9 +8,8 @@ require 'departure/version'
|
|
|
8
8
|
Gem::Specification.new do |spec|
|
|
9
9
|
spec.name = 'departure'
|
|
10
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
|
-
|
|
11
|
+
spec.authors = ['Ilya Zayats', 'Pau Pérez', 'Fran Casas', 'Jorge Morante', 'Enrico Stano', 'Adrian Serafin', 'Kirk Haines', 'Guillermo Iguaran', 'Austin Story', 'Douglas Soares de Andrade']
|
|
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', 'lonnieastory@gmail.com', 'douglas@51street.dev']
|
|
14
13
|
spec.summary = %q(pt-online-schema-change runner for ActiveRecord migrations)
|
|
15
14
|
spec.description = %q(Execute your ActiveRecord migrations with Percona's pt-online-schema-change. Formerly known as Percona Migrator.)
|
|
16
15
|
spec.homepage = 'https://github.com/departurerb/departure'
|
|
@@ -21,11 +20,11 @@ Gem::Specification.new do |spec|
|
|
|
21
20
|
|
|
22
21
|
spec.required_ruby_version = '>= 3.2.0'
|
|
23
22
|
|
|
24
|
-
spec.add_runtime_dependency 'railties', '>= 7.0
|
|
25
|
-
spec.add_runtime_dependency 'activerecord', '>= 7.0
|
|
23
|
+
spec.add_runtime_dependency 'railties', '>= 7.2.0'
|
|
24
|
+
spec.add_runtime_dependency 'activerecord', '>= 7.2.0'
|
|
26
25
|
spec.add_runtime_dependency 'mysql2', '>= 0.4.0', '< 0.6.0'
|
|
27
26
|
|
|
28
|
-
spec.add_development_dependency 'appraisal', '~> 2.
|
|
27
|
+
spec.add_development_dependency 'appraisal', '~> 2.5.0'
|
|
29
28
|
spec.add_development_dependency 'rake', '>= 10.0'
|
|
30
29
|
spec.add_development_dependency 'rspec', '~> 3.4', '>= 3.4.0'
|
|
31
30
|
spec.add_development_dependency 'rspec-its', '~> 1.2'
|
data/docker-compose.yml
CHANGED