data-migration 1.3.0 → 2.0.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.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +8 -0
  3. data/README.md +27 -3
  4. data/data-migration.gemspec +27 -15
  5. data/lib/data-migration.rb +1 -1
  6. data/lib/data_migration/config.rb +1 -1
  7. data/lib/data_migration/job.rb +27 -9
  8. data/lib/data_migration/task.rb +22 -19
  9. metadata +185 -65
  10. data/.editorconfig +0 -14
  11. data/.github/dependabot.yml +0 -27
  12. data/.github/workflows/_trunk_check.yml +0 -15
  13. data/.github/workflows/test.yml +0 -42
  14. data/.gitignore +0 -24
  15. data/.ruby-version +0 -1
  16. data/.trunk/.gitignore +0 -9
  17. data/.trunk/configs/.markdownlint.yaml +0 -2
  18. data/.trunk/configs/.shellcheckrc +0 -7
  19. data/.trunk/configs/.yamllint.yaml +0 -7
  20. data/.trunk/trunk.yaml +0 -39
  21. data/.vscode/extensions.json +0 -18
  22. data/.vscode/settings.json +0 -7
  23. data/Gemfile +0 -3
  24. data/Gemfile.lock +0 -246
  25. data/spec/data_migration/config_spec.rb +0 -116
  26. data/spec/data_migration/job_spec.rb +0 -96
  27. data/spec/data_migration/task_spec.rb +0 -152
  28. data/spec/data_migration_spec.rb +0 -65
  29. data/spec/fixtures/data_migrations/20241206200111_create_users.rb +0 -17
  30. data/spec/fixtures/data_migrations/20241206200112_create_bad_users.rb +0 -5
  31. data/spec/fixtures/data_migrations/20241206200113_change_users.rb +0 -5
  32. data/spec/fixtures/data_migrations/20241206200114_create_batch_users.rb +0 -9
  33. data/spec/fixtures/schema.rb +0 -26
  34. data/spec/generators/install_generator_spec.rb +0 -48
  35. data/spec/generators/migration_generator_spec.rb +0 -50
  36. data/spec/rails_helper.rb +0 -21
  37. data/spec/spec_helper.rb +0 -30
  38. data/spec/support/junit_formatter.rb +0 -6
  39. data/spec/support/rails_helpers.rb +0 -53
  40. data/usr/bin/release.sh +0 -35
