data_migrate 9.2.0 → 9.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/build.yml +1 -0
- data/Changelog.md +3 -0
- data/Gemfile +0 -1
- data/Gemfile.lock +100 -64
- data/data_migrate.gemspec +1 -1
- data/gemfiles/rails_6.1.gemfile +0 -1
- data/gemfiles/rails_6.1.gemfile.lock +83 -81
- data/gemfiles/rails_7.0.gemfile +1 -2
- data/gemfiles/rails_7.0.gemfile.lock +81 -80
- data/gemfiles/rails_7.1.gemfile +0 -1
- data/gemfiles/rails_7.1.gemfile.lock +33 -32
- data/lib/data_migrate/database_configurations_wrapper.rb +11 -0
- data/lib/data_migrate/database_tasks.rb +114 -59
- data/lib/data_migrate/test.rb +14 -0
- data/lib/data_migrate/version.rb +1 -1
- data/lib/data_migrate.rb +1 -0
- data/tasks/databases.rake +21 -38
- metadata +9 -8
- data/Gemfile.rails6.1 +0 -11
@@ -1,74 +1,74 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ..
|
3
3
|
specs:
|
4
|
-
data_migrate (9.
|
4
|
+
data_migrate (9.3.0)
|
5
5
|
activerecord (>= 6.1)
|
6
6
|
railties (>= 6.1)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: http://rubygems.org/
|
10
10
|
specs:
|
11
|
-
actioncable (7.0.
|
12
|
-
actionpack (= 7.0.
|
13
|
-
activesupport (= 7.0.
|
11
|
+
actioncable (7.0.8.1)
|
12
|
+
actionpack (= 7.0.8.1)
|
13
|
+
activesupport (= 7.0.8.1)
|
14
14
|
nio4r (~> 2.0)
|
15
15
|
websocket-driver (>= 0.6.1)
|
16
|
-
actionmailbox (7.0.
|
17
|
-
actionpack (= 7.0.
|
18
|
-
activejob (= 7.0.
|
19
|
-
activerecord (= 7.0.
|
20
|
-
activestorage (= 7.0.
|
21
|
-
activesupport (= 7.0.
|
16
|
+
actionmailbox (7.0.8.1)
|
17
|
+
actionpack (= 7.0.8.1)
|
18
|
+
activejob (= 7.0.8.1)
|
19
|
+
activerecord (= 7.0.8.1)
|
20
|
+
activestorage (= 7.0.8.1)
|
21
|
+
activesupport (= 7.0.8.1)
|
22
22
|
mail (>= 2.7.1)
|
23
23
|
net-imap
|
24
24
|
net-pop
|
25
25
|
net-smtp
|
26
|
-
actionmailer (7.0.
|
27
|
-
actionpack (= 7.0.
|
28
|
-
actionview (= 7.0.
|
29
|
-
activejob (= 7.0.
|
30
|
-
activesupport (= 7.0.
|
26
|
+
actionmailer (7.0.8.1)
|
27
|
+
actionpack (= 7.0.8.1)
|
28
|
+
actionview (= 7.0.8.1)
|
29
|
+
activejob (= 7.0.8.1)
|
30
|
+
activesupport (= 7.0.8.1)
|
31
31
|
mail (~> 2.5, >= 2.5.4)
|
32
32
|
net-imap
|
33
33
|
net-pop
|
34
34
|
net-smtp
|
35
35
|
rails-dom-testing (~> 2.0)
|
36
|
-
actionpack (7.0.
|
37
|
-
actionview (= 7.0.
|
38
|
-
activesupport (= 7.0.
|
36
|
+
actionpack (7.0.8.1)
|
37
|
+
actionview (= 7.0.8.1)
|
38
|
+
activesupport (= 7.0.8.1)
|
39
39
|
rack (~> 2.0, >= 2.2.4)
|
40
40
|
rack-test (>= 0.6.3)
|
41
41
|
rails-dom-testing (~> 2.0)
|
42
42
|
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
43
|
-
actiontext (7.0.
|
44
|
-
actionpack (= 7.0.
|
45
|
-
activerecord (= 7.0.
|
46
|
-
activestorage (= 7.0.
|
47
|
-
activesupport (= 7.0.
|
43
|
+
actiontext (7.0.8.1)
|
44
|
+
actionpack (= 7.0.8.1)
|
45
|
+
activerecord (= 7.0.8.1)
|
46
|
+
activestorage (= 7.0.8.1)
|
47
|
+
activesupport (= 7.0.8.1)
|
48
48
|
globalid (>= 0.6.0)
|
49
49
|
nokogiri (>= 1.8.5)
|
50
|
-
actionview (7.0.
|
51
|
-
activesupport (= 7.0.
|
50
|
+
actionview (7.0.8.1)
|
51
|
+
activesupport (= 7.0.8.1)
|
52
52
|
builder (~> 3.1)
|
53
53
|
erubi (~> 1.4)
|
54
54
|
rails-dom-testing (~> 2.0)
|
55
55
|
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
56
|
-
activejob (7.0.
|
57
|
-
activesupport (= 7.0.
|
56
|
+
activejob (7.0.8.1)
|
57
|
+
activesupport (= 7.0.8.1)
|
58
58
|
globalid (>= 0.3.6)
|
59
|
-
activemodel (7.0.
|
60
|
-
activesupport (= 7.0.
|
61
|
-
activerecord (7.0.
|
62
|
-
activemodel (= 7.0.
|
63
|
-
activesupport (= 7.0.
|
64
|
-
activestorage (7.0.
|
65
|
-
actionpack (= 7.0.
|
66
|
-
activejob (= 7.0.
|
67
|
-
activerecord (= 7.0.
|
68
|
-
activesupport (= 7.0.
|
59
|
+
activemodel (7.0.8.1)
|
60
|
+
activesupport (= 7.0.8.1)
|
61
|
+
activerecord (7.0.8.1)
|
62
|
+
activemodel (= 7.0.8.1)
|
63
|
+
activesupport (= 7.0.8.1)
|
64
|
+
activestorage (7.0.8.1)
|
65
|
+
actionpack (= 7.0.8.1)
|
66
|
+
activejob (= 7.0.8.1)
|
67
|
+
activerecord (= 7.0.8.1)
|
68
|
+
activesupport (= 7.0.8.1)
|
69
69
|
marcel (~> 1.0)
|
70
70
|
mini_mime (>= 1.1.0)
|
71
|
-
activesupport (7.0.
|
71
|
+
activesupport (7.0.8.1)
|
72
72
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
73
73
|
i18n (>= 1.6, < 2)
|
74
74
|
minitest (>= 5.1)
|
@@ -81,19 +81,19 @@ GEM
|
|
81
81
|
builder (3.2.4)
|
82
82
|
childprocess (4.1.0)
|
83
83
|
coderay (1.1.3)
|
84
|
-
concurrent-ruby (1.2.
|
84
|
+
concurrent-ruby (1.2.3)
|
85
85
|
crass (1.0.6)
|
86
|
-
date (3.3.
|
86
|
+
date (3.3.4)
|
87
87
|
diff-lcs (1.5.0)
|
88
88
|
erubi (1.12.0)
|
89
|
-
globalid (1.1
|
90
|
-
activesupport (>=
|
89
|
+
globalid (1.2.1)
|
90
|
+
activesupport (>= 6.1)
|
91
91
|
i18n (1.14.1)
|
92
92
|
concurrent-ruby (~> 1.0)
|
93
93
|
iniparse (1.5.0)
|
94
94
|
json (2.6.3)
|
95
95
|
language_server-protocol (3.17.0.3)
|
96
|
-
loofah (2.
|
96
|
+
loofah (2.22.0)
|
97
97
|
crass (~> 1.0.2)
|
98
98
|
nokogiri (>= 1.12.0)
|
99
99
|
mail (2.8.1)
|
@@ -103,21 +103,21 @@ GEM
|
|
103
103
|
net-smtp
|
104
104
|
marcel (1.0.2)
|
105
105
|
method_source (1.0.0)
|
106
|
-
mini_mime (1.1.
|
107
|
-
minitest (5.
|
108
|
-
net-imap (0.
|
106
|
+
mini_mime (1.1.5)
|
107
|
+
minitest (5.22.2)
|
108
|
+
net-imap (0.4.10)
|
109
109
|
date
|
110
110
|
net-protocol
|
111
111
|
net-pop (0.1.2)
|
112
112
|
net-protocol
|
113
|
-
net-protocol (0.2.
|
113
|
+
net-protocol (0.2.2)
|
114
114
|
timeout
|
115
|
-
net-smtp (0.
|
115
|
+
net-smtp (0.4.0.1)
|
116
116
|
net-protocol
|
117
|
-
nio4r (2.
|
118
|
-
nokogiri (1.
|
117
|
+
nio4r (2.7.0)
|
118
|
+
nokogiri (1.16.2-arm64-darwin)
|
119
119
|
racc (~> 1.4)
|
120
|
-
nokogiri (1.
|
120
|
+
nokogiri (1.16.2-x86_64-linux)
|
121
121
|
racc (~> 1.4)
|
122
122
|
overcommit (0.60.0)
|
123
123
|
childprocess (>= 0.6.3, < 5)
|
@@ -130,40 +130,40 @@ GEM
|
|
130
130
|
pry (0.14.2)
|
131
131
|
coderay (~> 1.1)
|
132
132
|
method_source (~> 1.0)
|
133
|
-
racc (1.7.
|
134
|
-
rack (2.2.
|
133
|
+
racc (1.7.3)
|
134
|
+
rack (2.2.8.1)
|
135
135
|
rack-test (2.1.0)
|
136
136
|
rack (>= 1.3)
|
137
|
-
rails (7.0.
|
138
|
-
actioncable (= 7.0.
|
139
|
-
actionmailbox (= 7.0.
|
140
|
-
actionmailer (= 7.0.
|
141
|
-
actionpack (= 7.0.
|
142
|
-
actiontext (= 7.0.
|
143
|
-
actionview (= 7.0.
|
144
|
-
activejob (= 7.0.
|
145
|
-
activemodel (= 7.0.
|
146
|
-
activerecord (= 7.0.
|
147
|
-
activestorage (= 7.0.
|
148
|
-
activesupport (= 7.0.
|
137
|
+
rails (7.0.8.1)
|
138
|
+
actioncable (= 7.0.8.1)
|
139
|
+
actionmailbox (= 7.0.8.1)
|
140
|
+
actionmailer (= 7.0.8.1)
|
141
|
+
actionpack (= 7.0.8.1)
|
142
|
+
actiontext (= 7.0.8.1)
|
143
|
+
actionview (= 7.0.8.1)
|
144
|
+
activejob (= 7.0.8.1)
|
145
|
+
activemodel (= 7.0.8.1)
|
146
|
+
activerecord (= 7.0.8.1)
|
147
|
+
activestorage (= 7.0.8.1)
|
148
|
+
activesupport (= 7.0.8.1)
|
149
149
|
bundler (>= 1.15.0)
|
150
|
-
railties (= 7.0.
|
151
|
-
rails-dom-testing (2.
|
150
|
+
railties (= 7.0.8.1)
|
151
|
+
rails-dom-testing (2.2.0)
|
152
152
|
activesupport (>= 5.0.0)
|
153
153
|
minitest
|
154
154
|
nokogiri (>= 1.6)
|
155
155
|
rails-html-sanitizer (1.6.0)
|
156
156
|
loofah (~> 2.21)
|
157
157
|
nokogiri (~> 1.14)
|
158
|
-
railties (7.0.
|
159
|
-
actionpack (= 7.0.
|
160
|
-
activesupport (= 7.0.
|
158
|
+
railties (7.0.8.1)
|
159
|
+
actionpack (= 7.0.8.1)
|
160
|
+
activesupport (= 7.0.8.1)
|
161
161
|
method_source
|
162
162
|
rake (>= 12.2)
|
163
163
|
thor (~> 1.0)
|
164
164
|
zeitwerk (~> 2.5)
|
165
165
|
rainbow (3.1.1)
|
166
|
-
rake (13.0
|
166
|
+
rake (13.1.0)
|
167
167
|
rb-readline (0.5.5)
|
168
168
|
regexp_parser (2.8.1)
|
169
169
|
rexml (3.2.5)
|
@@ -194,21 +194,22 @@ GEM
|
|
194
194
|
rubocop-ast (1.29.0)
|
195
195
|
parser (>= 3.2.1.0)
|
196
196
|
ruby-progressbar (1.13.0)
|
197
|
-
sqlite3 (1.
|
198
|
-
sqlite3 (1.
|
199
|
-
thor (1.
|
197
|
+
sqlite3 (1.7.2-arm64-darwin)
|
198
|
+
sqlite3 (1.7.2-x86_64-linux)
|
199
|
+
thor (1.3.1)
|
200
200
|
timecop (0.9.6)
|
201
|
-
timeout (0.4.
|
201
|
+
timeout (0.4.1)
|
202
202
|
tzinfo (2.0.6)
|
203
203
|
concurrent-ruby (~> 1.0)
|
204
204
|
unicode-display_width (2.4.2)
|
205
|
-
websocket-driver (0.7.
|
205
|
+
websocket-driver (0.7.6)
|
206
206
|
websocket-extensions (>= 0.1.0)
|
207
207
|
websocket-extensions (0.1.5)
|
208
|
-
zeitwerk (2.6.
|
208
|
+
zeitwerk (2.6.13)
|
209
209
|
|
210
210
|
PLATFORMS
|
211
211
|
arm64-darwin-22
|
212
|
+
arm64-darwin-23
|
212
213
|
x86_64-linux
|
213
214
|
|
214
215
|
DEPENDENCIES
|
@@ -216,14 +217,14 @@ DEPENDENCIES
|
|
216
217
|
data_migrate!
|
217
218
|
overcommit
|
218
219
|
pry
|
219
|
-
rails (~> 7.0)
|
220
|
+
rails (~> 7.0.0)
|
220
221
|
rake
|
221
222
|
rb-readline
|
222
223
|
rspec
|
223
224
|
rspec-core
|
224
225
|
rubocop
|
225
|
-
sqlite3
|
226
|
+
sqlite3
|
226
227
|
timecop
|
227
228
|
|
228
229
|
BUNDLED WITH
|
229
|
-
2.
|
230
|
+
2.5.6
|
data/gemfiles/rails_7.1.gemfile
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ..
|
3
3
|
specs:
|
4
|
-
data_migrate (9.
|
4
|
+
data_migrate (9.3.0)
|
5
5
|
activerecord (>= 6.1)
|
6
6
|
railties (>= 6.1)
|
7
7
|
|
@@ -86,17 +86,17 @@ GEM
|
|
86
86
|
rake
|
87
87
|
thor (>= 0.14.0)
|
88
88
|
ast (2.4.2)
|
89
|
-
base64 (0.
|
90
|
-
bigdecimal (3.1.
|
89
|
+
base64 (0.2.0)
|
90
|
+
bigdecimal (3.1.6)
|
91
91
|
builder (3.2.4)
|
92
92
|
childprocess (4.1.0)
|
93
93
|
coderay (1.1.3)
|
94
|
-
concurrent-ruby (1.2.
|
94
|
+
concurrent-ruby (1.2.3)
|
95
95
|
connection_pool (2.4.1)
|
96
96
|
crass (1.0.6)
|
97
|
-
date (3.3.
|
97
|
+
date (3.3.4)
|
98
98
|
diff-lcs (1.5.0)
|
99
|
-
drb (2.
|
99
|
+
drb (2.2.0)
|
100
100
|
ruby2_keywords
|
101
101
|
erubi (1.12.0)
|
102
102
|
globalid (1.2.1)
|
@@ -104,13 +104,13 @@ GEM
|
|
104
104
|
i18n (1.14.1)
|
105
105
|
concurrent-ruby (~> 1.0)
|
106
106
|
iniparse (1.5.0)
|
107
|
-
io-console (0.
|
108
|
-
irb (1.
|
107
|
+
io-console (0.7.2)
|
108
|
+
irb (1.11.2)
|
109
109
|
rdoc
|
110
|
-
reline (>= 0.
|
110
|
+
reline (>= 0.4.2)
|
111
111
|
json (2.6.3)
|
112
112
|
language_server-protocol (3.17.0.3)
|
113
|
-
loofah (2.
|
113
|
+
loofah (2.22.0)
|
114
114
|
crass (~> 1.0.2)
|
115
115
|
nokogiri (>= 1.12.0)
|
116
116
|
mail (2.8.1)
|
@@ -118,24 +118,24 @@ GEM
|
|
118
118
|
net-imap
|
119
119
|
net-pop
|
120
120
|
net-smtp
|
121
|
-
marcel (1.0.
|
121
|
+
marcel (1.0.4)
|
122
122
|
method_source (1.0.0)
|
123
123
|
mini_mime (1.1.5)
|
124
|
-
minitest (5.
|
125
|
-
mutex_m (0.
|
126
|
-
net-imap (0.4.
|
124
|
+
minitest (5.22.2)
|
125
|
+
mutex_m (0.2.0)
|
126
|
+
net-imap (0.4.10)
|
127
127
|
date
|
128
128
|
net-protocol
|
129
129
|
net-pop (0.1.2)
|
130
130
|
net-protocol
|
131
|
-
net-protocol (0.2.
|
131
|
+
net-protocol (0.2.2)
|
132
132
|
timeout
|
133
|
-
net-smtp (0.4.0)
|
133
|
+
net-smtp (0.4.0.1)
|
134
134
|
net-protocol
|
135
|
-
nio4r (2.
|
136
|
-
nokogiri (1.
|
135
|
+
nio4r (2.7.0)
|
136
|
+
nokogiri (1.16.2-arm64-darwin)
|
137
137
|
racc (~> 1.4)
|
138
|
-
nokogiri (1.
|
138
|
+
nokogiri (1.16.2-x86_64-linux)
|
139
139
|
racc (~> 1.4)
|
140
140
|
overcommit (0.60.0)
|
141
141
|
childprocess (>= 0.6.3, < 5)
|
@@ -148,10 +148,10 @@ GEM
|
|
148
148
|
pry (0.14.2)
|
149
149
|
coderay (~> 1.1)
|
150
150
|
method_source (~> 1.0)
|
151
|
-
psych (5.1.
|
151
|
+
psych (5.1.2)
|
152
152
|
stringio
|
153
|
-
racc (1.7.
|
154
|
-
rack (3.0.
|
153
|
+
racc (1.7.3)
|
154
|
+
rack (3.0.9.1)
|
155
155
|
rack-session (2.0.0)
|
156
156
|
rack (>= 3.0.0)
|
157
157
|
rack-test (2.1.0)
|
@@ -189,12 +189,12 @@ GEM
|
|
189
189
|
thor (~> 1.0, >= 1.2.2)
|
190
190
|
zeitwerk (~> 2.6)
|
191
191
|
rainbow (3.1.1)
|
192
|
-
rake (13.0
|
192
|
+
rake (13.1.0)
|
193
193
|
rb-readline (0.5.5)
|
194
|
-
rdoc (6.
|
194
|
+
rdoc (6.6.2)
|
195
195
|
psych (>= 4.0.0)
|
196
196
|
regexp_parser (2.8.1)
|
197
|
-
reline (0.3
|
197
|
+
reline (0.4.3)
|
198
198
|
io-console (~> 0.5)
|
199
199
|
rexml (3.2.5)
|
200
200
|
rspec (3.12.0)
|
@@ -225,12 +225,12 @@ GEM
|
|
225
225
|
parser (>= 3.2.1.0)
|
226
226
|
ruby-progressbar (1.13.0)
|
227
227
|
ruby2_keywords (0.0.5)
|
228
|
-
sqlite3 (1.
|
229
|
-
sqlite3 (1.
|
230
|
-
stringio (3.0
|
231
|
-
thor (1.
|
228
|
+
sqlite3 (1.7.2-arm64-darwin)
|
229
|
+
sqlite3 (1.7.2-x86_64-linux)
|
230
|
+
stringio (3.1.0)
|
231
|
+
thor (1.3.1)
|
232
232
|
timecop (0.9.6)
|
233
|
-
timeout (0.4.
|
233
|
+
timeout (0.4.1)
|
234
234
|
tzinfo (2.0.6)
|
235
235
|
concurrent-ruby (~> 1.0)
|
236
236
|
unicode-display_width (2.4.2)
|
@@ -238,10 +238,11 @@ GEM
|
|
238
238
|
websocket-driver (0.7.6)
|
239
239
|
websocket-extensions (>= 0.1.0)
|
240
240
|
websocket-extensions (0.1.5)
|
241
|
-
zeitwerk (2.6.
|
241
|
+
zeitwerk (2.6.13)
|
242
242
|
|
243
243
|
PLATFORMS
|
244
244
|
arm64-darwin-22
|
245
|
+
arm64-darwin-23
|
245
246
|
x86_64-linux
|
246
247
|
|
247
248
|
DEPENDENCIES
|
@@ -255,7 +256,7 @@ DEPENDENCIES
|
|
255
256
|
rspec
|
256
257
|
rspec-core
|
257
258
|
rubocop
|
258
|
-
sqlite3
|
259
|
+
sqlite3
|
259
260
|
timecop
|
260
261
|
|
261
262
|
BUNDLED WITH
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module DataMigrate
|
2
|
+
# This wrapper is used to differentiate between
|
3
|
+
# a data and schema db config when running migrations
|
4
|
+
class DatabaseConfigurationWrapper
|
5
|
+
attr_reader :db_config
|
6
|
+
|
7
|
+
def initialize(db_config)
|
8
|
+
@db_config = db_config
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -5,87 +5,142 @@ require "data_migrate/config"
|
|
5
5
|
module DataMigrate
|
6
6
|
##
|
7
7
|
# This class extends DatabaseTasks to add a schema_file method.
|
8
|
-
|
8
|
+
module DatabaseTasks
|
9
9
|
extend ActiveRecord::Tasks::DatabaseTasks
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
19
|
-
|
20
|
-
# This method is removed in Rails 7.0
|
21
|
-
def dump_filename(spec_name, format = ActiveRecord::Base.schema_format)
|
22
|
-
filename = if spec_name == "primary"
|
23
|
-
schema_file_type(format)
|
10
|
+
extend self
|
11
|
+
|
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:
|
15
|
+
if name
|
16
|
+
db_config = ActiveRecord::Base.configurations.configs_for(env_name: env, name: name)
|
17
|
+
with_temporary_connection(db_config, &block)
|
24
18
|
else
|
25
|
-
|
19
|
+
ActiveRecord::Base.configurations.configs_for(env_name: env, name: name).each do |db_config|
|
20
|
+
with_temporary_connection(db_config, &block)
|
21
|
+
end
|
26
22
|
end
|
27
|
-
|
28
|
-
ENV["DATA_SCHEMA"] || File.join(db_dir, filename)
|
29
23
|
end
|
30
24
|
|
31
|
-
def
|
32
|
-
|
33
|
-
|
34
|
-
Kernel.abort message
|
25
|
+
def with_temporary_connection(db_config) # :nodoc:
|
26
|
+
with_temporary_pool(db_config) do |pool|
|
27
|
+
yield pool.connection
|
35
28
|
end
|
36
29
|
end
|
37
30
|
|
38
|
-
def
|
39
|
-
|
40
|
-
pending_schema_migrations,
|
41
|
-
pending_data_migrations
|
42
|
-
)
|
31
|
+
def migration_class # :nodoc:
|
32
|
+
ActiveRecord::Base
|
43
33
|
end
|
44
34
|
|
45
|
-
def
|
46
|
-
|
35
|
+
def migration_connection # :nodoc:
|
36
|
+
migration_class.connection
|
47
37
|
end
|
48
38
|
|
49
|
-
def
|
50
|
-
|
51
|
-
|
39
|
+
private def with_temporary_pool(db_config)
|
40
|
+
original_db_config = migration_class.connection_db_config
|
41
|
+
pool = migration_class.connection_handler.establish_connection(db_config)
|
52
42
|
|
53
|
-
|
54
|
-
|
43
|
+
yield pool
|
44
|
+
ensure
|
45
|
+
migration_class.connection_handler.establish_connection(original_db_config)
|
55
46
|
end
|
47
|
+
end
|
56
48
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
49
|
+
def db_configs_with_versions
|
50
|
+
db_configs_with_versions = Hash.new { |h, k| h[k] = [] }
|
51
|
+
|
52
|
+
with_temporary_connection_for_each do |conn|
|
53
|
+
db_config = conn.pool.db_config
|
54
|
+
if db_config.primary?
|
55
|
+
versions_to_run = DataMigrate::DatabaseTasks.pending_data_migrations.map { |m| m[:version] }
|
56
|
+
target_version = ActiveRecord::Tasks::DatabaseTasks.target_version
|
57
|
+
|
58
|
+
versions_to_run.each do |version|
|
59
|
+
next if target_version && target_version != version
|
60
|
+
db_configs_with_versions[version] << DatabaseConfigurationWrapper.new(db_config)
|
61
|
+
end
|
68
62
|
end
|
69
63
|
end
|
70
64
|
|
71
|
-
|
72
|
-
|
65
|
+
db_configs_with_versions
|
66
|
+
end
|
73
67
|
|
74
|
-
|
75
|
-
|
68
|
+
def schema_file(_format = nil)
|
69
|
+
File.join(db_dir, "data_schema.rb")
|
70
|
+
end
|
76
71
|
|
77
|
-
|
72
|
+
def schema_file_type(_format = nil)
|
73
|
+
"data_schema.rb"
|
74
|
+
end
|
75
|
+
|
76
|
+
# This method is removed in Rails 7.0
|
77
|
+
def dump_filename(spec_name, format = ActiveRecord::Base.schema_format)
|
78
|
+
filename = if spec_name == "primary"
|
79
|
+
schema_file_type(format)
|
80
|
+
else
|
81
|
+
"#{spec_name}_#{schema_file_type(format)}"
|
78
82
|
end
|
79
83
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
84
|
+
ENV["DATA_SCHEMA"] || File.join(db_dir, filename)
|
85
|
+
end
|
86
|
+
|
87
|
+
def check_schema_file(filename)
|
88
|
+
unless File.exist?(filename)
|
89
|
+
message = +%{#{filename} doesn't exist yet. Run `rake data:migrate` to create it, then try again.}
|
90
|
+
Kernel.abort message
|
85
91
|
end
|
86
92
|
end
|
87
93
|
|
88
|
-
def
|
94
|
+
def pending_migrations
|
95
|
+
sort_migrations(
|
96
|
+
pending_schema_migrations,
|
97
|
+
pending_data_migrations
|
98
|
+
)
|
99
|
+
end
|
100
|
+
|
101
|
+
def sort_migrations(*migrations)
|
102
|
+
migrations.flatten.sort { |a, b| sort_string(a) <=> sort_string(b) }
|
103
|
+
end
|
104
|
+
|
105
|
+
def sort_string migration
|
106
|
+
"#{migration[:version]}_#{migration[:kind] == :data ? 1 : 0}"
|
107
|
+
end
|
108
|
+
|
109
|
+
def data_migrations_path
|
110
|
+
::DataMigrate.config.data_migrations_path
|
111
|
+
end
|
112
|
+
|
113
|
+
def run_migration(migration, direction)
|
114
|
+
if migration[:kind] == :data
|
115
|
+
::ActiveRecord::Migration.write("== %s %s" % ['Data', "=" * 71])
|
116
|
+
::DataMigrate::DataMigrator.run(direction, data_migrations_path, migration[:version])
|
117
|
+
else
|
118
|
+
::ActiveRecord::Migration.write("== %s %s" % ['Schema', "=" * 69])
|
119
|
+
::DataMigrate::SchemaMigration.run(
|
120
|
+
direction,
|
121
|
+
::DataMigrate::SchemaMigration.migrations_paths,
|
122
|
+
migration[:version]
|
123
|
+
)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
def schema_dump_path(db_config, format = ActiveRecord.schema_format)
|
128
|
+
return ENV["DATA_SCHEMA"] if ENV["DATA_SCHEMA"]
|
129
|
+
|
130
|
+
# We only require a schema.rb file for the primary database
|
131
|
+
return unless db_config.primary?
|
132
|
+
|
133
|
+
File.join(File.dirname(ActiveRecord::Tasks::DatabaseTasks.schema_dump_path(db_config, format)), schema_file_type)
|
134
|
+
end
|
135
|
+
|
136
|
+
# Override this method from `ActiveRecord::Tasks::DatabaseTasks`
|
137
|
+
# to ensure that the sha saved in ar_internal_metadata table
|
138
|
+
# is from the original schema.rb file
|
139
|
+
def schema_sha1(file)
|
140
|
+
ActiveRecord::Tasks::DatabaseTasks.schema_dump_path(ActiveRecord::Base.configurations.configs_for(env_name: ActiveRecord::Tasks::DatabaseTasks.env, name: "primary"))
|
141
|
+
end
|
142
|
+
|
143
|
+
def forward(step = 1)
|
89
144
|
DataMigrate::DataMigrator.create_data_schema_table
|
90
145
|
migrations = pending_migrations.reverse.pop(step).reverse
|
91
146
|
migrations.each do | pending_migration |
|
@@ -99,7 +154,7 @@ module DataMigrate
|
|
99
154
|
end
|
100
155
|
end
|
101
156
|
|
102
|
-
def
|
157
|
+
def pending_data_migrations
|
103
158
|
data_migrations = DataMigrate::DataMigrator.migrations(data_migrations_path)
|
104
159
|
data_migrator = DataMigrate::RailsHelper.data_migrator(:up, data_migrations)
|
105
160
|
sort_migrations(
|
@@ -107,11 +162,11 @@ module DataMigrate
|
|
107
162
|
)
|
108
163
|
end
|
109
164
|
|
110
|
-
def
|
165
|
+
def pending_schema_migrations
|
111
166
|
::DataMigrate::SchemaMigration.pending_schema_migrations
|
112
167
|
end
|
113
168
|
|
114
|
-
def
|
169
|
+
def past_migrations(sort = nil)
|
115
170
|
data_versions = DataMigrate::RailsHelper.data_schema_migration.table_exists? ? DataMigrate::RailsHelper.data_schema_migration.normalized_versions : []
|
116
171
|
schema_versions = DataMigrate::RailsHelper.schema_migration.normalized_versions
|
117
172
|
migrations = data_versions.map { |v| { version: v.to_i, kind: :data } } + schema_versions.map { |v| { version: v.to_i, kind: :schema } }
|