monarch_migrate 0.6.0 → 0.8.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/ci.yml +6 -8
- data/.gitignore +3 -0
- data/.ruby-version +1 -1
- data/Appraisals +7 -3
- data/Gemfile.lock +151 -120
- data/README.md +23 -10
- data/bin/console +7 -0
- data/lib/generators/monarch_migrate/install/install_generator.rb +12 -12
- data/lib/generators/rails/data_migration/data_migration_generator.rb +10 -2
- data/lib/generators/rspec/data_migration_generator.rb +20 -18
- data/lib/generators/test_unit/data_migration_generator.rb +20 -17
- data/lib/monarch_migrate/migration.rb +11 -1
- data/lib/monarch_migrate/version.rb +1 -1
- data/lib/monarch_migrate.rb +1 -0
- data/monarch_migrate.gemspec +3 -3
- metadata +9 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8c8760b8a5929fc1b93c0fa006cb9557b4ef7e7fc942dc8af78aaa1294e2da9b
|
4
|
+
data.tar.gz: 9286f3dff8556f56221302bd3b4233d94ecb999a27337a18e199421046d0e1d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 176ef9b9a375c4454c53e459ce38dc539d61d92eabe0e2d05105a0555414f1f51b8546396f925537dcb27370b3dc3dace33b857be5fc65ba00282da767c3d048
|
7
|
+
data.tar.gz: 8e147b8f1661cbf76bcd06d6d3fc1619f63c72cb006f456c5d38366930833d7a5a15ad0d5bfff94869d661aa59330fdace239146d48308c6a774d32765ea7b3c
|
data/.github/workflows/ci.yml
CHANGED
@@ -16,18 +16,14 @@ jobs:
|
|
16
16
|
fail-fast: false
|
17
17
|
matrix:
|
18
18
|
gemfile:
|
19
|
-
- "5.2"
|
20
19
|
- "6.1"
|
21
20
|
- "7.0"
|
21
|
+
- "7.1"
|
22
22
|
ruby:
|
23
|
-
- "2.7.3"
|
24
23
|
- "3.0.0"
|
25
24
|
- "3.1.0"
|
26
|
-
|
27
|
-
-
|
28
|
-
ruby: "3.0.0"
|
29
|
-
- gemfile: "5.2"
|
30
|
-
ruby: "3.1.0"
|
25
|
+
- "3.2.2"
|
26
|
+
- "3.3.0"
|
31
27
|
|
32
28
|
env:
|
33
29
|
BUNDLE_GEMFILE: gemfiles/rails_${{ matrix.gemfile }}.gemfile
|
@@ -43,7 +39,9 @@ jobs:
|
|
43
39
|
bundler-cache: true
|
44
40
|
|
45
41
|
- name: "Reset app database"
|
46
|
-
run:
|
42
|
+
run: |
|
43
|
+
bundle exec rake fake:db:reset
|
44
|
+
bundle exec rake fake:db:test:prepare
|
47
45
|
|
48
46
|
- name: "Run tests without acceptance"
|
49
47
|
run: |
|
data/.gitignore
CHANGED
@@ -73,6 +73,7 @@ fabric.properties
|
|
73
73
|
|
74
74
|
# Migration generated during tests
|
75
75
|
/test/generators/**/tmp
|
76
|
+
/test/fixtures/tmp
|
76
77
|
|
77
78
|
# Ignore gem compile directory
|
78
79
|
/pkg
|
@@ -85,6 +86,8 @@ fabric.properties
|
|
85
86
|
# Ignore the default SQLite database.
|
86
87
|
/db/*.sqlite3
|
87
88
|
/db/*.sqlite3-journal
|
89
|
+
/db/*.sqlite3-shm
|
90
|
+
/db/*.sqlite3-wal
|
88
91
|
|
89
92
|
# Ignore all logfiles and tempfiles.
|
90
93
|
/log/*
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
3.3.0
|
data/Appraisals
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
# Support Rails release series that receive patches and new versions
|
2
|
+
# in case of a security issue.
|
3
|
+
# See https://guides.rubyonrails.org/maintenance_policy.html#security-issues
|
4
4
|
|
5
5
|
appraise "rails_6.1" do
|
6
6
|
gem "rails", "~> 6.1"
|
@@ -12,3 +12,7 @@ end
|
|
12
12
|
appraise "rails_7.0" do
|
13
13
|
gem "rails", "~> 7.0"
|
14
14
|
end
|
15
|
+
|
16
|
+
appraise "rails_7.1" do
|
17
|
+
gem "rails", "~> 7.1.0"
|
18
|
+
end
|
data/Gemfile.lock
CHANGED
@@ -1,121 +1,137 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
monarch_migrate (0.
|
5
|
-
rails (>=
|
4
|
+
monarch_migrate (0.8.0)
|
5
|
+
rails (>= 6.0)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
actioncable (7.
|
11
|
-
actionpack (= 7.
|
12
|
-
activesupport (= 7.
|
10
|
+
actioncable (7.1.3.2)
|
11
|
+
actionpack (= 7.1.3.2)
|
12
|
+
activesupport (= 7.1.3.2)
|
13
13
|
nio4r (~> 2.0)
|
14
14
|
websocket-driver (>= 0.6.1)
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
15
|
+
zeitwerk (~> 2.6)
|
16
|
+
actionmailbox (7.1.3.2)
|
17
|
+
actionpack (= 7.1.3.2)
|
18
|
+
activejob (= 7.1.3.2)
|
19
|
+
activerecord (= 7.1.3.2)
|
20
|
+
activestorage (= 7.1.3.2)
|
21
|
+
activesupport (= 7.1.3.2)
|
21
22
|
mail (>= 2.7.1)
|
22
23
|
net-imap
|
23
24
|
net-pop
|
24
25
|
net-smtp
|
25
|
-
actionmailer (7.
|
26
|
-
actionpack (= 7.
|
27
|
-
actionview (= 7.
|
28
|
-
activejob (= 7.
|
29
|
-
activesupport (= 7.
|
26
|
+
actionmailer (7.1.3.2)
|
27
|
+
actionpack (= 7.1.3.2)
|
28
|
+
actionview (= 7.1.3.2)
|
29
|
+
activejob (= 7.1.3.2)
|
30
|
+
activesupport (= 7.1.3.2)
|
30
31
|
mail (~> 2.5, >= 2.5.4)
|
31
32
|
net-imap
|
32
33
|
net-pop
|
33
34
|
net-smtp
|
34
|
-
rails-dom-testing (~> 2.
|
35
|
-
actionpack (7.
|
36
|
-
actionview (= 7.
|
37
|
-
activesupport (= 7.
|
38
|
-
|
35
|
+
rails-dom-testing (~> 2.2)
|
36
|
+
actionpack (7.1.3.2)
|
37
|
+
actionview (= 7.1.3.2)
|
38
|
+
activesupport (= 7.1.3.2)
|
39
|
+
nokogiri (>= 1.8.5)
|
40
|
+
racc
|
41
|
+
rack (>= 2.2.4)
|
42
|
+
rack-session (>= 1.0.1)
|
39
43
|
rack-test (>= 0.6.3)
|
40
|
-
rails-dom-testing (~> 2.
|
41
|
-
rails-html-sanitizer (~> 1.
|
42
|
-
actiontext (7.
|
43
|
-
actionpack (= 7.
|
44
|
-
activerecord (= 7.
|
45
|
-
activestorage (= 7.
|
46
|
-
activesupport (= 7.
|
44
|
+
rails-dom-testing (~> 2.2)
|
45
|
+
rails-html-sanitizer (~> 1.6)
|
46
|
+
actiontext (7.1.3.2)
|
47
|
+
actionpack (= 7.1.3.2)
|
48
|
+
activerecord (= 7.1.3.2)
|
49
|
+
activestorage (= 7.1.3.2)
|
50
|
+
activesupport (= 7.1.3.2)
|
47
51
|
globalid (>= 0.6.0)
|
48
52
|
nokogiri (>= 1.8.5)
|
49
|
-
actionview (7.
|
50
|
-
activesupport (= 7.
|
53
|
+
actionview (7.1.3.2)
|
54
|
+
activesupport (= 7.1.3.2)
|
51
55
|
builder (~> 3.1)
|
52
|
-
erubi (~> 1.
|
53
|
-
rails-dom-testing (~> 2.
|
54
|
-
rails-html-sanitizer (~> 1.
|
55
|
-
activejob (7.
|
56
|
-
activesupport (= 7.
|
56
|
+
erubi (~> 1.11)
|
57
|
+
rails-dom-testing (~> 2.2)
|
58
|
+
rails-html-sanitizer (~> 1.6)
|
59
|
+
activejob (7.1.3.2)
|
60
|
+
activesupport (= 7.1.3.2)
|
57
61
|
globalid (>= 0.3.6)
|
58
|
-
activemodel (7.
|
59
|
-
activesupport (= 7.
|
60
|
-
activerecord (7.
|
61
|
-
activemodel (= 7.
|
62
|
-
activesupport (= 7.
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
62
|
+
activemodel (7.1.3.2)
|
63
|
+
activesupport (= 7.1.3.2)
|
64
|
+
activerecord (7.1.3.2)
|
65
|
+
activemodel (= 7.1.3.2)
|
66
|
+
activesupport (= 7.1.3.2)
|
67
|
+
timeout (>= 0.4.0)
|
68
|
+
activestorage (7.1.3.2)
|
69
|
+
actionpack (= 7.1.3.2)
|
70
|
+
activejob (= 7.1.3.2)
|
71
|
+
activerecord (= 7.1.3.2)
|
72
|
+
activesupport (= 7.1.3.2)
|
68
73
|
marcel (~> 1.0)
|
69
|
-
|
70
|
-
|
74
|
+
activesupport (7.1.3.2)
|
75
|
+
base64
|
76
|
+
bigdecimal
|
71
77
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
78
|
+
connection_pool (>= 2.2.5)
|
79
|
+
drb
|
72
80
|
i18n (>= 1.6, < 2)
|
73
81
|
minitest (>= 5.1)
|
82
|
+
mutex_m
|
74
83
|
tzinfo (~> 2.0)
|
75
84
|
appraisal (2.4.1)
|
76
85
|
bundler
|
77
86
|
rake
|
78
87
|
thor (>= 0.14.0)
|
79
88
|
ast (2.4.2)
|
89
|
+
base64 (0.2.0)
|
90
|
+
bigdecimal (3.1.6)
|
80
91
|
break (0.40.0)
|
81
92
|
builder (3.2.4)
|
82
93
|
coderay (1.1.3)
|
83
|
-
concurrent-ruby (1.
|
94
|
+
concurrent-ruby (1.2.3)
|
95
|
+
connection_pool (2.4.1)
|
84
96
|
crass (1.0.6)
|
97
|
+
date (3.3.3)
|
85
98
|
diff-lcs (1.5.0)
|
86
|
-
|
87
|
-
erubi (1.
|
88
|
-
globalid (1.
|
89
|
-
activesupport (>=
|
90
|
-
i18n (1.
|
99
|
+
drb (2.2.1)
|
100
|
+
erubi (1.12.0)
|
101
|
+
globalid (1.2.1)
|
102
|
+
activesupport (>= 6.1)
|
103
|
+
i18n (1.14.1)
|
91
104
|
concurrent-ruby (~> 1.0)
|
92
|
-
|
105
|
+
io-console (0.7.2)
|
106
|
+
irb (1.11.2)
|
107
|
+
rdoc
|
108
|
+
reline (>= 0.4.2)
|
109
|
+
loofah (2.22.0)
|
93
110
|
crass (~> 1.0.2)
|
94
|
-
nokogiri (>= 1.
|
95
|
-
mail (2.
|
111
|
+
nokogiri (>= 1.12.0)
|
112
|
+
mail (2.8.1)
|
96
113
|
mini_mime (>= 0.1.1)
|
97
|
-
|
114
|
+
net-imap
|
115
|
+
net-pop
|
116
|
+
net-smtp
|
117
|
+
marcel (1.0.4)
|
98
118
|
method_source (1.0.0)
|
99
|
-
mini_mime (1.1.
|
100
|
-
mini_portile2 (2.8.
|
101
|
-
minitest (5.
|
102
|
-
|
103
|
-
|
119
|
+
mini_mime (1.1.5)
|
120
|
+
mini_portile2 (2.8.5)
|
121
|
+
minitest (5.22.2)
|
122
|
+
mutex_m (0.2.0)
|
123
|
+
net-imap (0.3.6)
|
124
|
+
date
|
104
125
|
net-protocol
|
105
|
-
|
106
|
-
net-pop (0.1.1)
|
107
|
-
digest
|
126
|
+
net-pop (0.1.2)
|
108
127
|
net-protocol
|
128
|
+
net-protocol (0.2.1)
|
109
129
|
timeout
|
110
|
-
net-
|
111
|
-
timeout
|
112
|
-
net-smtp (0.3.1)
|
113
|
-
digest
|
130
|
+
net-smtp (0.3.3)
|
114
131
|
net-protocol
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
mini_portile2 (~> 2.8.0)
|
132
|
+
nio4r (2.5.9)
|
133
|
+
nokogiri (1.16.2)
|
134
|
+
mini_portile2 (~> 2.8.2)
|
119
135
|
racc (~> 1.4)
|
120
136
|
parallel (1.22.1)
|
121
137
|
parser (3.1.2.0)
|
@@ -123,57 +139,71 @@ GEM
|
|
123
139
|
pry (0.14.1)
|
124
140
|
coderay (~> 1.1)
|
125
141
|
method_source (~> 1.0)
|
126
|
-
|
127
|
-
|
128
|
-
|
142
|
+
psych (5.1.2)
|
143
|
+
stringio
|
144
|
+
racc (1.7.3)
|
145
|
+
rack (3.0.9.1)
|
146
|
+
rack-session (2.0.0)
|
147
|
+
rack (>= 3.0.0)
|
148
|
+
rack-test (2.1.0)
|
129
149
|
rack (>= 1.3)
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
150
|
+
rackup (2.1.0)
|
151
|
+
rack (>= 3)
|
152
|
+
webrick (~> 1.8)
|
153
|
+
rails (7.1.3.2)
|
154
|
+
actioncable (= 7.1.3.2)
|
155
|
+
actionmailbox (= 7.1.3.2)
|
156
|
+
actionmailer (= 7.1.3.2)
|
157
|
+
actionpack (= 7.1.3.2)
|
158
|
+
actiontext (= 7.1.3.2)
|
159
|
+
actionview (= 7.1.3.2)
|
160
|
+
activejob (= 7.1.3.2)
|
161
|
+
activemodel (= 7.1.3.2)
|
162
|
+
activerecord (= 7.1.3.2)
|
163
|
+
activestorage (= 7.1.3.2)
|
164
|
+
activesupport (= 7.1.3.2)
|
142
165
|
bundler (>= 1.15.0)
|
143
|
-
railties (= 7.
|
144
|
-
rails-dom-testing (2.0
|
145
|
-
activesupport (>=
|
166
|
+
railties (= 7.1.3.2)
|
167
|
+
rails-dom-testing (2.2.0)
|
168
|
+
activesupport (>= 5.0.0)
|
169
|
+
minitest
|
146
170
|
nokogiri (>= 1.6)
|
147
|
-
rails-html-sanitizer (1.
|
148
|
-
loofah (~> 2.
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
171
|
+
rails-html-sanitizer (1.6.0)
|
172
|
+
loofah (~> 2.21)
|
173
|
+
nokogiri (~> 1.14)
|
174
|
+
railties (7.1.3.2)
|
175
|
+
actionpack (= 7.1.3.2)
|
176
|
+
activesupport (= 7.1.3.2)
|
177
|
+
irb
|
178
|
+
rackup (>= 1.0.0)
|
153
179
|
rake (>= 12.2)
|
154
|
-
thor (~> 1.0)
|
155
|
-
zeitwerk (~> 2.
|
180
|
+
thor (~> 1.0, >= 1.2.2)
|
181
|
+
zeitwerk (~> 2.6)
|
156
182
|
rainbow (3.1.1)
|
157
183
|
rake (13.0.6)
|
184
|
+
rdoc (6.6.2)
|
185
|
+
psych (>= 4.0.0)
|
158
186
|
regexp_parser (2.5.0)
|
187
|
+
reline (0.4.3)
|
188
|
+
io-console (~> 0.5)
|
159
189
|
rexml (3.2.5)
|
160
|
-
rspec-core (3.
|
161
|
-
rspec-support (~> 3.
|
162
|
-
rspec-expectations (3.
|
190
|
+
rspec-core (3.12.0)
|
191
|
+
rspec-support (~> 3.12.0)
|
192
|
+
rspec-expectations (3.12.2)
|
163
193
|
diff-lcs (>= 1.2.0, < 2.0)
|
164
|
-
rspec-support (~> 3.
|
165
|
-
rspec-mocks (3.
|
194
|
+
rspec-support (~> 3.12.0)
|
195
|
+
rspec-mocks (3.12.3)
|
166
196
|
diff-lcs (>= 1.2.0, < 2.0)
|
167
|
-
rspec-support (~> 3.
|
168
|
-
rspec-rails (
|
169
|
-
actionpack (>=
|
170
|
-
activesupport (>=
|
171
|
-
railties (>=
|
172
|
-
rspec-core (~> 3.
|
173
|
-
rspec-expectations (~> 3.
|
174
|
-
rspec-mocks (~> 3.
|
175
|
-
rspec-support (~> 3.
|
176
|
-
rspec-support (3.
|
197
|
+
rspec-support (~> 3.12.0)
|
198
|
+
rspec-rails (6.0.1)
|
199
|
+
actionpack (>= 6.1)
|
200
|
+
activesupport (>= 6.1)
|
201
|
+
railties (>= 6.1)
|
202
|
+
rspec-core (~> 3.11)
|
203
|
+
rspec-expectations (~> 3.11)
|
204
|
+
rspec-mocks (~> 3.11)
|
205
|
+
rspec-support (~> 3.11)
|
206
|
+
rspec-support (3.12.0)
|
177
207
|
rubocop (1.29.1)
|
178
208
|
parallel (~> 1.10)
|
179
209
|
parser (>= 3.1.0.0)
|
@@ -193,16 +223,17 @@ GEM
|
|
193
223
|
standard (1.12.1)
|
194
224
|
rubocop (= 1.29.1)
|
195
225
|
rubocop-performance (= 1.13.3)
|
196
|
-
|
197
|
-
thor (1.2.
|
198
|
-
timeout (0.
|
199
|
-
tzinfo (2.0.
|
226
|
+
stringio (3.1.0)
|
227
|
+
thor (1.2.2)
|
228
|
+
timeout (0.4.1)
|
229
|
+
tzinfo (2.0.6)
|
200
230
|
concurrent-ruby (~> 1.0)
|
201
231
|
unicode-display_width (2.2.0)
|
232
|
+
webrick (1.8.1)
|
202
233
|
websocket-driver (0.7.5)
|
203
234
|
websocket-extensions (>= 0.1.0)
|
204
235
|
websocket-extensions (0.1.5)
|
205
|
-
zeitwerk (2.6.
|
236
|
+
zeitwerk (2.6.8)
|
206
237
|
|
207
238
|
PLATFORMS
|
208
239
|
ruby
|
@@ -218,4 +249,4 @@ DEPENDENCIES
|
|
218
249
|
standard
|
219
250
|
|
220
251
|
BUNDLED WITH
|
221
|
-
2.
|
252
|
+
2.5.6
|
data/README.md
CHANGED
@@ -13,7 +13,7 @@ A library for Rails developers who are not willing to leave data migrations to c
|
|
13
13
|
- [Running Data Migrations](#running-data-migrations)
|
14
14
|
- [Display Status of Data Migrations](#display-status-of-data-migrations)
|
15
15
|
- [Reverting Data Migrations](#reverting-data-migrations)
|
16
|
-
- [
|
16
|
+
- [Tasks in Data Migrations](#tasks-in-data-migrations)
|
17
17
|
- [Testing](#testing)
|
18
18
|
- [RSpec](#rspec)
|
19
19
|
- [TestUnit](#testunit)
|
@@ -144,7 +144,7 @@ rails data:migrate:status
|
|
144
144
|
Rollback functionality is not provided by design. Create another data migration instead.
|
145
145
|
|
146
146
|
|
147
|
-
###
|
147
|
+
### Tasks in Data Migrations
|
148
148
|
|
149
149
|
After the data manipulation is complete, you may want to trigger a long running task.
|
150
150
|
Yet, there are [some pitfalls](#long-running-tasks-in-migrations) to be aware of.
|
@@ -309,10 +309,16 @@ Here a regular Rails migration:
|
|
309
309
|
|
310
310
|
```ruby
|
311
311
|
# db/migrate/20220605083010_backfill_users_name.rb
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
312
|
+
class BackfillUsersName < ActiveRecord::Migration[7.0]
|
313
|
+
def up
|
314
|
+
User.all.each do |user|
|
315
|
+
user.name = "#{user.first_name} #{user.last_name}"
|
316
|
+
user.save
|
317
|
+
end
|
318
|
+
end
|
319
|
+
|
320
|
+
def down
|
321
|
+
# ...
|
316
322
|
end
|
317
323
|
end
|
318
324
|
```
|
@@ -328,9 +334,15 @@ To avoid issues 1-3, we can rewrite the migration to:
|
|
328
334
|
|
329
335
|
```ruby
|
330
336
|
# db/migrate/20220605083010_backfill_users_name.rb
|
331
|
-
|
332
|
-
|
333
|
-
|
337
|
+
class BackfillUsersName < ActiveRecord::Migration[7.0]
|
338
|
+
def up
|
339
|
+
User.where(name: nil).find_each do |user|
|
340
|
+
user.update_column(:name, "#{user.first_name} #{user.last_name}")
|
341
|
+
end
|
342
|
+
end
|
343
|
+
|
344
|
+
def down
|
345
|
+
# ...
|
334
346
|
end
|
335
347
|
end
|
336
348
|
```
|
@@ -354,7 +366,7 @@ You could run such tasks asynchronously (i.e. in a background job) but the task
|
|
354
366
|
before the transaction commits. This is a [known issue][sync-issue]. In addition,
|
355
367
|
a database under load can suffer from longer commit times.
|
356
368
|
|
357
|
-
See [
|
369
|
+
See [Tasks in Data Migrations](#tasks-in-data-migrations).
|
358
370
|
|
359
371
|
|
360
372
|
|
@@ -385,6 +397,7 @@ Genetically speaking, this is an incredible data migration!
|
|
385
397
|
Articles
|
386
398
|
|
387
399
|
- [Data Migrations in Rails](https://thoughtbot.com/blog/data-migrations-in-rails)
|
400
|
+
- [Decoupling database migrations from server startup: why and how](https://pythonspeed.com/articles/schema-migrations-server-startup/)
|
388
401
|
- [Zero downtime migrations: 500 million rows](https://www.honeybadger.io/blog/zero-downtime-migrations-of-large-databases-using-rails-postgres-and-redis/)
|
389
402
|
- [Three Useful Data Migration Patterns for Rails](https://www.ombulabs.com/blog/rails/data-migrations/three-useful-data-migrations-patterns-in-rails.html)
|
390
403
|
- [Ruby on Rails Model Patterns and Anti-patterns](https://blog.appsignal.com/2020/11/18/rails-model-patterns-and-anti-patterns.html)
|
data/bin/console
ADDED
@@ -1,16 +1,14 @@
|
|
1
1
|
require "rails/generators"
|
2
|
-
require "rails/generators/active_record"
|
2
|
+
require "rails/generators/active_record/migration"
|
3
3
|
|
4
4
|
module MonarchMigrate
|
5
5
|
module Generators
|
6
6
|
class InstallGenerator < Rails::Generators::Base
|
7
|
-
include
|
7
|
+
include ActiveRecord::Generators::Migration
|
8
8
|
|
9
|
-
|
9
|
+
class_option :database, type: :string, aliases: %i[--db], desc: "The database for your migration. By default, the current environment's primary database is used."
|
10
10
|
|
11
|
-
|
12
|
-
ActiveRecord::Generators::Base.next_migration_number(dir)
|
13
|
-
end
|
11
|
+
source_root File.expand_path("templates", __dir__)
|
14
12
|
|
15
13
|
def create_monarch_migrate_migration
|
16
14
|
return if migration_exists?
|
@@ -18,17 +16,19 @@ module MonarchMigrate
|
|
18
16
|
|
19
17
|
migration_template(
|
20
18
|
"create_data_migration_records.rb.erb",
|
21
|
-
"
|
19
|
+
"#{db_migrate_path}/create_data_migration_records.rb",
|
22
20
|
migration_version: migration_version
|
23
21
|
)
|
24
22
|
end
|
25
23
|
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
no_commands do
|
25
|
+
def migration_version
|
26
|
+
"[#{ActiveRecord::Migration.current_version}]"
|
27
|
+
end
|
29
28
|
|
30
|
-
|
31
|
-
|
29
|
+
def migration_table_name
|
30
|
+
MigrationRecord.table_name
|
31
|
+
end
|
32
32
|
end
|
33
33
|
|
34
34
|
private
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require "rails/generators"
|
2
|
+
require "rails/generators/migration"
|
1
3
|
require "rails/generators/active_record"
|
2
4
|
|
3
5
|
module Rails
|
@@ -5,14 +7,20 @@ module Rails
|
|
5
7
|
class DataMigrationGenerator < Rails::Generators::NamedBase
|
6
8
|
include ActiveRecord::Generators::Migration
|
7
9
|
|
8
|
-
source_root File.expand_path("
|
10
|
+
source_root File.expand_path("templates", __dir__)
|
11
|
+
|
12
|
+
def self.next_migration_number(_)
|
13
|
+
ActiveRecord::Generators::Base.next_migration_number(
|
14
|
+
MonarchMigrate.data_migrations_path
|
15
|
+
)
|
16
|
+
end
|
9
17
|
|
10
18
|
def create_data_migration
|
11
19
|
validate_file_name!
|
12
20
|
|
13
21
|
migration_template(
|
14
22
|
"data_migration.rb.erb",
|
15
|
-
File.join(MonarchMigrate.
|
23
|
+
File.join(MonarchMigrate.migrator.path, "#{file_name}.rb")
|
16
24
|
)
|
17
25
|
end
|
18
26
|
|
@@ -1,36 +1,38 @@
|
|
1
|
+
require "rails/generators"
|
2
|
+
require "monarch_migrate/migration"
|
3
|
+
|
1
4
|
module Rspec
|
2
5
|
module Generators
|
3
|
-
class DataMigrationGenerator <
|
6
|
+
class DataMigrationGenerator < Rails::Generators::NamedBase
|
7
|
+
include MonarchMigrate::Migration::Lookup
|
8
|
+
|
4
9
|
source_root File.expand_path("templates", __dir__)
|
5
10
|
|
6
11
|
def create_data_migration_test
|
7
|
-
|
8
|
-
|
9
|
-
return
|
12
|
+
if spec_file_name
|
13
|
+
template("data_migration_spec.rb.erb", File.join(destination_dir, spec_file_name))
|
10
14
|
end
|
11
|
-
|
12
|
-
template(
|
13
|
-
"data_migration_spec.rb.erb",
|
14
|
-
File.join("spec/data_migrations", "#{described_class}_spec.rb")
|
15
|
-
)
|
16
15
|
end
|
17
16
|
|
18
17
|
private
|
19
18
|
|
20
19
|
def described_class
|
21
|
-
File.basename(
|
20
|
+
File.basename(spec_file_name, ".*")
|
22
21
|
end
|
23
22
|
|
24
|
-
def
|
25
|
-
|
23
|
+
def destination_dir
|
24
|
+
File.join(destination_root, "spec/data_migrations")
|
26
25
|
end
|
27
26
|
|
28
|
-
def
|
29
|
-
@
|
30
|
-
|
31
|
-
.
|
32
|
-
.
|
33
|
-
|
27
|
+
def spec_file_name
|
28
|
+
@spec_file_name ||=
|
29
|
+
if behavior == :invoke
|
30
|
+
name = migration_exists?(MonarchMigrate.migrator.path, file_name)
|
31
|
+
File.basename(name, ".*") << "_spec.rb" if name
|
32
|
+
else
|
33
|
+
name = migration_exists?(destination_dir, "#{file_name}_spec")
|
34
|
+
File.basename(name) if name
|
35
|
+
end
|
34
36
|
end
|
35
37
|
end
|
36
38
|
end
|
@@ -1,33 +1,36 @@
|
|
1
|
+
require "rails/generators"
|
2
|
+
require "monarch_migrate/migration"
|
3
|
+
|
1
4
|
module TestUnit
|
2
5
|
module Generators
|
3
|
-
class DataMigrationGenerator <
|
6
|
+
class DataMigrationGenerator < Rails::Generators::NamedBase
|
7
|
+
include MonarchMigrate::Migration::Lookup
|
8
|
+
|
4
9
|
source_root File.expand_path("templates", __dir__)
|
5
10
|
|
6
11
|
check_class_collision suffix: "Test"
|
7
12
|
|
8
|
-
def
|
9
|
-
|
10
|
-
|
11
|
-
return
|
13
|
+
def create_data_migration_test_file
|
14
|
+
if test_file_name
|
15
|
+
template "unit_test.rb.erb", File.join(destination_dir, test_file_name)
|
12
16
|
end
|
13
|
-
|
14
|
-
prefix = File.basename(data_migration.filename, ".rb")
|
15
|
-
|
16
|
-
template "unit_test.rb.erb", File.join("test/data_migrations", "#{prefix}_test.rb")
|
17
17
|
end
|
18
18
|
|
19
19
|
private
|
20
20
|
|
21
|
-
def
|
22
|
-
|
21
|
+
def test_file_name
|
22
|
+
@test_file_name ||=
|
23
|
+
if behavior == :invoke
|
24
|
+
name = migration_exists?(MonarchMigrate.migrator.path, file_name)
|
25
|
+
File.basename(name, ".*") << "_test.rb" if name
|
26
|
+
else
|
27
|
+
name = migration_exists?(destination_dir, "#{file_name}_test")
|
28
|
+
File.basename(name) if name
|
29
|
+
end
|
23
30
|
end
|
24
31
|
|
25
|
-
def
|
26
|
-
|
27
|
-
MonarchMigrate.migrator
|
28
|
-
.migrations
|
29
|
-
.reverse
|
30
|
-
.find { |m| m.filename.ends_with?(data_migration_pattern) }
|
32
|
+
def destination_dir
|
33
|
+
File.join(destination_root, "test/data_migrations")
|
31
34
|
end
|
32
35
|
end
|
33
36
|
end
|
@@ -2,6 +2,16 @@
|
|
2
2
|
|
3
3
|
module MonarchMigrate
|
4
4
|
class Migration
|
5
|
+
module Lookup
|
6
|
+
def migration_lookup_at(dirname)
|
7
|
+
Dir.glob("#{dirname}/[0-9]*_*.rb")
|
8
|
+
end
|
9
|
+
|
10
|
+
def migration_exists?(dirname, file_name)
|
11
|
+
migration_lookup_at(dirname).grep(/\d+_#{file_name}.rb$/).first
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
5
15
|
def initialize(path)
|
6
16
|
@path = path.to_s
|
7
17
|
@after_commit_callback = nil
|
@@ -12,7 +22,7 @@ module MonarchMigrate
|
|
12
22
|
end
|
13
23
|
|
14
24
|
def name
|
15
|
-
File.basename(path, ".rb").
|
25
|
+
File.basename(path, ".rb").delete_prefix("#{version}_").humanize
|
16
26
|
end
|
17
27
|
|
18
28
|
def version
|
data/lib/monarch_migrate.rb
CHANGED
data/monarch_migrate.gemspec
CHANGED
@@ -6,10 +6,10 @@ Gem::Specification.new do |spec|
|
|
6
6
|
spec.authors = ["Yanko Ivanov"]
|
7
7
|
spec.email = ["yanko.ivanov@gmail.com"]
|
8
8
|
|
9
|
-
spec.summary = "
|
9
|
+
spec.summary = "A library for Rails developers who are not willing to leave data migrations to chance."
|
10
10
|
spec.homepage = "https://github.com/lunohodov/monarch"
|
11
11
|
spec.license = "MIT"
|
12
|
-
spec.required_ruby_version = Gem::Requirement.new(">=
|
12
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 3.0")
|
13
13
|
|
14
14
|
spec.metadata["homepage_uri"] = spec.homepage
|
15
15
|
spec.metadata["source_code_uri"] = "https://github.com/lunohodov/monarch"
|
@@ -20,5 +20,5 @@ Gem::Specification.new do |spec|
|
|
20
20
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|gemfiles|tmp)/}) }
|
21
21
|
end
|
22
22
|
|
23
|
-
spec.add_dependency("rails", ">=
|
23
|
+
spec.add_dependency("rails", ">= 6.0")
|
24
24
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: monarch_migrate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yanko Ivanov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-03-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: '6.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: '6.0'
|
27
27
|
description:
|
28
28
|
email:
|
29
29
|
- yanko.ivanov@gmail.com
|
@@ -40,6 +40,7 @@ files:
|
|
40
40
|
- LICENSE
|
41
41
|
- README.md
|
42
42
|
- Rakefile
|
43
|
+
- bin/console
|
43
44
|
- bin/setup
|
44
45
|
- db/schema.rb
|
45
46
|
- lib/generators/monarch_migrate/install/USAGE
|
@@ -79,15 +80,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
79
80
|
requirements:
|
80
81
|
- - ">="
|
81
82
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
83
|
+
version: '3.0'
|
83
84
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
85
|
requirements:
|
85
86
|
- - ">="
|
86
87
|
- !ruby/object:Gem::Version
|
87
88
|
version: '0'
|
88
89
|
requirements: []
|
89
|
-
rubygems_version: 3.
|
90
|
+
rubygems_version: 3.5.3
|
90
91
|
signing_key:
|
91
92
|
specification_version: 4
|
92
|
-
summary:
|
93
|
+
summary: A library for Rails developers who are not willing to leave data migrations
|
94
|
+
to chance.
|
93
95
|
test_files: []
|