data_migrate 3.2.0 → 11.3.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 (46) hide show
  1. checksums.yaml +5 -5
  2. data/Changelog.md +246 -2
  3. data/README.md +107 -91
  4. data/lib/capistrano/data_migrate/migrate.rb +3 -4
  5. data/lib/data_migrate/config.rb +33 -0
  6. data/lib/data_migrate/data_migrator.rb +54 -58
  7. data/lib/data_migrate/data_schema.rb +63 -0
  8. data/lib/data_migrate/data_schema_migration.rb +23 -6
  9. data/lib/data_migrate/database_configurations_wrapper.rb +11 -0
  10. data/lib/data_migrate/database_tasks.rb +290 -0
  11. data/lib/data_migrate/migration_context.rb +93 -0
  12. data/lib/data_migrate/rails_helper.rb +91 -0
  13. data/lib/data_migrate/schema_dumper.rb +38 -0
  14. data/lib/data_migrate/schema_migration.rb +41 -0
  15. data/lib/data_migrate/status_service.rb +58 -0
  16. data/lib/data_migrate/tasks/data_migrate_tasks.rb +107 -0
  17. data/lib/data_migrate/version.rb +1 -1
  18. data/lib/data_migrate.rb +20 -7
  19. data/lib/generators/data_migrate.rb +15 -2
  20. data/lib/generators/data_migration/data_migration_generator.rb +22 -21
  21. data/lib/generators/data_migration/templates/data_migration.rb +4 -2
  22. data/tasks/databases.rake +115 -228
  23. metadata +64 -42
  24. data/.gitignore +0 -6
  25. data/.rspec +0 -3
  26. data/.travis.yml +0 -17
  27. data/Appraisals +0 -21
  28. data/Gemfile +0 -4
  29. data/Gemfile.rails5 +0 -5
  30. data/Gemfile.rails5.1 +0 -5
  31. data/Rakefile +0 -2
  32. data/data_migrate.gemspec +0 -39
  33. data/gemfiles/rails_4.0.gemfile +0 -7
  34. data/gemfiles/rails_4.1.gemfile +0 -7
  35. data/gemfiles/rails_4.2.gemfile +0 -8
  36. data/gemfiles/rails_5.0.gemfile +0 -7
  37. data/gemfiles/rails_5.1.gemfile +0 -7
  38. data/lib/data_migrate/migration.rb +0 -26
  39. data/lib/data_migrate/migration_five.rb +0 -26
  40. data/screenshot.png +0 -0
  41. data/spec/data_migrate/data_migrator_spec.rb +0 -45
  42. data/spec/data_migrate/data_schema_migration_spec.rb +0 -16
  43. data/spec/data_migrate/migration.rb +0 -19
  44. data/spec/generators/data_migration/data_migration_generator_spec.rb +0 -27
  45. data/spec/spec_helper.rb +0 -5
  46. data/tasks/.gitkeep +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: bf69bd4a2c1fb2dc456bf88df16a89b06ea7b7dd
4
- data.tar.gz: 0836666a623ae289792dcba1b0422c98c9cd87cc
2
+ SHA256:
3
+ metadata.gz: 20f45c0a409f5eea659d56b8118d9625e3358cdd9d199978b56359d3416abe64
4
+ data.tar.gz: f553fd264b97b71671556ece98e9c79830223e960e7f41a46e383587a7b728c3
5
5
  SHA512:
