data_migrate 11.0.0.rc3 → 11.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 48ee408a432e7b193a5244355a42c8b9850d3712fa03650150ba75d764d4f9cb
4
- data.tar.gz: 9f2e3e3b896598afe9e560f063fc74816346fb6032f90008f0caa8d50380f753
3
+ metadata.gz: 93b03e47ca0a194f18a72fdb0cc47a54de82688858aa6660827ef7f68644ef8d
4
+ data.tar.gz: 4aa2328b5e432edb4b445fa46efe0f2871e5eb47acee15a02c2a19bc4505404b
5
5
  SHA512:
6
- metadata.gz: 4b209a7dc5fd808b0aa4b7ced806d82f7d4d971b68c79e9df3b71f3500dd25906417a91a73b1ee31d67b2ce49cf7cbe2d84d8c887ceef7ac958d294f0d50a1cd
7
- data.tar.gz: 739b8946e4a1318c0063345c2e84f3a1e6bd336547c8d763dfa5588a6f4a1b2b704298c23026f8b21e6670a350edc39a910ad9cdb43af00ee729f5be2d1ee720
6
+ metadata.gz: 975645eca490e58faa6895abd76888876f2fa5d90487272d95441c6f887d75799db561c1a5773b53dd3f0d4fe9ffe3487beb964eab138766243cde3162dd0284
7
+ data.tar.gz: d6aa8d28e0225ab194440f51b5c66787a363e4021c5291215ba406f7c410dd13ae898cdc3a19bb43908c20de6c0801c7bc3a51dcc78b8df7ccf69178d55568eb
@@ -9,7 +9,7 @@ jobs:
9
9
  strategy:
10
10
  fail-fast: false
11
11
  matrix:
12
- os: [ "ubuntu-20.04" ]
12
+ os: [ "ubuntu-24.04" ]
13
13
  ruby:
14
14
  - '3.1'
15
15
  - '3.2'
@@ -19,13 +19,17 @@ jobs:
19
19
  - gemfiles/rails_7.0.gemfile
20
20
  - gemfiles/rails_7.1.gemfile
21
21
  - gemfiles/rails_7.2.gemfile
22
+ - gemfiles/rails_8.0.gemfile
23
+ exclude:
24
+ - ruby: '3.1'
25
+ gemfile: 'gemfiles/rails_8.0.gemfile'
22
26
  runs-on: ubuntu-latest
23
27
  env:
24
28
  BUNDLE_GEMFILE: ${{ matrix.gemfile }}
25
29
  RAILS_ENV: test
26
30
  steps:
27
31
  - name: Checkout code
28
- uses: actions/checkout@v3
32
+ uses: actions/checkout@v4
29
33
  - name: Set up Ruby
30
34
  uses: ruby/setup-ruby@v1
31
35
  with:
data/Appraisals CHANGED
@@ -7,10 +7,13 @@ appraise 'rails-7.0' do
7
7
  end
8
8
 
9
9
  appraise 'rails-7.1' do
10
- gem 'rails', '7.1.0'
10
+ gem 'rails', '~> 7.1.0'
11
11
  end
12
12
 
13
-
14
13
  appraise 'rails-7.2' do
15
- gem 'rails', '7.2.0.beta1'
14
+ gem 'rails', '~> 7.2.0'
15
+ end
16
+
17
+ appraise 'rails-8.0' do
18
+ gem 'rails', '8.0.0.beta1'
16
19
  end
data/Changelog.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # Changelog
2
2
 