data/.editorconfig DELETED
@@ -1,14 +0,0 @@
1
- # Editor configuration, see https://editorconfig.org
2
- root = true
3
-
4
- [*]
5
- charset = utf-8
6
- indent_style = space
7
- indent_size = 2
8
- insert_final_newline = true
9
- trim_trailing_whitespace = true
10
- quote_type = double
11
-
12
- [*.md]
13
- max_line_length = off
14
- trim_trailing_whitespace = false
@@ -1,27 +0,0 @@
1
- # To get started with Dependabot version updates, you'll need to specify which
2
- # package ecosystems to update and where the package manifests are located.
3
- # Please see the documentation for all configuration options:
4
- # https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5
-
6
- version: 2
7
- updates:
8
- - package-ecosystem: github-actions
9
- directory: /
10
- open-pull-requests-limit: 10
11
- schedule:
12
- interval: weekly
13
- - package-ecosystem: bundler
14
- directory: /
15
- open-pull-requests-limit: 10
16
- schedule:
17
- interval: weekly
18
- - package-ecosystem: npm
19
- directory: /
20
- open-pull-requests-limit: 10
21
- schedule:
22
- interval: weekly
23
- - package-ecosystem: docker
24
- directory: /
25
- open-pull-requests-limit: 10
26
- schedule:
27
- interval: weekly
@@ -1,15 +0,0 @@
1
- name: _trunk_check
2
- on: [pull_request]
3
- concurrency:
4
- group: ${{ github.head_ref || github.run_id }}
5
- cancel-in-progress: true
6
- permissions: read-all
7
- jobs:
8
- run_trunk_action:
9
- runs-on: ubuntu-latest
10
- permissions:
11
- checks: write
12
- contents: read
13
- steps:
14
- - uses: actions/checkout@v4
15
- - uses: trunk-io/trunk-action@v1
@@ -1,42 +0,0 @@
1
- name: test
2
- permissions: read-all
3
- on: [push, pull_request]
4
- concurrency:
5
- group: ${{ github.workflow }}-${{ github.ref_name }}
6
- cancel-in-progress: false
7
- jobs:
8
- rspec:
9
- runs-on: ubuntu-latest
10
- strategy:
11
- matrix:
12
- ruby: [ruby, jruby, truffleruby]
13
- steps:
14
- - uses: actions/checkout@v4
15
- - uses: ruby/setup-ruby@v1
16
- with:
17
- ruby-version: ${{ matrix.ruby }}
18
- bundler-cache: true
19
- - run: bundle exec rspec
20
- coverage:
21
- runs-on: ubuntu-latest
22
- steps:
23
- - uses: actions/checkout@v4
24
- - uses: ruby/setup-ruby@v1
25
- with:
26
- bundler-cache: true
27
- - run: bundle exec rspec
28
- - uses: codecov/codecov-action@v5
29
- continue-on-error: true
30
- env:
31
- CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
32
- - uses: codecov/test-results-action@v1
33
- if: ${{ !cancelled() }}
34
- continue-on-error: true
35
- with:
36
- token: ${{ secrets.CODECOV_TOKEN }}
37
- files: coverage/junit-coverage.xml
38
- - uses: codacy/codacy-coverage-reporter-action@v1.3.0
39
- continue-on-error: true
40
- with:
41
- project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
42
- coverage-reports: coverage/coverage.xml
data/.gitignore DELETED
@@ -1,24 +0,0 @@
1
- # See https://help.github.com/articles/ignoring-files for more about ignoring files.
2
- #
3
- # If you find yourself ignoring temporary files generated by your text editor
4
- # or operating system, you probably want to add a global ignore instead:
5
- # git config --global core.excludesfile '~/.gitignore_global'
6
-
7
- # Ignore bundler config.
8
- /.bundle
9
- /vendor/bundle
10
-
11
- .byebug_history
12
-
13
- /coverage
14
- /coverage/*
15
-
16
- /spec/examples.txt
17
- /tmp/*
18
-
19
- .DS_Store
20
- .idea
21
- .lh
22
-
23
- *.local
24
- *.gem
data/.ruby-version DELETED
@@ -1 +0,0 @@
1
- 3.3.4
data/.trunk/.gitignore DELETED
@@ -1,9 +0,0 @@
1
- *out
2
- *logs
3
- *actions
4
- *notifications
5
- *tools
6
- plugins
7
- user_trunk.yaml
8
- user.yaml
9
- tmp
@@ -1,2 +0,0 @@
1
- # Prettier friendly markdownlint config (all formatting rules disabled)
2
- extends: markdownlint/style/prettier
@@ -1,7 +0,0 @@
1
- enable=all
2
- source-path=SCRIPTDIR
3
- disable=SC2154
4
-
5
- # If you're having issues with shellcheck following source, disable the errors via:
6
- # disable=SC1090
7
- # disable=SC1091
@@ -1,7 +0,0 @@
1
- rules:
2
- quoted-strings:
3
- required: only-when-needed
4
- extra-allowed: ["{|}"]
5
- key-duplicates: {}
6
- octal-values:
7
- forbid-implicit-octal: true
data/.trunk/trunk.yaml DELETED
@@ -1,39 +0,0 @@
1
- # This file controls the behavior of Trunk: https://docs.trunk.io/cli
2
- # To learn more about the format of this file, see https://docs.trunk.io/reference/trunk-yaml
3
- version: 0.1
4
- cli:
5
- version: 1.22.8
6
- # Trunk provides extensibility via plugins. (https://docs.trunk.io/plugins)
7
- plugins:
8
- sources:
9
- - id: trunk
10
- ref: v1.6.5
11
- uri: https://github.com/trunk-io/plugins
12
- # Many linters and tools depend on runtimes - configure them here. (https://docs.trunk.io/runtimes)
13
- runtimes:
14
- enabled:
15
- - ruby@3.1.4
16
- - go@1.21.0
17
- - node@18.12.1
18
- - python@3.10.8
19
- # This is the section where you manage your linters. (https://docs.trunk.io/check/configuration)
20
- lint:
21
- enabled:
22
- - standardrb@1.3.0
23
- - actionlint@1.7.4
24
- - checkov@3.2.332
25
- - git-diff-check
26
- - markdownlint@0.43.0
27
- - osv-scanner@1.9.1
28
- - prettier@3.4.2
29
- - shellcheck@0.10.0
30
- - shfmt@3.6.0
31
- - trufflehog@3.85.0
32
- - yamllint@1.35.1
33
- actions:
34
- disabled:
35
- - trunk-announce
36
- - trunk-check-pre-push
37
- - trunk-fmt-pre-commit
38
- enabled:
39
- - trunk-upgrade-available
@@ -1,18 +0,0 @@
1
- {
2
- "recommendations": [
3
- "donjayamanne.githistory",
4
- "editorconfig.editorconfig",
5
- "mikestead.dotenv",
6
- "anweber.vscode-httpyac",
7
- "shopify.ruby-lsp",
8
- "bung87.vscode-gemfile",
9
- "wayou.vscode-todo-highlight",
10
- "vscode-icons-team.vscode-icons",
11
- "koichisasada.vscode-rdbg",
12
- "fooo.ruby-spec-runner",
13
- "nhoizey.gremlins",
14
- "streetsidesoftware.code-spell-checker",
15
- "dewski.simplecov",
16
- "trunk.io"
17
- ]
18
- }
@@ -1,7 +0,0 @@
1
- {
2
- "editor.defaultFormatter": "trunk.io",
3
- "editor.formatOnSave": false,
4
- "editor.detectIndentation": false,
5
- "editor.tabSize": 2,
6
- "editor.insertSpaces": true
7
- }
data/Gemfile DELETED
@@ -1,3 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gemspec
data/Gemfile.lock DELETED
@@ -1,246 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- data-migration (1.3.0)
5
- activejob (> 5)
6
- activerecord (> 5)
7
- activesupport (> 5)
8
- rails (> 5)
9
-
10
- GEM
11
- remote: https://rubygems.org/
12
- specs:
13
- actioncable (8.0.0)
14
- actionpack (= 8.0.0)
15
- activesupport (= 8.0.0)
16
- nio4r (~> 2.0)
17
- websocket-driver (>= 0.6.1)
18
- zeitwerk (~> 2.6)
19
- actionmailbox (8.0.0)
20
- actionpack (= 8.0.0)
21
- activejob (= 8.0.0)
22
- activerecord (= 8.0.0)
23
- activestorage (= 8.0.0)
24
- activesupport (= 8.0.0)
25
- mail (>= 2.8.0)
26
- actionmailer (8.0.0)
27
- actionpack (= 8.0.0)
28
- actionview (= 8.0.0)
29
- activejob (= 8.0.0)
30
- activesupport (= 8.0.0)
31
- mail (>= 2.8.0)
32
- rails-dom-testing (~> 2.2)
33
- actionpack (8.0.0)
34
- actionview (= 8.0.0)
35
- activesupport (= 8.0.0)
36
- nokogiri (>= 1.8.5)
37
- rack (>= 2.2.4)
38
- rack-session (>= 1.0.1)
39
- rack-test (>= 0.6.3)
40
- rails-dom-testing (~> 2.2)
41
- rails-html-sanitizer (~> 1.6)
42
- useragent (~> 0.16)
43
- actiontext (8.0.0)
44
- actionpack (= 8.0.0)
45
- activerecord (= 8.0.0)
46
- activestorage (= 8.0.0)
47
- activesupport (= 8.0.0)
48
- globalid (>= 0.6.0)
49
- nokogiri (>= 1.8.5)
50
- actionview (8.0.0)
51
- activesupport (= 8.0.0)
52
- builder (~> 3.1)
53
- erubi (~> 1.11)
54
- rails-dom-testing (~> 2.2)
55
- rails-html-sanitizer (~> 1.6)
56
- activejob (8.0.0)
57
- activesupport (= 8.0.0)
58
- globalid (>= 0.3.6)
59
- activemodel (8.0.0)
60
- activesupport (= 8.0.0)
61
- activerecord (8.0.0)
62
- activemodel (= 8.0.0)
63
- activesupport (= 8.0.0)
64
- timeout (>= 0.4.0)
65
- activestorage (8.0.0)
66
- actionpack (= 8.0.0)
67
- activejob (= 8.0.0)
68
- activerecord (= 8.0.0)
69
- activesupport (= 8.0.0)
70
- marcel (~> 1.0)
71
- activesupport (8.0.0)
72
- base64
73
- benchmark (>= 0.3)
74
- bigdecimal
75
- concurrent-ruby (~> 1.0, >= 1.3.1)
76
- connection_pool (>= 2.2.5)
77
- drb
78
- i18n (>= 1.6, < 2)
79
- logger (>= 1.4.2)
80
- minitest (>= 5.1)
81
- securerandom (>= 0.3)
82
- tzinfo (~> 2.0, >= 2.0.5)
83
- uri (>= 0.13.1)
84
- base64 (0.2.0)
85
- benchmark (0.4.0)
86
- bigdecimal (3.1.8)
87
- bigdecimal (3.1.8-java)
88
- builder (3.3.0)
89
- concurrent-ruby (1.3.4)
90
- connection_pool (2.4.1)
91
- crass (1.0.6)
92
- date (3.4.1)
93
- date (3.4.1-java)
94
- diff-lcs (1.5.1)
95
- docile (1.4.1)
96
- drb (2.2.1)
97
- erubi (1.13.0)
98
- globalid (1.2.1)
99
- activesupport (>= 6.1)
100
- i18n (1.14.6)
101
- concurrent-ruby (~> 1.0)
102
- io-console (0.8.0)
103
- io-console (0.8.0-java)
104
- irb (1.14.1)
105
- rdoc (>= 4.0.0)
106
- reline (>= 0.4.2)
107
- jar-dependencies (0.5.0)
108
- logger (1.6.2)
109
- loofah (2.23.1)
110
- crass (~> 1.0.2)
111
- nokogiri (>= 1.12.0)
112
- mail (2.8.1)
113
- mini_mime (>= 0.1.1)
114
- net-imap
115
- net-pop
116
- net-smtp
117
- marcel (1.0.4)
118
- mini_mime (1.1.5)
119
- mini_portile2 (2.8.8)
120
- minitest (5.25.4)
121
- net-imap (0.5.1)
122
- date
123
- net-protocol
124
- net-pop (0.1.2)
125
- net-protocol
126
- net-protocol (0.2.2)
127
- timeout
128
- net-smtp (0.5.0)
129
- net-protocol
130
- nio4r (2.7.4)
131
- nio4r (2.7.4-java)
132
- nokogiri (1.16.8-arm64-darwin)
133
- racc (~> 1.4)
134
- nokogiri (1.16.8-java)
135
- racc (~> 1.4)
136
- nokogiri (1.16.8-x86_64-linux)
137
- racc (~> 1.4)
138
- psych (5.2.1)
139
- date
140
- stringio
141
- psych (5.2.1-java)
142
- date
143
- jar-dependencies (>= 0.1.7)
144
- racc (1.8.1)
145
- racc (1.8.1-java)
146
- rack (3.1.8)
147
- rack-session (2.0.0)
148
- rack (>= 3.0.0)
149
- rack-test (2.1.0)
150
- rack (>= 1.3)
151
- rackup (2.2.1)
152
- rack (>= 3)
153
- rails (8.0.0)
154
- actioncable (= 8.0.0)
155
- actionmailbox (= 8.0.0)
156
- actionmailer (= 8.0.0)
157
- actionpack (= 8.0.0)
158
- actiontext (= 8.0.0)
159
- actionview (= 8.0.0)
160
- activejob (= 8.0.0)
161
- activemodel (= 8.0.0)
162
- activerecord (= 8.0.0)
163
- activestorage (= 8.0.0)
164
- activesupport (= 8.0.0)
165
- bundler (>= 1.15.0)
166
- railties (= 8.0.0)
167
- rails-dom-testing (2.2.0)
168
- activesupport (>= 5.0.0)
169
- minitest
170
- nokogiri (>= 1.6)
171
- rails-html-sanitizer (1.6.1)
172
- loofah (~> 2.21)
173
- nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
174
- railties (8.0.0)
175
- actionpack (= 8.0.0)
176
- activesupport (= 8.0.0)
177
- irb (~> 1.13)
178
- rackup (>= 1.0.0)
179
- rake (>= 12.2)
180
- thor (~> 1.0, >= 1.2.2)
181
- zeitwerk (~> 2.6)
182
- rake (13.2.1)
183
- rdoc (6.8.1)
184
- psych (>= 4.0.0)
185
- reline (0.5.12)
186
- io-console (~> 0.5)
187
- rexml (3.3.9)
188
- rspec (3.13.0)
189
- rspec-core (~> 3.13.0)
190
- rspec-expectations (~> 3.13.0)
191
- rspec-mocks (~> 3.13.0)
192
- rspec-core (3.13.2)
193
- rspec-support (~> 3.13.0)
194
- rspec-expectations (3.13.3)
195
- diff-lcs (>= 1.2.0, < 2.0)
196
- rspec-support (~> 3.13.0)
197
- rspec-mocks (3.13.2)
198
- diff-lcs (>= 1.2.0, < 2.0)
199
- rspec-support (~> 3.13.0)
200
- rspec-support (3.13.2)
201
- rspec_junit_formatter (0.6.0)
202
- rspec-core (>= 2, < 4, != 2.12.0)
203
- securerandom (0.4.0)
204
- simplecov (0.22.0)
205
- docile (~> 1.1)
206
- simplecov-html (~> 0.11)
207
- simplecov_json_formatter (~> 0.1)
208
- simplecov-cobertura (2.1.0)
209
- rexml
210
- simplecov (~> 0.19)
211
- simplecov-html (0.13.1)
212
- simplecov_json_formatter (0.1.4)
213
- sqlite3 (2.4.0)
214
- mini_portile2 (~> 2.8.0)
215
- sqlite3 (2.4.0-arm64-darwin)
216
- sqlite3 (2.4.0-x86_64-linux-gnu)
217
- stringio (3.1.2)
218
- thor (1.3.2)
219
- timeout (0.4.2)
220
- tzinfo (2.0.6)
221
- concurrent-ruby (~> 1.0)
222
- uri (1.0.2)
223
- useragent (0.16.11)
224
- websocket-driver (0.7.6)
225
- websocket-extensions (>= 0.1.0)
226
- websocket-driver (0.7.6-java)
227
- websocket-extensions (>= 0.1.0)
228
- websocket-extensions (0.1.5)
229
- zeitwerk (2.7.1)
230
-
231
- PLATFORMS
232
- arm64-darwin
233
- universal-java-11
234
- x86_64-linux
235
-
236
- DEPENDENCIES
237
- bundler (~> 2)
238
- data-migration!
239
- rspec (~> 3)
240
- rspec_junit_formatter (~> 0.6)
241
- simplecov (~> 0.21)
242
- simplecov-cobertura (~> 2)
243
- sqlite3 (~> 2.4)
244
-
245
- BUNDLED WITH
246
- 2.5.20
@@ -1,116 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe DataMigration::Config do
4
- subject(:config) { described_class.new }
5
-
6
- let(:current_user) do
7
- User.new(id: 1)
8
- end
9
- let(:action_reporter) do
10
- Class.new do
11
- def current_user
12
- User.new(id: 3)
13
- end
14
-
15
- def context(**kwargs)
16
- kwargs
17
- end
18
- end.new
19
- end
20
- let(:audited) do
21
- Class.new do
22
- def store
23
- { audited_user: User.new(id: 4) }
24
- end
25
- end.new
26
- end
27
- let(:logger) do
28
- Class.new do
29
- def info(message)
30
- puts message
31
- end
32
- end.new
33
- end
34
- let(:other_user) do
35
- User.new(id: 2)
36
- end
37
- let(:migration) do
38
- DataMigration::Task.new(id: 1, name: "test", operator: other_user)
39
- end
40
-
41
- before do
42
- allow(Rails).to receive(:root).and_return(rails_root)
43
- allow(Rails).to receive(:logger).and_return(logger)
44
- end
45
-
46
- it "has default schema migrations path" do
47
- expect(config.schema_migrations_path).to eq "db/migrate"
48
- end
49
-
50
- it "has default data migrations path" do
51
- expect(config.data_migrations_path).to eq "db/data_migrations"
52
- end
53
-
54
- it "has default data migrations full path" do
55
- expect(config.data_migrations_full_path).to eq Rails.root.join("db/data_migrations")
56
- end
57
-
58
- it "has default data migrations path glob" do
59
- expect(config.data_migrations_path_glob).to eq Rails.root.join("db/data_migrations/*.rb").to_s
60
- end
61
-
62
- it "has default generate spec" do
63
- expect(config.generate_spec?).to be true
64
- end
65
-
66
- it "has default task class" do
67
- expect(config.task_class).to eq DataMigration::Task
68
- end
69
-
70
- it "has default job class" do
71
- expect(config.job_class).to eq DataMigration::Job
72
- end
73
-
74
- it "has default job queue name" do
75
- expect(config.job_queue_name).to eq :default
76
- end
77
-
78
- it "has default default jobs limit" do
79
- expect(config.default_jobs_limit).to eq 10
80
- end
81
-
82
- it "has default monitoring context" do
83
- expect(config.monitoring_context).to be_a Proc
84
-
85
- expect(Rails.logger).to receive(:info).with("Data migration context: {:data_migration_name=>\"test\", :data_migration_id=>1, :data_migration_operator_id=>2}")
86
- expect { config.monitoring_context.call(migration) }.not_to raise_error
87
- end
88
-
89
- context "when ActionReporter is defined" do
90
- before do
91
- stub_const("ActionReporter", action_reporter)
92
- end
93
-
94
- it "sets monitoring context" do
95
- expect(ActionReporter).to receive(:context).with(
96
- data_migration_name: "test",
97
- data_migration_id: 1,
98
- data_migration_operator_id: 2
99
- )
100
- expect(ActionReporter).to receive(:current_user).and_return(nil)
101
- expect(ActionReporter).to receive(:current_user=).with(other_user)
102
- expect { config.monitoring_context.call(migration) }.not_to raise_error
103
- end
104
- end
105
-
106
- context "when Audited is defined" do
107
- before do
108
- stub_const("Audited", audited)
109
- end
110
-
111
- it "sets monitoring context" do
112
- expect(Audited).to receive(:store).and_return(audited_user: User.new(id: 5))
113
- expect { config.monitoring_context.call(migration) }.not_to raise_error
114
- end
115
- end
116
- end
@@ -1,96 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe DataMigration::Job do
4
- subject(:job) { DataMigration::Job.new }
5
-
6
- let(:operator) { User.create!(email: "test@example.com") }
7
- let(:task) { DataMigration::Task.create!(name: migration_name, operator: operator) }
8
-
9
- let(:migration_name) { "20241206200111_create_users" }
10
- let(:data_migrations_full_path) { File.expand_path("../fixtures/data_migrations", __dir__) }
11
-
12
- before do
13
- allow(Rails).to receive(:env).and_return(rails_env)
14
- allow(Rails).to receive(:logger).and_return(rails_logger)
15
- allow(DataMigration.config).to receive(:data_migrations_full_path).and_return(data_migrations_full_path)
16
- end
17
-
18
- it "runs rspec spec/fixtures/data_migrations/20241206200111_create_users.rb" do
19
- output = `RUN_MIGRATION_TESTS=1 rspec #{data_migrations_full_path}/#{migration_name}.rb`
20
- expect(output).to include("1 example, 0 failures")
21
- end
22
-
23
- describe "#perform" do
24
- subject(:perform) { job.perform(task.id, **job_kwargs) }
25
-
26
- let(:job_kwargs) { {} }
27
-
28
- it "updates the task status to completed" do
29
- expect { perform }.to change { task.reload.status }.to("completed")
30
- end
31
-
32
- context "when migration file is not found" do
33
- before do
34
- task
35
- allow_any_instance_of(DataMigration::Task).to receive(:file_exists?).and_return(false)
36
- end
37
-
38
- it "updates the task status to failed" do
39
- expect(DataMigration).to receive(:notify).with("#{migration_name} not found")
40
- expect { perform }.not_to raise_error
41
- end
42
- end
43
-
44
- context "when migration class is not found" do
45
- let(:migration_name) { "20241206200112_create_bad_users" }
46
-
47
- it "raises an error" do
48
- expect { perform }.to raise_error("Data migration class #{migration_name.gsub(/^[0-9_]+/, "").camelize} not found")
49
- end
50
- end
51
-
52
- context "when migration class does not implement perform method" do
53
- let(:migration_name) { "20241206200113_change_users" }
54
-
55
- it "raises an error" do
56
- expect { perform }.to raise_error("Data migration class #{migration_name.gsub(/^[0-9_]+/, "").camelize} must implement `perform` method")
57
- end
58
- end
59
-
60
- context "when there is an enqueue call" do
61
- let(:migration_name) { "20241206200114_create_batch_users" }
62
-
63
- it "runs the migration in foreground" do
64
- expect { perform }.to change { User.count }.by(3)
65
- expect(task.reload.current_jobs.count).to eq(0)
66
- expect(task.status).to eq("completed")
67
- expect(User.pluck(:email)).to match_array(["test@example.com", "test_1@example.com", "test_2@example.com"])
68
- end
69
-
70
- context "when background is true" do
71
- let(:job_kwargs) { { background: true } }
72
-
73
- before do
74
- operator
75
- end
76
-
77
- it "runs the migration in background" do
78
- expect { perform }.to change(User, :count).by(1)
79
- expect(task.reload.status).to eq("performing")
80
- expect(task.current_jobs.count).to eq(0)
81
- expect(task.kwargs).to eq({})
82
-
83
- expect { job.perform(task.id, index: 2, background: true) }.to change(User, :count).by(1)
84
- expect(task.reload.status).to eq("performing")
85
- expect(task.reload.current_jobs.count).to eq(0)
86
- expect(task.kwargs).to eq({})
87
-
88
- expect { job.perform(task.id, index: 3, background: true) }.to change(User, :count).by(0)
89
- expect(task.reload.status).to eq("completed")
90
- expect(task.reload.current_jobs.count).to eq(0)
91
- expect(task.kwargs).to eq({})
92
- end
93
- end
94
- end
95
- end
96
- end