6
- metadata.gz: 93da479ae6eb63a85d954d6a140e30578e7e511b4bec44aa0c952fb09e98e7b62bfd2f3661147872e3c08d28c245197582aa49c24012fe1615e3d680241b2d40
7
- data.tar.gz: 6d11fcff914918d0b2f1f5575e9f08cfcabf16ae912a98837bcc43e5407695b75f8b7300b32bf7ead08729946fb37ec7291c386ea6066a99b598962fc5e7a65d
6
+ metadata.gz: 8ac579c9ca5323c12e413f4c2ad228f9f36cbeb7d84624ff6fa24160f350b5e91f3ca7a8f18e469ce8e25dd4390a9d76316f40257dd9ef5bf4324c60309dd55f
7
+ data.tar.gz: f2fe12d32734ba839ce736d6634d2e794aad151b2719ff6e4a9bf1c9a05ccfdc4ab2a2de6bed8636a9423e89d6dddf62442ccf2f4c91ede15cf66736f36ff64f
data/Changelog.md CHANGED
@@ -1,7 +1,251 @@
1
- Changelog
2
- =========
1
+ # Changelog
2
+
3
+ # 11.3.0
4
+ - Make table_name configurable https://github.com/ilyakatz/data-migrate/pull/361
5
+ - Use lease_connection over deprecated connection for rails 8 https://github.com/ilyakatz/data-migrate/pull/353
6
+ - Add Ruby 3.4 to CI matrix
7
+
8
+ # 11.2.0
9
+ - Remove committed Gemfile.lock, reduce bundled file list when running `gem install` https://github.com/ilyakatz/data-migrate/pull/351
10
+ - [Bump actionpack from 7.1.3.4 to 7.1.4.1](https://github.com/ilyakatz/data-migrate/pull/348)
11
+ - [Bump rexml from 3.3.6 to 3.3.9](https://github.com/ilyakatz/data-migrate/pull/349)
12
+ - Fix db_config_with_versions arity change and backport https://github.com/ilyakatz/data-migrate/pull/337
13
+
14
+ # 11.1.0
15
+ - Allow multiple data migration paths https://github.com/ilyakatz/data-migrate/pull/331
16
+ - Fix db:prepare:with_data task on [Rails 7.2](https://github.com/ilyakatz/data-migrate/pull/339)
17
+ - Fix ConnectionPool deprecation warnings on [Rails 7.2](https://github.com/ilyakatz/data-migrate/pull/341)
18
+ - Add Rails 8.0 to testing grounds https://github.com/ilyakatz/data-migrate/pull/341
19
+ - [Bump webrick from 1.8.1 to 1.8.2](https://github.com/ilyakatz/data-migrate/pull/345)
20
+
21
+ # 11.0.0
22
+ - [Update rexml to 3.3.6](https://github.com/ilyakatz/data-migrate/pull/329)
23
+ - Fixes a bug which ignored migrations on [Rails 7.1 and higher](https://github.com/ilyakatz/data-migrate/pull/326)
24
+
25
+ # 11.0.0rc
26
+ - Remove Ruby 3.0 from build matrix
27
+ - Support Rails 7.2.0 https://github.com/ilyakatz/data-migrate/pull/312
28
+ - Update gemfile.lock builds
29
+
30
+ ## 9.4.2
31
+ - Fix db:prepare:with_data task
32
+
33
+ ## 9.4.1
34
+ - Add db:prepare task
35
+
36
+ ## 9.4.0
37
+ - Reset model schema cache before each data migration https://github.com/ilyakatz/data-migrate/pull/307
38
+ - Run load_config rake task before db:migrate:with_data https://github.com/ilyakatz/data-migrate/pull/308
39
+
40
+ ## 9.3.0
41
+ - Improve with_data Rake task for multiple database https://github.com/ilyakatz/data-migrate/pull/296
42
+
43
+ ## 9.2.0
44
+ - Support Rails 7.1 https://github.com/ilyakatz/data-migrate/pull/278
45
+ - Build and test against 7.1.0.rc1 https://github.com/ilyakatz/data-migrate/pull/286
46
+
47
+ ## 9.1.0
48
+
49
+ - Fix a bug that caused `schema_sha1` in `ar_internal_metadata` to be reset to the `data_schema.rb` file. (#272)
50
+ - Remove the need for empty data_schema files for non-primary databases. (#273)
51
+
52
+ ## [YANKED] 10.0.3.rc
53
+
54
+ - Remove all travis references [leoarnold](https//:github.com/leoarnold)
55
+ - Changing to rc because of ongoing discussion how to properly handle multiple database environments
56
+
57
+ ## [YANKED] 10.0.2
58
+
59
+ Change "rails" dependencies to "railties"
60
+
61
+ ## [YANKED] 10.0.1
62
+
63
+ - Bug fix for Rails 6 config [chaunce](https//:github.com/chaunce)
64
+ - Railties bug fix by [opti](https://github.com/opti)
65
+
66
+ ## [YANKED] 10.0.0
67
+
68
+ Releasing 10.0.0
69
+
70
+ !!! Breaking changes !!!
71
+
72
+ - This version introduces a breaking change which may lead to undesired
73
+ behavior in multi-database environments. See https://github.com/ilyakatz/data-migrate/issues/181
74
+
75
+ ## [YANKED] 10.0.0.rc1
76
+
77
+ - Changes by [chaunce](https//:github.com/chaunce)
78
+ - Multiple databases support
79
+ - Refactor to clean things up
80
+ - Deprecate rails 5.2 support for real
81
+
82
+ ## 9.0.0
83
+
84
+ Ruby 3.2 support [mehanoid](https://github.com/mehanoid)
85
+ Rails 5.2 is no longer supported
86
+
87
+ ## 8.5.0
88
+
89
+ Allow custom templates [bazay](https://github.com/bazay)
90
+
91
+ ## 8.4.0
92
+
93
+ Avoid Globally Accessible Functions for All Rake Tasks [berniechiu](https://github.com/berniechiu)
94
+
95
+ ## 8.3.0
96
+
97
+ Add delegation to exists? for use by third parties [foxondo](https://github.com/foxondo)
98
+
99
+ ## 8.2.0
100
+
101
+ Delegate to anonymous subclass of AR::SchemaMigration [foxondo](https://github.com/foxondo)
102
+
103
+ ## 8.1.1
104
+
105
+ Revert 8.1.0 changes
106
+
107
+ ## 8.1.0
108
+
109
+ Avoid globally accessible functions for all rake tasks [berniechiu](https://github.com/berniechiu)
110
+ fixed `db:migrate:with_data` to compare data schema versions correctly [cadactive](https://github.com/cadactive)
111
+
112
+ ## 8.0.0.rc2
113
+
114
+ Bug fixes [gdott9](https://github.com/gdott9)
115
+
116
+ ## 8.0.0.rc1
117
+ Add support for Rails 7
118
+ Removed support for Rails versions below 5.2. Now are supported only versions Rails 5.2 and up
119
+
120
+ ## 7.0.2
121
+
122
+ Remove magic comment in migration files [y-yagi](https://github.com/y-yagi)
123
+ User frozen string [jonnay](https://github.com/jonnay)
124
+ ## 7.0.1
125
+ Use SchemaMigration.migrations_paths in main rake task [lewhit](https://github.com/lewhit)
126
+
127
+ ## 6.8.0
128
+
129
+ Specify database name for migrations_paths [lewhit](https://github.com/lewhit)
130
+ ## 6.7.0
131
+
132
+ Add configuration for which database name is to be used for database migrations [lewhit](https://github.com/lewhit)
133
+ Add tests for Rails 6.1 [lewhit](https://github.com/lewhit)
134
+ Migrations files should end only in .rb [kroehre](https://github.com/kroehre)
135
+
136
+ ## 6.6.2
137
+ ## 6.6.1
138
+
139
+ configs_for deprecation notice [borama](https://github.com/borama)
140
+ ## 6.6.0
141
+
142
+ Allow data dump connection to be configured [lewhit](https://github.com/lewhit)
143
+
144
+ ## 6.4.0
145
+
146
+ Add primary key to data_migrations table [aandis](https://github.com/aandis)
147
+
148
+ ## 6.3.0
149
+
150
+ Add `abort_if_pending_migrations` rake tasks [tomgia](https://github.com/tomgia)
151
+
152
+ ## 6.2.0
153
+
154
+ Add `rake data:schema:load` [timkrins](https://github.com/timkrins)
155
+
156
+ ## 6.1.0
157
+
158
+ Fixing `rake db:schema:load:with_data` for Rails 6
159
+
160
+ Note:
161
+
162
+ Rails 5.0 is no longer maintained. The gem will still work but it is not being
163
+ actively tested.
164
+
165
+ ## 6.0.5
166
+
167
+ Fixing `needs_migration?` method for Rails 5.2 and up [EnomaDebby](https://github.com/EnomaDebby)
168
+
169
+ ## 6.0.4.beta
170
+
171
+ Fix rolling back schema migrations failing for Rails 5.2 and above
172
+
173
+ ## 6.0.3.beta
174
+
175
+ Compatiblity with Rails 6 RC2 [y-yagi](https://github.com/y-yagi)
176
+
177
+ ## 6.0.1.beta
178
+
179
+ Fix migrations being generated in wrong folder
180
+
181
+ ## 6.0.0
182
+
183
+ Support for Rails 6
184
+ No longer supporting Rails 4.2
185
+
186
+ ## 5.3.3
187
+
188
+ Ruby 2.2 and 2.3 are no longer actively validated with tests since they are both EOL
189
+
190
+ ## 5.3.2
191
+
192
+ Fix capistrano migration tasks to only skip migrations if there are no changes in the db/data and db/migrate folders
193
+
194
+ ## 5.3.1
195
+
196
+ Change database task to use data_migrations_path_configuration
197
+
198
+ ## 5.3.0
199
+
200
+ Add support to configure data migration path
201
+
202
+ ## 5.1.0
203
+
204
+ Fixes to `db:schema:load:with_data` + `db:structure:load:with_data` definition, thanks to [craineum](https://github.com/craineum)
205
+
206
+ ## 5.0.0
207
+
208
+ Remove support for legacy migrations (from v2).
209
+
210
+ **IMPORTANT**: If you used this gem from before version 2, make sure to run migration script
211
+
212
+ ```
213
+ DataMigrate::LegacyMigrator.new.migrate
214
+ ```
215
+
216
+ **Failure to do so may cause re-running old migrations**
217
+
218
+ ## 4.0.0
219
+
220
+ Support for Rails 5.2
221
+ Deprecated support for Rails 4.1
222
+ Internal changes to make data-migrate behavior more similar to Rails migrations
223
+
224
+ ## 3.5.0
225
+
226
+ Deprecated support for rails 4.0
227
+ Improvements to timestamped migrations, thanks to [Pierre-Michard](https://github.com/Pierre-Michard)
228
+
229
+ ## 3.4.0
230
+
231
+ `rake data:migrate:status` to return result in chronological order
232
+
233
+ ## 3.3.1
234
+
235
+ Regression fix, thanks to [subakva](https://github.com/subakva)
236
+
237
+ ## 3.3.0
238
+
239
+ The concept of schema:dump to data migrations, thanks to
240
+ [tobyndockerill](https://github.com/tobyndockerill)
241
+
242
+ ## 3.2.1
243
+
244
+ data_migrate table into rails schema dump, thanks to
245
+ [jturkel](https://github.com/jturkel)
3
246
 
4
247
  ## 3.2.0
248
+
5
249
  - Add support for Rails 5.1
6
250
  - No longer testing EOL rubies
7
251
 
data/README.md CHANGED
@@ -1,10 +1,9 @@
1
- Data Migrate
2
- ====
1
+ # Data Migrate
3
2
 
4
3
  - [![Version](http://img.shields.io/gem/v/data_migrate.svg?style=flat-square)](https://rubygems.org/gems/data_migrate)
5
4
  - [![License](http://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](http://opensource.org/licenses/MIT)
6
- - [![Travis](https://img.shields.io/travis/ilyakatz/data-migrate.svg)](https://travis-ci.org/ilyakatz/data-migrate)
7
-
5
+ - ![.github/workflows/build.yml](https://github.com/ilyakatz/data-migrate/actions/workflows/.github/workflows/build.yml/badge.svg)
6
+ - [![Reviewed by Hound](https://img.shields.io/badge/Reviewed_by-Hound-8E64B0.svg)](https://houndci.com)
8
7
 
9
8
  Run data migrations alongside schema migrations.
10
9
 
@@ -13,48 +12,16 @@ migrations, except they should be reserved for data migrations. For
13
12
  instance, if you realize you need to titleize all your titles, this
14
13
  is the place to do it.
15
14
 
16
- ![Travis](./screenshot.png)
17
-
18
- # Why should I use this?
19
-
20
- Its seems when a project hits a certain size, I get to manipulate data
21
- outside the application itself. Changing defaults, new validations,
22
- one-to-one to one-to-many... I found it a pain and dodgy to have to
23
- step up migrations one by one, run a ruby script of some sort, then
24
- resume migrations. It tanks a lot of the automation of deploy.
25
-
26
- If you don't use the one off scripts, you could do it as a regular
27
- migration. It'd be much better to keep concerns separate. The benefit
28
- of having them separate has to do with your data model.
29
-
30
- For instance, lets take an absurd example, to illustrate: You have
31
- a blog application that has posts with many comments.
32
- After some use, you decide you are going to be a trend setter,
33
- and want only one comment per post, and just the text.
34
-
35
- Given that you:
36
- - write a migration to add a comment column to `Post`
37
- - write a migration to move the contents of the first comments to the `Post`
38
- - drop the `column_id` column from `Post`
39
- - drop the `Comment` model
40
- - fix all your tests
41
-
42
- You've just got bit. When you `rake setup:development`, the mess gets
43
- mad at you after it creates your database, and starts cranking through
44
- migrations. It gets to the part where you iterate over the comments
45
- and it blows up. You don't have a `Comment` model anymore for it to
46
- even try and get 'all' from. You think you are smarter, and wrap the
47
- ActiveRecord call in a conditional based on the environment.
48
-
49
- That's fine until you get that QA gal, and she wants her own thing.
50
- Then the UI people get tired of waiting for the full stack to load on page
51
- refreshes, so you have to edit past migrations...
52
-
53
- With Data Migrate, you have the control. You can generate your
54
- migrations as schema or data as you would as your work flow. For
55
- setting tasks that don't require any intermediate AR activity, like
56
- dev and test, you stick with `db:migrate`. For production and QA, you
57
- change their scripts to `db:migrate:with_data`. Of course you want to
15
+ ![directory tree example](./screenshot.png)
16
+
17
+ ## Why should I use this?
18
+
19
+ With data-migrate you can generate your migrations for data as you would schema
20
+ in your regular work flow.
21
+
22
+ For setting tasks that don't require any intermediate AR activity, like
23
+ dev and test, you stick with `db:migrate`. For production and QA, you
24
+ change their scripts to `db:migrate:with_data`. Of course you want to
58
25
  test your migration, so you have the choice of `db:migrate:with_data` or
59
26
  `data:migrate` to just capture that data change.
60
27
 
@@ -65,28 +32,17 @@ migrations, except they should be reserved for data migrations. For
65
32
  instance, if you realize you need to titleize all yours titles, this
66
33
  is the place to do it. Running any of the provided rake tasks also
67
34
  creates a data schema table to mirror the usual schema migrations
68
- table to track all the goodness.
35
+ table to track all migrations.
69
36
 
70
37
  ## Rails Support
71
38
 
72
- Rails 3.1: Version 1.2 supports Rails 3.1.0 and higher **but** is no longer maintained.
73
-
74
- Rails 4: Version 2.0 supports Rails 4.0 and higher
75
-
76
- Rails 5.0: Supported
77
-
78
- Rails 5.1: Supported
39
+ Support Rails 6.1 through 8.0
79
40
 
80
- ### Important notes for older versions
41
+ For **Rails 6.0** support, please use gem version `9.1.x`:
81
42
 
82
- #### v2
83
-
84
- If you upgraded to Rails 4 while using `data_migrate` prior to version 2,
85
- the gem wrote data migration versions into
86
- `schema_migrations` table. After the fix, it was corrected to write into
87
- `data_migrations`.
88
-
89
- This may cause some unintended consequences. See [#22](https://github.com/ilyakatz/data-migrate/issues/22)
43
+ ```ruby
44
+ gem 'data_migrate', '~> 9.1.0'
45
+ ```
90
46
 
91
47
  #### v1
92
48
 
@@ -94,6 +50,7 @@ If you've installed previous to v1.1.0, you'll want to delete the
94
50
  `create_data_migrations_table` migration.
95
51
 
96
52
  ## Installation
53
+
97
54
  Add the gem to your project
98
55
 
99
56
  # Gemfile
@@ -105,7 +62,6 @@ So you know, when you use one of the provide rake tasks, a table
105
62
  called `data_migrations` will be created in your database. This
106
63
  is to mirror the way the standard `db` rake tasks work.
107
64
 
108
-
109
65
  ## Usage
110
66
 
111
67
  ### Generating Migrations
@@ -117,28 +73,62 @@ You can generate a data migration as you would a schema migration:
117
73
  ### Rake Tasks
118
74
 
119
75
  $> rake -T data
120
- rake data:forward # Pushes the schema to the next version (specify steps w/ STEP=n)
121
- rake data:migrate # Migrate data migrations (options: VERSION=x, VERBOSE=false)
122
- rake data:migrate:down # Runs the "down" for a given migration VERSION
123
- rake data:migrate:redo # Rollbacks the database one migration and re migrate up (options: STEP=x, VERSIO...
124
- rake data:migrate:status # Display status of data migrations
125
- rake data:migrate:up # Runs the "up" for a given migration VERSION
126
- rake data:rollback # Rolls the schema back to the previous version (specify steps w/ STEP=n)
127
- rake data:version # Retrieves the current schema version number for data migrations
128
- rake db:forward:with_data # Pushes the schema to the next version (specify steps w/ STEP=n)
129
- rake db:migrate:down:with_data # Runs the "down" for a given migration VERSION
130
- rake db:migrate:redo:with_data # Rollbacks the database one migration and re migrate up (options: STEP=x, VERSIO...
131
- rake db:migrate:status:with_data # Display status of data and schema migrations
132
- rake db:migrate:up:with_data # Runs the "up" for a given migration VERSION
133
- rake db:migrate:with_data # Migrate the database data and schema (options: VERSION=x, VERBOSE=false)
134
- rake db:rollback:with_data # Rolls the schema back to the previous version (specify steps w/ STEP=n)
135
- rake db:version:with_data # Retrieves the current schema version numbers for data and schema migrations
136
-
137
- Tasks work as they would with the 'vanilla' db version. The 'with_data' addition to the 'db' tasks will run the task in the context of both the data and schema migrations. That is, `rake db:rollback:with_data` will check to see if it was a schema or data migration invoked last, and do that. Tasks invoked in that space also have an additional line of output, indicating if the action is performed on data or schema.
138
-
139
- With 'up' and 'down', you can specify the option 'BOTH', which defaults to false. Using true, will migrate both the data and schema (in the desired direction) if they both match the version provided. Again, going up, schema is given precedence. Down its data.
140
-
141
- `rake db:migrate:status:with_data` provides and additional column to indicate which type of migration.
76
+ rake data:abort_if_pending_migrations # Raises an error if there are pending data migrations
77
+ rake data:dump # Create a db/data_schema.rb file that stores the current data version
78
+ rake data:forward # Pushes the schema to the next version (specify steps w/ STEP=n)
79
+ rake data:migrate # Migrate data migrations (options: VERSION=x, VERBOSE=false)
80
+ rake data:migrate:down # Runs the "down" for a given migration VERSION
81
+ rake data:migrate:redo # Rollbacks the database one migration and re migrate up (options: STEP=x, VERSION=x)
82
+ rake data:migrate:status # Display status of data migrations
83
+ rake data:migrate:up # Runs the "up" for a given migration VERSION
84
+ rake data:rollback # Rolls the schema back to the previous version (specify steps w/ STEP=n)
85
+ rake data:schema:load # Load data_schema.rb file into the database without running the data migrations
86
+ rake data:version # Retrieves the current schema version number for data migrations
87
+ rake db:abort_if_pending_migrations:with_data # Raises an error if there are pending migrations or data migrations
88
+ rake db:forward:with_data # Pushes the schema to the next version (specify steps w/ STEP=n)
89
+ rake db:migrate:down:with_data # Runs the "down" for a given migration VERSION
90
+ rake db:migrate:redo:with_data # Rollbacks the database one migration and re migrate up (options: STEP=x, VERSION=x)
91
+ rake db:migrate:status:with_data # Display status of data and schema migrations
92
+ rake db:migrate:up:with_data # Runs the "up" for a given migration VERSION
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
95
+ rake db:rollback:with_data # Rolls the schema back to the previous version (specify steps w/ STEP=n)
96
+ rake db:schema:load:with_data # Load both schema.rb and data_schema.rb file into the database
97
+ rake db:structure:load:with_data # Load both structure.sql and data_schema.rb file into the database
98
+ rake db:version:with_data # Retrieves the current schema version numbers for data and schema migrations
99
+
100
+
101
+ Tasks work as they would with the 'vanilla' db version. The 'with_data' addition to the 'db' tasks will run the task in the context of both the data and schema migrations. That is, rake db:rollback:with_data will check to see if it was a schema or data migration invoked last, and do that. Tasks invoked in that space also have an additional line of output, indicating if the action is performed on data or schema.
102
+
103
+ With 'up' and 'down', you can specify the option 'BOTH', which defaults to false. Using true, will migrate both the data and schema (in the desired direction) if they both match the version provided. Again, going up, schema is given precedence. Down its data.
104
+
105
+ When using `rake db:migrate:with_data` migrations will be run in ascending order by their version. For example, if you have a data migration with version 20230410000000 and a schema migration with version 20230415000000, expect the data migration to run first.
106
+
107
+ `rake db:migrate:status:with_data` provides an additional column to indicate which type of migration.
108
+
109
+ ### Configuration
110
+
111
+ `data_migrate` respects `ActiveRecord::Base.dump_schema_after_migration`. If it is set to `false`, data schema file will not be generated
112
+
113
+ By default, data migrations are added to the `db/data/` path.
114
+ You can override this setting in `config/initializers/data_migrate.rb`
115
+
116
+ ```ruby
117
+ DataMigrate.configure do |config|
118
+ config.data_migrations_table_name = 'my_migrations_database_name'
119
+ config.data_migrations_path = 'db/awesomepath/'
120
+ config.data_template_path = Rails.root.join("lib", "awesomepath", "custom_data_migration.rb")
121
+ config.db_configuration = {
122
+ 'host' => '127.0.0.1',
123
+ 'database' => 'awesome_database',
124
+ 'adapter' => 'mysql2',
125
+ 'username' => 'root',
126
+ 'password' => nil,
127
+ }
128
+ config.spec_name = 'primary'
129
+ end
130
+
131
+ ```
142
132
 
143
133
  ## Capistrano Support
144
134
 
@@ -152,6 +142,20 @@ require 'capistrano/data_migrate'
152
142
 
153
143
  From now on capistrano will run `rake db:migrate:with_data` in every deploy.
154
144
 
145
+ ## Rails Engines support
146
+
147
+ This gem also has a initial support for adding data migrations inside Rails engines.
148
+ Just add your engines directory pattern to data_migrations initializer, for example
149
+ in the case your engines are located in `engines` folder you can set it up like this:
150
+
151
+ ```ruby
152
+ DataMigrate.configure do |config|
153
+ config.data_migrations_path = ['db/data'] + Dir['engines/**/db/data']
154
+ end
155
+ ```
156
+
157
+ Then, in the Engine's `db/data` folder, you can add data migrations and run them as usual.
158
+
155
159
  ### Contributing
156
160
 
157
161
  ## Testing
@@ -159,14 +163,26 @@ From now on capistrano will run `rake db:migrate:with_data` in every deploy.
159
163
  Run tests for a specific version of Rails
160
164
 
161
165
  ```
162
- appraisal install
163
- appraisal rails-4.2 rspec
164
- appraisal rails-5.0 rspec
166
+ bundle exec appraisal rails-6.1 rspec
167
+ bundle exec appraisal rails-7.0 rspec
168
+ bundle exec appraisal rails-7.1 rspec
169
+ bundle exec appraisal rails-7.2 rspec
170
+ bundle exec appraisal rails-8.0 rspec
165
171
  ```
166
172
 
173
+ ## Releasing new version
174
+
175
+ 1. Update version.rb file, run `bundle exec appraisal` to update the version in corresponding gemfile.lock
176
+ 2. Create a new tag, eg `git tag 9.4.1`
177
+ 3. Go to https://github.com/ilyakatz/data-migrate/tags
178
+ 4. Click "Create release" under 9.4.1
179
+ 5. CLick "Generate release notes"
180
+ 6. Click "Publish release"
181
+
167
182
  ## Thanks
183
+
168
184
  [Andrew J Vargo](http://github.com/ajvargo) Andrew was the original creator and maintainer of this project!
169
185
 
170
- [Jeremy Durham](http://jeremydurham.com/) for fleshing out the idea with me, and providing guidance.
186
+ [Jeremy Durham](http://jeremydurham.com/) for fleshing out the idea and providing guidance.
171
187
 
172
- You! Yes, you. Thanks for checking it out.
188
+ You! Yes, you. Thanks for checking it out.
@@ -7,10 +7,9 @@ namespace :deploy do
7
7
  conditionally_migrate = fetch(:conditionally_migrate)
8
8
  info '[deploy:migrate] Checking changes in db/migrate or db/data' if conditionally_migrate
9
9
 
10
- if conditionally_migrate && (
11
- test("diff -q #{release_path}/db/migrate #{current_path}/db/migrate") ||
12
- test("diff -q #{release_path}/db/data #{current_path}/db/data")
13
- )
10
+ if conditionally_migrate &&
11
+ test("diff -q #{release_path}/db/migrate #{current_path}/db/migrate") &&
12
+ test("diff -q #{release_path}/db/data #{current_path}/db/data")
14
13
  info '[deploy:migrate] Skip `deploy:migrate` (nothing changed in db/migrate or db/data)'
15
14
  else
16
15
  info '[deploy:migrate] Run `rake db:migrate:with_data`'
@@ -0,0 +1,33 @@
1
+ module DataMigrate
2
+ include ActiveSupport::Configurable
3
+ class << self
4
+
5
+ def configure
6
+ yield config
7
+ end
8
+
9
+ def config
10
+ @config ||= Config.new
11
+ end
12
+ end
13
+
14
+ class Config
15
+ attr_accessor :data_migrations_table_name, :data_migrations_path, :data_template_path, :db_configuration, :spec_name
16
+
17
+ DEFAULT_DATA_TEMPLATE_PATH = "data_migration.rb"
18
+
19
+ def initialize
20
+ @data_migrations_table_name = "data_migrations"
21
+ @data_migrations_path = "db/data/"
22
+ @data_template_path = DEFAULT_DATA_TEMPLATE_PATH
23
+ @db_configuration = nil
24
+ @spec_name = nil
25
+ end
26
+
27
+ def data_template_path=(value)
28
+ @data_template_path = value.tap do |path|
29
+ raise ArgumentError, "File not found: '#{path}'" unless path == DEFAULT_DATA_TEMPLATE_PATH || File.exist?(path)
30
+ end
31
+ end
32
+ end
33
+ end