3
+ # 11.1.0
4
+ - Allow multiple data migration paths https://github.com/ilyakatz/data-migrate/pull/331
5
+ - Fix db:prepare:with_data task on [Rails 7.2](https://github.com/ilyakatz/data-migrate/pull/339)
6
+ - Fix ConnectionPool deprecation warnings on [Rails 7.2](https://github.com/ilyakatz/data-migrate/pull/341)
7
+ - Add Rails 8.0 to testing grounds https://github.com/ilyakatz/data-migrate/pull/341
8
+ - [Bump webrick from 1.8.1 to 1.8.2](https://github.com/ilyakatz/data-migrate/pull/345)
9
+
10
+ # 11.0.0
11
+ - [Update rexml to 3.3.6](https://github.com/ilyakatz/data-migrate/pull/329)
12
+ - Fixes a bug which ignored migrations on [Rails 7.1 and higher](https://github.com/ilyakatz/data-migrate/pull/326)
13
+
3
14
  # 11.0.0rc
4
15
  - Remove Ruby 3.0 from build matrix
5
16
  - Support Rails 7.2.0 https://github.com/ilyakatz/data-migrate/pull/312
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- data_migrate (11.0.0.rc3)
4
+ data_migrate (11.1.0)
5
5
  activerecord (>= 6.1)
6
6
  railties (>= 6.1)
7
7
 
@@ -124,7 +124,7 @@ GEM
124
124
  regexp_parser (2.9.0)
125
125
  reline (0.4.3)
126
126
  io-console (~> 0.5)
127
- rexml (3.3.3)
127
+ rexml (3.3.6)
128
128
  strscan
129
129
  rspec (3.13.0)
130
130
  rspec-core (~> 3.13.0)
@@ -165,7 +165,7 @@ GEM
165
165
  tzinfo (2.0.6)
166
166
  concurrent-ruby (~> 1.0)
167
167
  unicode-display_width (2.5.0)
168
- webrick (1.8.1)
168
+ webrick (1.8.2)
169
169
  zeitwerk (2.6.13)
170
170
 
171
171
  PLATFORMS
data/README.md CHANGED
@@ -38,6 +38,11 @@ table to track all migrations.
38
38
 
39
39
  Support Rails 6.1 through 7.2
40
40
 
41
+ For **Rails 6.0** support, please use gem version `9.1.x`:
42
+
43
+ ```ruby
44
+ gem 'data_migrate', '~> 9.1.0'
45
+ ```
41
46
 
42
47
  #### v1
43
48
 
@@ -86,6 +91,7 @@ You can generate a data migration as you would a schema migration:
86
91
  rake db:migrate:status:with_data # Display status of data and schema migrations
87
92
  rake db:migrate:up:with_data # Runs the "up" for a given migration VERSION
88
93
  rake db:migrate:with_data # Migrate the database data and schema (options: VERSION=x, VERBOSE=false)
94
+ rake db:prepare:with_data # Runs setup if database does not exist, or runs data and schema migrations if it does
89
95
  rake db:rollback:with_data # Rolls the schema back to the previous version (specify steps w/ STEP=n)
90
96
  rake db:schema:load:with_data # Load both schema.rb and data_schema.rb file into the database
91
97
  rake db:structure:load:with_data # Load both structure.sql and data_schema.rb file into the database
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- data_migrate (11.0.0.rc3)
4
+ data_migrate (11.1.0)
5
5
  activerecord (>= 6.1)
6
6
  railties (>= 6.1)
7
7
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- data_migrate (11.0.0.rc3)
4
+ data_migrate (11.1.0)
5
5
  activerecord (>= 6.1)
6
6
  railties (>= 6.1)
7
7
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- data_migrate (11.0.0.rc3)
4
+ data_migrate (11.1.0)
5
5
  activerecord (>= 6.1)
6
6
  railties (>= 6.1)
7
7
 
@@ -121,6 +121,7 @@ GEM
121
121
  marcel (1.0.4)
122
122
  method_source (1.0.0)
123
123
  mini_mime (1.1.5)
124
+ mini_portile2 (2.8.7)
124
125
  minitest (5.25.1)
125
126
  mutex_m (0.2.0)
126
127
  net-imap (0.4.14)
@@ -133,6 +134,9 @@ GEM
133
134
  net-smtp (0.5.0)
134
135
  net-protocol
135
136
  nio4r (2.7.3)
137
+ nokogiri (1.16.7)
138
+ mini_portile2 (~> 2.8.2)
139
+ racc (~> 1.4)
136
140
  nokogiri (1.16.7-aarch64-linux)
137
141
  racc (~> 1.4)
138
142
  nokogiri (1.16.7-arm64-darwin)
@@ -228,6 +232,8 @@ GEM
228
232
  rubocop-ast (1.29.0)
229
233
  parser (>= 3.2.1.0)
230
234
  ruby-progressbar (1.13.0)
235
+ sqlite3 (1.7.2)
236
+ mini_portile2 (~> 2.8.0)
231
237
  sqlite3 (1.7.2-aarch64-linux)
232
238
  sqlite3 (1.7.2-arm64-darwin)
233
239
  sqlite3 (1.7.2-x86_64-darwin)
@@ -249,6 +255,7 @@ PLATFORMS
249
255
  aarch64-linux
250
256
  arm64-darwin-22
251
257
  arm64-darwin-23
258
+ ruby
252
259
  x86_64-darwin-22
253
260
  x86_64-linux
254
261
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- data_migrate (11.0.0.rc3)
4
+ data_migrate (11.1.0)
5
5
  activerecord (>= 6.1)
6
6
  railties (>= 6.1)
7
7
 
@@ -118,6 +118,7 @@ GEM
118
118
  marcel (1.0.4)
119
119
  method_source (1.1.0)
120
120
  mini_mime (1.1.5)
121
+ mini_portile2 (2.8.7)
121
122
  minitest (5.25.1)
122
123
  net-imap (0.4.14)
123
124
  date
@@ -129,6 +130,9 @@ GEM
129
130
  net-smtp (0.5.0)
130
131
  net-protocol
131
132
  nio4r (2.7.3)
133
+ nokogiri (1.16.7)
134
+ mini_portile2 (~> 2.8.2)
135
+ racc (~> 1.4)
132
136
  nokogiri (1.16.7-aarch64-linux)
133
137
  racc (~> 1.4)
134
138
  nokogiri (1.16.7-arm64-darwin)
@@ -248,6 +252,7 @@ GEM
248
252
  PLATFORMS
249
253
  aarch64-linux
250
254
  arm64-darwin-23
255
+ ruby
251
256
  x86_64-darwin-22
252
257
  x86_64-linux
253
258
 
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "rails", "8.0.0.beta1"
6
+
7
+ gemspec path: "../"
@@ -0,0 +1,268 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ data_migrate (11.1.0)
5
+ activerecord (>= 6.1)
6
+ railties (>= 6.1)
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ actioncable (8.0.0.beta1)
12
+ actionpack (= 8.0.0.beta1)
13
+ activesupport (= 8.0.0.beta1)
14
+ nio4r (~> 2.0)
15
+ websocket-driver (>= 0.6.1)
16
+ zeitwerk (~> 2.6)
17
+ actionmailbox (8.0.0.beta1)
18
+ actionpack (= 8.0.0.beta1)
19
+ activejob (= 8.0.0.beta1)
20
+ activerecord (= 8.0.0.beta1)
21
+ activestorage (= 8.0.0.beta1)
22
+ activesupport (= 8.0.0.beta1)
23
+ mail (>= 2.8.0)
24
+ actionmailer (8.0.0.beta1)
25
+ actionpack (= 8.0.0.beta1)
26
+ actionview (= 8.0.0.beta1)
27
+ activejob (= 8.0.0.beta1)
28
+ activesupport (= 8.0.0.beta1)
29
+ mail (>= 2.8.0)
30
+ rails-dom-testing (~> 2.2)
31
+ actionpack (8.0.0.beta1)
32
+ actionview (= 8.0.0.beta1)
33
+ activesupport (= 8.0.0.beta1)
34
+ nokogiri (>= 1.8.5)
35
+ rack (>= 2.2.4)
36
+ rack-session (>= 1.0.1)
37
+ rack-test (>= 0.6.3)
38
+ rails-dom-testing (~> 2.2)
39
+ rails-html-sanitizer (~> 1.6)
40
+ useragent (~> 0.16)
41
+ actiontext (8.0.0.beta1)
42
+ actionpack (= 8.0.0.beta1)
43
+ activerecord (= 8.0.0.beta1)
44
+ activestorage (= 8.0.0.beta1)
45
+ activesupport (= 8.0.0.beta1)
46
+ globalid (>= 0.6.0)
47
+ nokogiri (>= 1.8.5)
48
+ actionview (8.0.0.beta1)
49
+ activesupport (= 8.0.0.beta1)
50
+ builder (~> 3.1)
51
+ erubi (~> 1.11)
52
+ rails-dom-testing (~> 2.2)
53
+ rails-html-sanitizer (~> 1.6)
54
+ activejob (8.0.0.beta1)
55
+ activesupport (= 8.0.0.beta1)
56
+ globalid (>= 0.3.6)
57
+ activemodel (8.0.0.beta1)
58
+ activesupport (= 8.0.0.beta1)
59
+ activerecord (8.0.0.beta1)
60
+ activemodel (= 8.0.0.beta1)
61
+ activesupport (= 8.0.0.beta1)
62
+ timeout (>= 0.4.0)
63
+ activestorage (8.0.0.beta1)
64
+ actionpack (= 8.0.0.beta1)
65
+ activejob (= 8.0.0.beta1)
66
+ activerecord (= 8.0.0.beta1)
67
+ activesupport (= 8.0.0.beta1)
68
+ marcel (~> 1.0)
69
+ activesupport (8.0.0.beta1)
70
+ base64
71
+ benchmark (>= 0.3)
72
+ bigdecimal
73
+ concurrent-ruby (~> 1.0, >= 1.3.1)
74
+ connection_pool (>= 2.2.5)
75
+ drb
76
+ i18n (>= 1.6, < 2)
77
+ logger (>= 1.4.2)
78
+ minitest (>= 5.1)
79
+ securerandom (>= 0.3)
80
+ tzinfo (~> 2.0, >= 2.0.5)
81
+ uri (>= 0.13.1)
82
+ appraisal (2.5.0)
83
+ bundler
84
+ rake
85
+ thor (>= 0.14.0)
86
+ ast (2.4.2)
87
+ base64 (0.2.0)
88
+ benchmark (0.3.0)
89
+ bigdecimal (3.1.8)
90
+ builder (3.3.0)
91
+ childprocess (5.1.0)
92
+ logger (~> 1.5)
93
+ coderay (1.1.3)
94
+ concurrent-ruby (1.3.4)
95
+ connection_pool (2.4.1)
96
+ crass (1.0.6)
97
+ date (3.3.4)
98
+ diff-lcs (1.5.1)
99
+ drb (2.2.1)
100
+ erubi (1.13.0)
101
+ globalid (1.2.1)
102
+ activesupport (>= 6.1)
103
+ i18n (1.14.6)
104
+ concurrent-ruby (~> 1.0)
105
+ iniparse (1.5.0)
106
+ io-console (0.7.2)
107
+ irb (1.14.1)
108
+ rdoc (>= 4.0.0)
109
+ reline (>= 0.4.2)
110
+ json (2.7.2)
111
+ language_server-protocol (3.17.0.3)
112
+ logger (1.6.1)
113
+ loofah (2.22.0)
114
+ crass (~> 1.0.2)
115
+ nokogiri (>= 1.12.0)
116
+ mail (2.8.1)
117
+ mini_mime (>= 0.1.1)
118
+ net-imap
119
+ net-pop
120
+ net-smtp
121
+ marcel (1.0.4)
122
+ method_source (1.1.0)
123
+ mini_mime (1.1.5)
124
+ mini_portile2 (2.8.7)
125
+ minitest (5.25.1)
126
+ net-imap (0.4.16)
127
+ date
128
+ net-protocol
129
+ net-pop (0.1.2)
130
+ net-protocol
131
+ net-protocol (0.2.2)
132
+ timeout
133
+ net-smtp (0.5.0)
134
+ net-protocol
135
+ nio4r (2.7.3)
136
+ nokogiri (1.16.7)
137
+ mini_portile2 (~> 2.8.2)
138
+ racc (~> 1.4)
139
+ nokogiri (1.16.7-arm64-darwin)
140
+ racc (~> 1.4)
141
+ overcommit (0.64.0)
142
+ childprocess (>= 0.6.3, < 6)
143
+ iniparse (~> 1.4)
144
+ rexml (~> 3.2)
145
+ parallel (1.26.3)
146
+ parser (3.3.5.0)
147
+ ast (~> 2.4.1)
148
+ racc
149
+ pry (0.14.2)
150
+ coderay (~> 1.1)
151
+ method_source (~> 1.0)
152
+ psych (5.1.2)
153
+ stringio
154
+ racc (1.8.1)
155
+ rack (3.1.7)
156
+ rack-session (2.0.0)
157
+ rack (>= 3.0.0)
158
+ rack-test (2.1.0)
159
+ rack (>= 1.3)
160
+ rackup (2.1.0)
161
+ rack (>= 3)
162
+ webrick (~> 1.8)
163
+ rails (8.0.0.beta1)
164
+ actioncable (= 8.0.0.beta1)
165
+ actionmailbox (= 8.0.0.beta1)
166
+ actionmailer (= 8.0.0.beta1)
167
+ actionpack (= 8.0.0.beta1)
168
+ actiontext (= 8.0.0.beta1)
169
+ actionview (= 8.0.0.beta1)
170
+ activejob (= 8.0.0.beta1)
171
+ activemodel (= 8.0.0.beta1)
172
+ activerecord (= 8.0.0.beta1)
173
+ activestorage (= 8.0.0.beta1)
174
+ activesupport (= 8.0.0.beta1)
175
+ bundler (>= 1.15.0)
176
+ railties (= 8.0.0.beta1)
177
+ rails-dom-testing (2.2.0)
178
+ activesupport (>= 5.0.0)
179
+ minitest
180
+ nokogiri (>= 1.6)
181
+ rails-html-sanitizer (1.6.0)
182
+ loofah (~> 2.21)
183
+ nokogiri (~> 1.14)
184
+ railties (8.0.0.beta1)
185
+ actionpack (= 8.0.0.beta1)
186
+ activesupport (= 8.0.0.beta1)
187
+ irb (~> 1.13)
188
+ rackup (>= 1.0.0)
189
+ rake (>= 12.2)
190
+ thor (~> 1.0, >= 1.2.2)
191
+ zeitwerk (~> 2.6)
192
+ rainbow (3.1.1)
193
+ rake (13.2.1)
194
+ rb-readline (0.5.5)
195
+ rdoc (6.7.0)
196
+ psych (>= 4.0.0)
197
+ regexp_parser (2.9.2)
198
+ reline (0.5.10)
199
+ io-console (~> 0.5)
200
+ rexml (3.3.7)
201
+ rspec (3.13.0)
202
+ rspec-core (~> 3.13.0)
203
+ rspec-expectations (~> 3.13.0)
204
+ rspec-mocks (~> 3.13.0)
205
+ rspec-core (3.13.1)
206
+ rspec-support (~> 3.13.0)
207
+ rspec-expectations (3.13.3)
208
+ diff-lcs (>= 1.2.0, < 2.0)
209
+ rspec-support (~> 3.13.0)
210
+ rspec-mocks (3.13.1)
211
+ diff-lcs (>= 1.2.0, < 2.0)
212
+ rspec-support (~> 3.13.0)
213
+ rspec-support (3.13.1)
214
+ rubocop (1.66.1)
215
+ json (~> 2.3)
216
+ language_server-protocol (>= 3.17.0)
217
+ parallel (~> 1.10)
218
+ parser (>= 3.3.0.2)
219
+ rainbow (>= 2.2.2, < 4.0)
220
+ regexp_parser (>= 2.4, < 3.0)
221
+ rubocop-ast (>= 1.32.2, < 2.0)
222
+ ruby-progressbar (~> 1.7)
223
+ unicode-display_width (>= 2.4.0, < 3.0)
224
+ rubocop-ast (1.32.3)
225
+ parser (>= 3.3.1.0)
226
+ ruby-progressbar (1.13.0)
227
+ securerandom (0.3.1)
228
+ sqlite3 (2.1.0)
229
+ mini_portile2 (~> 2.8.0)
230
+ sqlite3 (2.1.0-arm64-darwin)
231
+ stringio (3.1.1)
232
+ thor (1.3.2)
233
+ timecop (0.9.10)
234
+ timeout (0.4.1)
235
+ tzinfo (2.0.6)
236
+ concurrent-ruby (~> 1.0)
237
+ unicode-display_width (2.6.0)
238
+ uri (0.13.1)
239
+ useragent (0.16.10)
240
+ webrick (1.8.2)
241
+ websocket-driver (0.7.6)
242
+ websocket-extensions (>= 0.1.0)
243
+ websocket-extensions (0.1.5)
244
+ zeitwerk (2.6.18)
245
+
246
+ PLATFORMS
247
+ aarch64-linux
248
+ arm64-darwin-23
249
+ ruby
250
+ x86_64-darwin-22
251
+ x86_64-linux
252
+
253
+ DEPENDENCIES
254
+ appraisal
255
+ data_migrate!
256
+ overcommit
257
+ pry
258
+ rails (= 8.0.0.beta1)
259
+ rake
260
+ rb-readline
261
+ rspec
262
+ rspec-core
263
+ rubocop
264
+ sqlite3
265
+ timecop
266
+
267
+ BUNDLED WITH
268
+ 2.4.17
@@ -12,7 +12,7 @@ module DataMigrate
12
12
 
13
13
  class << self
14
14
  def migrations_paths
15
- [DataMigrate.config.data_migrations_path]
15
+ Array.wrap(DataMigrate.config.data_migrations_path)
16
16
  end
17
17
 
18
18
  def create_data_schema_table
@@ -29,13 +29,13 @@ module DataMigrate
29
29
  end
30
30
 
31
31
  def versions
32
- @versions ||= begin
33
- versions = []
34
- Dir.foreach(DataMigrate::DataMigrator.full_migrations_path) do |file|
35
- match_data = DataMigrate::DataMigrator.match(file)
36
- versions << match_data[1].to_i if match_data
32
+ @versions ||= Set.new.tap do |versions|
33
+ DataMigrate::DataMigrator.migrations_paths.each do |path|
34
+ Dir.foreach(path) do |file|
35
+ match_data = DataMigrate::DataMigrator.match(file)
36
+ versions << match_data[1].to_i if match_data
37
+ end
37
38
  end
38
- versions
39
39
  end
40
40
  end
41
41
 
@@ -10,21 +10,21 @@ module DataMigrate
10
10
  extend self
11
11
 
12
12
  # These method are only introduced in Rails 7.1
13
- unless respond_to?(:with_temporary_connection_for_each)
14
- def with_temporary_connection_for_each(env: ActiveRecord::Tasks::DatabaseTasks.env, name: nil, &block) # :nodoc:
13
+ unless respond_to?(:with_temporary_pool_for_each)
14
+ def with_temporary_pool_for_each(env: ActiveRecord::Tasks::DatabaseTasks.env, name: nil, &block) # :nodoc:
15
15
  if name
16
16
  db_config = ActiveRecord::Base.configurations.configs_for(env_name: env, name: name)
17
- with_temporary_connection(db_config, &block)
17
+ with_temporary_pool(db_config, &block)
18
18
  else
19
19
  ActiveRecord::Base.configurations.configs_for(env_name: env, name: name).each do |db_config|
20
- with_temporary_connection(db_config, &block)
20
+ with_temporary_pool(db_config, &block)
21
21
  end
22
22
  end
23
23
  end
24
24
 
25
- def with_temporary_connection(db_config) # :nodoc:
25
+ def with_temporary_connection(db_config, &block) # :nodoc:
26
26
  with_temporary_pool(db_config) do |pool|
27
- yield pool.connection
27
+ pool.with_connection(&block)
28
28
  end
29
29
  end
30
30
 
@@ -49,8 +49,8 @@ module DataMigrate
49
49
  def db_configs_with_versions
50
50
  db_configs_with_versions = Hash.new { |h, k| h[k] = [] }
51
51
 
52
- with_temporary_connection_for_each do |conn|
53
- db_config = conn.pool.db_config
52
+ with_temporary_pool_for_each do |pool|
53
+ db_config = pool.db_config
54
54
  if db_config.primary?
55
55
  versions_to_run = DataMigrate::DatabaseTasks.pending_data_migrations.map { |m| m[:version] }
56
56
  target_version = ActiveRecord::Tasks::DatabaseTasks.target_version
@@ -214,19 +214,13 @@ module DataMigrate
214
214
  seed = false
215
215
 
216
216
  each_current_configuration(env) do |db_config|
217
- next unless db_config.primary?
217
+ next unless primary?(db_config)
218
218
 
219
- with_temporary_pool(db_config) do
220
- begin
221
- database_initialized = migration_connection.schema_migration.table_exists?
222
- rescue ActiveRecord::NoDatabaseError
219
+ with_temporary_pool(db_config) do |pool|
220
+ unless database_exists?(pool.connection)
223
221
  create(db_config)
224
- retry
225
- end
226
-
227
- unless database_initialized
228
222
  if File.exist?(schema_dump_path(db_config))
229
- load_schema(db_config, ActiveRecord.schema_format, nil)
223
+ load_schema(db_config, schema_format, nil)
230
224
  load_schema_current(
231
225
  :ruby,
232
226
  ENV["DATA_SCHEMA"]
@@ -237,7 +231,7 @@ module DataMigrate
237
231
  end
238
232
 
239
233
  migrate_with_data
240
- if ActiveRecord.dump_schema_after_migration
234
+ if dump_schema_after_migration?
241
235
  dump_schema(db_config)
242
236
  DataMigrate::Tasks::DataMigrateTasks.dump
243
237
  end
@@ -246,5 +240,41 @@ module DataMigrate
246
240
 
247
241
  load_seed if seed
248
242
  end
243
+
244
+ private
245
+
246
+ def database_exists?(connection)
247
+ if connection.respond_to?(:database_exists?) # Rails 7.1+
248
+ connection.database_exists?
249
+ else
250
+ connection.table_exists?(ActiveRecord::SchemaMigration.table_name)
251
+ end
252
+ rescue ActiveRecord::NoDatabaseError
253
+ false
254
+ end
255
+
256
+ def primary?(db_config)
257
+ if db_config.respond_to?(:primary?) # Rails 7.0+
258
+ db_config.primary?
259
+ else
260
+ db_config.name == "primary"
261
+ end
262
+ end
263
+
264
+ def dump_schema_after_migration?
265
+ if ActiveRecord.respond_to?(:dump_schema_after_migration)
266
+ ActiveRecord.dump_schema_after_migration
267
+ else
268
+ ActiveRecord::Base.dump_schema_after_migration
269
+ end
270
+ end
271
+
272
+ def schema_format
273
+ if ActiveRecord.respond_to?(:schema_format)
274
+ ActiveRecord.schema_format
275
+ else
276
+ ActiveRecord::Base.schema_format
277
+ end
278
+ end
249
279
  end
250
280
  end
@@ -6,7 +6,7 @@ module DataMigrate
6
6
  extend self
7
7
 
8
8
  def migrations_paths
9
- @migrations_paths ||= DataMigrate.config.data_migrations_path
9
+ @migrations_paths ||= Array.wrap(DataMigrate.config.data_migrations_path)
10
10
  end
11
11
 
12
12
  def dump
@@ -55,11 +55,13 @@ module DataMigrate
55
55
  db_list_schema = DataMigrate::RailsHelper.schema_migration_versions
56
56
  file_list = []
57
57
 
58
- Dir.foreach(File.join(Rails.root, migrations_paths)) do |file|
59
- # only files matching "20091231235959_some_name.rb" pattern
60
- if match_data = /(\d{14})_(.+)\.rb/.match(file)
61
- status = db_list_data.delete(match_data[1]) ? 'up' : 'down'
62
- file_list << [status, match_data[1], match_data[2], 'data']
58
+ migrations_paths.each do |path|
59
+ Dir.foreach(File.join(Rails.root, path)) do |file|
60
+ # only files matching "20091231235959_some_name.rb" pattern
61
+ if match_data = /(\d{14})_(.+)\.rb/.match(file)
62
+ status = db_list_data.delete(match_data[1]) ? 'up' : 'down'
63
+ file_list << [status, match_data[1], match_data[2], 'data']
64
+ end
63
65
  end
64
66
  end
65
67
 
@@ -1,3 +1,3 @@
1
1
  module DataMigrate
2
- VERSION = "11.0.0.rc3".freeze
2
+ VERSION = "11.1.0".freeze
3
3
  end
@@ -38,8 +38,9 @@ module DataMigrate
38
38
  File.join(data_migrations_path, "#{file_name}.rb")
39
39
  end
40
40
 
41
+ # Use the first path in the data_migrations_path as the target directory
41
42
  def data_migrations_path
42
- DataMigrate.config.data_migrations_path
43
+ Array.wrap(DataMigrate.config.data_migrations_path).first
43
44
  end
44
45
  end
45
46
  end
@@ -51,9 +51,10 @@ describe DataMigrate::DataMigrator do
51
51
  describe "#migrations_status" do
52
52
  it "returns all migrations statuses" do
53
53
  status = described_class.migrations_status
54
- expect(status.length).to eq 2
54
+ expect(status.length).to eq 3
55
55
  expect(status.first).to eq ["down", "20091231235959", "Some name"]
56
56
  expect(status.second).to eq ["down", "20171231235959", "Super update"]
57
+ expect(status.third).to eq ["down", "20241231235959", "Data two update"]
57
58
  end
58
59
  end
59
60
 
@@ -5,9 +5,7 @@ require "spec_helper"
5
5
  describe DataMigrate::DatabaseTasks do
6
6
  let(:subject) { DataMigrate::DatabaseTasks }
7
7
  let(:migration_path) { "spec/db/migrate" }
8
- let(:data_migrations_path) {
9
- DataMigrate.config.data_migrations_path
10
- }
8
+ let(:data_migrations_path) { DataMigrate.config.data_migrations_path }
11
9
 
12
10
  before do
13
11
  # In a normal Rails installation, db_dir would defer to
@@ -18,11 +16,13 @@ describe DataMigrate::DatabaseTasks do
18
16
  end
19
17
 
20
18
  before do
21
- allow(DataMigrate::Tasks::DataMigrateTasks).to receive(:migrations_paths) {
19
+ allow(DataMigrate::Tasks::DataMigrateTasks).to receive(:migrations_paths) do
22
20
  data_migrations_path
23
- }
24
- ActiveRecord::Base.establish_connection({ adapter: "sqlite3", database: "spec/db/test.db" })
25
- hash_config = ActiveRecord::DatabaseConfigurations::HashConfig.new('test', 'test', { adapter: "sqlite3", database: "spec/db/test.db" })
21
+ end
22
+ ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: "spec/db/test.db")
23
+ hash_config = ActiveRecord::DatabaseConfigurations::HashConfig.new(
24
+ 'test', 'test', adapter: "sqlite3", database: "spec/db/test.db"
25
+ )
26
26
  config_obj = ActiveRecord::DatabaseConfigurations.new([hash_config])
27
27
  allow(ActiveRecord::Base).to receive(:configurations).and_return(config_obj)
28
28
  end
@@ -36,12 +36,10 @@ describe DataMigrate::DatabaseTasks do
36
36
  before do
37
37
  DataMigrate::RailsHelper.schema_migration.create_table
38
38
 
39
- allow(DataMigrate::SchemaMigration).to receive(:migrations_paths) {
40
- migration_path
41
- }
42
- allow(DataMigrate::DatabaseTasks).to receive(:data_migrations_path) {
39
+ allow(DataMigrate::SchemaMigration).to receive(:migrations_paths) { migration_path }
40
+ allow(DataMigrate::DatabaseTasks).to receive(:data_migrations_path) do
43
41
  data_migrations_path
44
- }.at_least(:once)
42
+ end.at_least(:once)
45
43
  end
46
44
 
47
45
  describe :past_migrations do
@@ -79,11 +77,14 @@ describe DataMigrate::DatabaseTasks do
79
77
  if DataMigrate::RailsHelper.rails_version_equal_to_or_higher_than_7_0
80
78
  describe :schema_dump_path do
81
79
  before do
82
- allow(ActiveRecord::Base).to receive(:configurations).and_return(ActiveRecord::DatabaseConfigurations.new([db_config]))
80
+ allow(ActiveRecord::Base).to receive(:configurations)
81
+ .and_return(ActiveRecord::DatabaseConfigurations.new([db_config]))
83
82
  end
84
83
 
85
84
  context "for primary database" do
86
- let(:db_config) { ActiveRecord::DatabaseConfigurations::HashConfig.new("development", "primary", {} ) }
85
+ let(:db_config) do
86
+ ActiveRecord::DatabaseConfigurations::HashConfig.new("development", "primary", {})
87
+ end
87
88
 
88
89
  context "for :ruby db format" do
89
90
  it 'returns the data schema path' do
@@ -101,5 +102,113 @@ describe DataMigrate::DatabaseTasks do
101
102
  end
102
103
  end
103
104
  end
105
+
106
+ describe :prepare_all_with_data do
107
+ let(:db_config) do
108
+ ActiveRecord::DatabaseConfigurations::HashConfig.new(
109
+ 'test',
110
+ 'primary',
111
+ adapter: "sqlite3",
112
+ database: "spec/db/test.db"
113
+ )
114
+ end
115
+
116
+ let(:pool) { double("ConnectionPool") }
117
+ let(:connection) { double("Connection") }
118
+
119
+ before do
120
+ allow(subject).to receive(:each_current_configuration).and_yield(db_config)
121
+ allow(subject).to receive(:with_temporary_pool).with(db_config).and_yield(pool)
122
+ allow(pool).to receive(:connection).and_return(connection)
123
+ allow(subject).to receive(:schema_dump_path).and_return("db/data_schema.rb")
124
+ allow(File).to receive(:exist?).and_return(true)
125
+ allow(subject).to receive(:load_schema)
126
+ allow(subject).to receive(:load_schema_current)
127
+ allow(subject).to receive(:migrate_with_data)
128
+ allow(subject).to receive(:dump_schema)
129
+ allow(DataMigrate::Tasks::DataMigrateTasks).to receive(:dump)
130
+ allow(subject).to receive(:load_seed)
131
+
132
+ configurations = ActiveRecord::DatabaseConfigurations.new([db_config])
133
+ allow(ActiveRecord::Base).to receive(:configurations).and_return(configurations)
134
+ end
135
+
136
+ context "when the database does not exist" do
137
+ before do
138
+ allow(subject).to receive(:database_exists?).with(connection).and_return(false)
139
+ allow_any_instance_of(ActiveRecord::Tasks::DatabaseTasks).to receive(:create)
140
+ .and_return(true)
141
+ end
142
+
143
+ it "creates the database" do
144
+ expect_any_instance_of(ActiveRecord::Tasks::DatabaseTasks).to receive(:create)
145
+ .with(db_config)
146
+ subject.prepare_all_with_data
147
+ end
148
+
149
+ it "loads the schema" do
150
+ expect(subject).to receive(:load_schema).with(
151
+ db_config,
152
+ subject.send(:schema_format),
153
+ nil
154
+ )
155
+ subject.prepare_all_with_data
156
+ end
157
+
158
+ it "loads the current data schema" do
159
+ expect(subject).to receive(:load_schema_current).with(:ruby, ENV["DATA_SCHEMA"])
160
+ subject.prepare_all_with_data
161
+ end
162
+
163
+ it "runs migrations with data" do
164
+ expect(subject).to receive(:migrate_with_data)
165
+ subject.prepare_all_with_data
166
+ end
167
+
168
+ it "dumps the schema after migration" do
169
+ expect(subject).to receive(:dump_schema).with(db_config)
170
+ expect(DataMigrate::Tasks::DataMigrateTasks).to receive(:dump)
171
+ subject.prepare_all_with_data
172
+ end
173
+
174
+ it "loads seed data" do
175
+ expect(subject).to receive(:load_seed)
176
+ subject.prepare_all_with_data
177
+ end
178
+ end
179
+
180
+ context "when the database exists" do
181
+ before do
182
+ allow(subject).to receive(:database_exists?).with(connection).and_return(true)
183
+ end
184
+
185
+ it "does not create the database" do
186
+ expect(ActiveRecord::Tasks::DatabaseTasks).not_to receive(:create)
187
+ subject.prepare_all_with_data
188
+ end
189
+
190
+ it "does not load the schema" do
191
+ expect(subject).not_to receive(:load_schema)
192
+ expect(subject).not_to receive(:load_schema_current)
193
+ subject.prepare_all_with_data
194
+ end
195
+
196
+ it "runs migrations with data" do
197
+ expect(subject).to receive(:migrate_with_data)
198
+ subject.prepare_all_with_data
199
+ end
200
+
201
+ it "dumps the schema after migration" do
202
+ expect(subject).to receive(:dump_schema).with(db_config)
203
+ expect(DataMigrate::Tasks::DataMigrateTasks).to receive(:dump)
204
+ subject.prepare_all_with_data
205
+ end
206
+
207
+ it "does not load seed data" do
208
+ expect(subject).not_to receive(:load_seed)
209
+ subject.prepare_all_with_data
210
+ end
211
+ end
212
+ end
104
213
  end
105
214
  end
@@ -0,0 +1,9 @@
1
+ class DataTwoUpdate < ActiveRecord::Migration[6.1]
2
+ def up
3
+ puts "Doing DataTwoUpdate"
4
+ end
5
+
6
+ def down
7
+ puts "Undoing DataTwoUpdate"
8
+ end
9
+ end
data/spec/spec_helper.rb CHANGED
@@ -21,7 +21,7 @@ RSpec.configure do |config|
21
21
  else
22
22
  @prev_data_migrations_path = DataMigrate.config.data_migrations_path
23
23
  DataMigrate.configure do |config|
24
- config.data_migrations_path = "spec/db/data"
24
+ config.data_migrations_path = ["spec/db/data", "spec/db/data_two"]
25
25
  end
26
26
  end
27
27
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: data_migrate
3
3
  version: !ruby/object:Gem::Version
4
- version: 11.0.0.rc3
4
+ version: 11.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew J Vargo
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2024-08-20 00:00:00.000000000 Z
13
+ date: 2024-10-09 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
@@ -214,6 +214,8 @@ files:
214
214
  - gemfiles/rails_7.1.gemfile.lock
215
215
  - gemfiles/rails_7.2.gemfile
216
216
  - gemfiles/rails_7.2.gemfile.lock
217
+ - gemfiles/rails_8.0.gemfile
218
+ - gemfiles/rails_8.0.gemfile.lock
217
219
  - lib/capistrano/data_migrate.rb
218
220
  - lib/capistrano/data_migrate/migrate.rb
219
221
  - lib/data_migrate.rb
@@ -230,7 +232,6 @@ files:
230
232
  - lib/data_migrate/schema_migration.rb
231
233
  - lib/data_migrate/status_service.rb
232
234
  - lib/data_migrate/tasks/data_migrate_tasks.rb
233
- - lib/data_migrate/test.rb
234
235
  - lib/data_migrate/version.rb
235
236
  - lib/generators/data_migrate.rb
236
237
  - lib/generators/data_migration/data_migration_generator.rb
@@ -255,6 +256,7 @@ files:
255
256
  - spec/db/data/partial_schema/test_data_schema.rb
256
257
  - spec/db/data/schema/data_schema.rb
257
258
  - spec/db/data/schema/test_data_schema.rb
259
+ - spec/db/data_two/20241231235959_data_two_update.rb
258
260
  - spec/db/migrate/20131111111111_late_migration.rb
259
261
  - spec/db/migrate/20202020202011_db_migration.rb
260
262
  - spec/generators/data_migration/data_migration_generator_spec.rb
@@ -276,9 +278,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
276
278
  version: '0'
277
279
  required_rubygems_version: !ruby/object:Gem::Requirement
278
280
  requirements:
279
- - - ">"
281
+ - - ">="
280
282
  - !ruby/object:Gem::Version
281
- version: 1.3.1
283
+ version: '0'
282
284
  requirements: []
283
285
  rubygems_version: 3.4.19
284
286
  signing_key:
@@ -1,14 +0,0 @@
1
- module Base
2
- extend self
3
-
4
- def foo
5
- puts "Base#foo called"
6
- end
7
- end
8
-
9
- module Child
10
- extend Base
11
- extend self
12
-
13
- puts "foo: #{respond_to?(:foo)}"
14
- end