data_migrate 2.2.0 → 11.3.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 6983740ef87afeb4aa83f557c1f42e5e4f062223
4
- data.tar.gz: 91e0c313ec9ec3fed6b3483a94c35fefac8789f7
2
+ SHA256:
3
+ metadata.gz: 7bef47d5608c410a0158dfd4847c065895db273e0809f8467f3cae2e4d428604
4
+ data.tar.gz: 5f1221a6c8fa70c5d095790892877e1aee369c3a06f2e145ec87534e06993065
5
5
  SHA512:
6
- metadata.gz: abdb401fd44de7e22a1cb5b310cea84b147d95a4790f6b2b7dc6e33e878d9f42c8d94a4e73f7759d06550a2814f3133510c6a4bcfd43e6761366f2a045780775
7
- data.tar.gz: 69c8dcef142680e1109d75ee2cced9b5179bb5dc6ba8216a0c62fca6926e6f63023644f98885981a372c065c9265162985874f5dbc989480d9a530c381fed945
6
+ metadata.gz: 3df1a19a487efc065928f135dc8e372e282d300956b2172d654247d9f6bbc3edbfff279e309b1d557093e7ef44ba49217de9dbfd7d58f75c96d6e91be83fd3ec
7
+ data.tar.gz: 524ed4970e8f98a761d6b845b7d1d9be23015599be203e4aed2fb7fda68fe16b84a9dbcb29e68746de6d73559a2de584bad35307a1d60d134c8411b9f07fd75c
data/Changelog.md CHANGED
@@ -1,5 +1,272 @@
1
- Changelog
2
- =========
1
+ # Changelog
2
+
3
+ # 11.3.1
4
+ - Schema version -- do formatted version like activerecord https://github.com/ilyakatz/data-migrate/pull/363
5
+ - Resolve ActiveSupport::Configurable deprecation in Rails 8.2 https://github.com/ilyakatz/data-migrate/pull/365
6
+ - Add support for Rails 8.1 in Appraisal https://github.com/ilyakatz/data-migrate/pull/366
7
+
8
+ # 11.3.0
9
+ - Make table_name configurable https://github.com/ilyakatz/data-migrate/pull/361
10
+ - Use lease_connection over deprecated connection for rails 8 https://github.com/ilyakatz/data-migrate/pull/353
11
+ - Add Ruby 3.4 to CI matrix
12
+
13
+ # 11.2.0
14
+ - Remove committed Gemfile.lock, reduce bundled file list when running `gem install` https://github.com/ilyakatz/data-migrate/pull/351
15
+ - [Bump actionpack from 7.1.3.4 to 7.1.4.1](https://github.com/ilyakatz/data-migrate/pull/348)
16
+ - [Bump rexml from 3.3.6 to 3.3.9](https://github.com/ilyakatz/data-migrate/pull/349)
17
+ - Fix db_config_with_versions arity change and backport https://github.com/ilyakatz/data-migrate/pull/337
18
+
19
+ # 11.1.0
20
+ - Allow multiple data migration paths https://github.com/ilyakatz/data-migrate/pull/331
21
+ - Fix db:prepare:with_data task on [Rails 7.2](https://github.com/ilyakatz/data-migrate/pull/339)
22
+ - Fix ConnectionPool deprecation warnings on [Rails 7.2](https://github.com/ilyakatz/data-migrate/pull/341)
23
+ - Add Rails 8.0 to testing grounds https://github.com/ilyakatz/data-migrate/pull/341
24
+ - [Bump webrick from 1.8.1 to 1.8.2](https://github.com/ilyakatz/data-migrate/pull/345)
25
+
26
+ # 11.0.0
27
+ - [Update rexml to 3.3.6](https://github.com/ilyakatz/data-migrate/pull/329)
28
+ - Fixes a bug which ignored migrations on [Rails 7.1 and higher](https://github.com/ilyakatz/data-migrate/pull/326)
29
+
30
+ # 11.0.0rc
31
+ - Remove Ruby 3.0 from build matrix
32
+ - Support Rails 7.2.0 https://github.com/ilyakatz/data-migrate/pull/312
33
+ - Update gemfile.lock builds
34
+
35
+ ## 9.4.2
36
+ - Fix db:prepare:with_data task
37
+
38
+ ## 9.4.1
39
+ - Add db:prepare task
40
+
41
+ ## 9.4.0
42
+ - Reset model schema cache before each data migration https://github.com/ilyakatz/data-migrate/pull/307
43
+ - Run load_config rake task before db:migrate:with_data https://github.com/ilyakatz/data-migrate/pull/308
44
+
45
+ ## 9.3.0
46
+ - Improve with_data Rake task for multiple database https://github.com/ilyakatz/data-migrate/pull/296
47
+
48
+ ## 9.2.0
49
+ - Support Rails 7.1 https://github.com/ilyakatz/data-migrate/pull/278
50
+ - Build and test against 7.1.0.rc1 https://github.com/ilyakatz/data-migrate/pull/286
51
+
52
+ ## 9.1.0
53
+
54
+ - Fix a bug that caused `schema_sha1` in `ar_internal_metadata` to be reset to the `data_schema.rb` file. (#272)
55
+ - Remove the need for empty data_schema files for non-primary databases. (#273)
56
+
57
+ ## [YANKED] 10.0.3.rc
58
+
59
+ - Remove all travis references [leoarnold](https//:github.com/leoarnold)
60
+ - Changing to rc because of ongoing discussion how to properly handle multiple database environments
61
+
62
+ ## [YANKED] 10.0.2
63
+
64
+ Change "rails" dependencies to "railties"
65
+
66
+ ## [YANKED] 10.0.1
67
+
68
+ - Bug fix for Rails 6 config [chaunce](https//:github.com/chaunce)
69
+ - Railties bug fix by [opti](https://github.com/opti)
70
+
71
+ ## [YANKED] 10.0.0
72
+
73
+ Releasing 10.0.0
74
+
75
+ !!! Breaking changes !!!
76
+
77
+ - This version introduces a breaking change which may lead to undesired
78
+ behavior in multi-database environments. See https://github.com/ilyakatz/data-migrate/issues/181
79
+
80
+ ## [YANKED] 10.0.0.rc1
81
+
82
+ - Changes by [chaunce](https//:github.com/chaunce)
83
+ - Multiple databases support
84
+ - Refactor to clean things up
85
+ - Deprecate rails 5.2 support for real
86
+
87
+ ## 9.0.0
88
+
89
+ Ruby 3.2 support [mehanoid](https://github.com/mehanoid)
90
+ Rails 5.2 is no longer supported
91
+
92
+ ## 8.5.0
93
+
94
+ Allow custom templates [bazay](https://github.com/bazay)
95
+
96
+ ## 8.4.0
97
+
98
+ Avoid Globally Accessible Functions for All Rake Tasks [berniechiu](https://github.com/berniechiu)
99
+
100
+ ## 8.3.0
101
+
102
+ Add delegation to exists? for use by third parties [foxondo](https://github.com/foxondo)
103
+
104
+ ## 8.2.0
105
+
106
+ Delegate to anonymous subclass of AR::SchemaMigration [foxondo](https://github.com/foxondo)
107
+
108
+ ## 8.1.1
109
+
110
+ Revert 8.1.0 changes
111
+
112
+ ## 8.1.0
113
+
114
+ Avoid globally accessible functions for all rake tasks [berniechiu](https://github.com/berniechiu)
115
+ fixed `db:migrate:with_data` to compare data schema versions correctly [cadactive](https://github.com/cadactive)
116
+
117
+ ## 8.0.0.rc2
118
+
119
+ Bug fixes [gdott9](https://github.com/gdott9)
120
+
121
+ ## 8.0.0.rc1
122
+ Add support for Rails 7
123
+ Removed support for Rails versions below 5.2. Now are supported only versions Rails 5.2 and up
124
+
125
+ ## 7.0.2
126
+
127
+ Remove magic comment in migration files [y-yagi](https://github.com/y-yagi)
128
+ User frozen string [jonnay](https://github.com/jonnay)
129
+ ## 7.0.1
130
+ Use SchemaMigration.migrations_paths in main rake task [lewhit](https://github.com/lewhit)
131
+
132
+ ## 6.8.0
133
+
134
+ Specify database name for migrations_paths [lewhit](https://github.com/lewhit)
135
+ ## 6.7.0
136
+
137
+ Add configuration for which database name is to be used for database migrations [lewhit](https://github.com/lewhit)
138
+ Add tests for Rails 6.1 [lewhit](https://github.com/lewhit)
139
+ Migrations files should end only in .rb [kroehre](https://github.com/kroehre)
140
+
141
+ ## 6.6.2
142
+ ## 6.6.1
143
+
144
+ configs_for deprecation notice [borama](https://github.com/borama)
145
+ ## 6.6.0
146
+
147
+ Allow data dump connection to be configured [lewhit](https://github.com/lewhit)
148
+
149
+ ## 6.4.0
150
+
151
+ Add primary key to data_migrations table [aandis](https://github.com/aandis)
152
+
153
+ ## 6.3.0
154
+
155
+ Add `abort_if_pending_migrations` rake tasks [tomgia](https://github.com/tomgia)
156
+
157
+ ## 6.2.0
158
+
159
+ Add `rake data:schema:load` [timkrins](https://github.com/timkrins)
160
+
161
+ ## 6.1.0
162
+
163
+ Fixing `rake db:schema:load:with_data` for Rails 6
164
+
165
+ Note:
166
+
167
+ Rails 5.0 is no longer maintained. The gem will still work but it is not being
168
+ actively tested.
169
+
170
+ ## 6.0.5
171
+
172
+ Fixing `needs_migration?` method for Rails 5.2 and up [EnomaDebby](https://github.com/EnomaDebby)
173
+
174
+ ## 6.0.4.beta
175
+
176
+ Fix rolling back schema migrations failing for Rails 5.2 and above
177
+
178
+ ## 6.0.3.beta
179
+
180
+ Compatiblity with Rails 6 RC2 [y-yagi](https://github.com/y-yagi)
181
+
182
+ ## 6.0.1.beta
183
+
184
+ Fix migrations being generated in wrong folder
185
+
186
+ ## 6.0.0
187
+
188
+ Support for Rails 6
189
+ No longer supporting Rails 4.2
190
+
191
+ ## 5.3.3
192
+
193
+ Ruby 2.2 and 2.3 are no longer actively validated with tests since they are both EOL
194
+
195
+ ## 5.3.2
196
+
197
+ Fix capistrano migration tasks to only skip migrations if there are no changes in the db/data and db/migrate folders
198
+
199
+ ## 5.3.1
200
+
201
+ Change database task to use data_migrations_path_configuration
202
+
203
+ ## 5.3.0
204
+
205
+ Add support to configure data migration path
206
+
207
+ ## 5.1.0
208
+
209
+ Fixes to `db:schema:load:with_data` + `db:structure:load:with_data` definition, thanks to [craineum](https://github.com/craineum)
210
+
211
+ ## 5.0.0
212
+
213
+ Remove support for legacy migrations (from v2).
214
+
215
+ **IMPORTANT**: If you used this gem from before version 2, make sure to run migration script
216
+
217
+ ```
218
+ DataMigrate::LegacyMigrator.new.migrate
219
+ ```
220
+
221
+ **Failure to do so may cause re-running old migrations**
222
+
223
+ ## 4.0.0
224
+
225
+ Support for Rails 5.2
226
+ Deprecated support for Rails 4.1
227
+ Internal changes to make data-migrate behavior more similar to Rails migrations
228
+
229
+ ## 3.5.0
230
+
231
+ Deprecated support for rails 4.0
232
+ Improvements to timestamped migrations, thanks to [Pierre-Michard](https://github.com/Pierre-Michard)
233
+
234
+ ## 3.4.0
235
+
236
+ `rake data:migrate:status` to return result in chronological order
237
+
238
+ ## 3.3.1
239
+
240
+ Regression fix, thanks to [subakva](https://github.com/subakva)
241
+
242
+ ## 3.3.0
243
+
244
+ The concept of schema:dump to data migrations, thanks to
245
+ [tobyndockerill](https://github.com/tobyndockerill)
246
+
247
+ ## 3.2.1
248
+
249
+ data_migrate table into rails schema dump, thanks to
250
+ [jturkel](https://github.com/jturkel)
251
+
252
+ ## 3.2.0
253
+
254
+ - Add support for Rails 5.1
255
+ - No longer testing EOL rubies
256
+
257
+ ## 3.1.0
258
+
259
+ Rails 5.0 support thanks to
260
+ [jturkel](https://github.com/jturkel) and [abreckner](https://github.com/abreckner)
261
+
262
+ ## 3.0.1
263
+
264
+ ([gacha](https://github.com/gacha)) Capistrano fixes
265
+
266
+ ## 3.0.0
267
+
268
+ `--skip-schema-migration` removed deprecated. This gem will no longer generate schema
269
+ migrations. It still supports running schema/data migrations with one command.
3
270
 
4
271
  ## 2.2.0
5
272
 
data/README.md CHANGED
@@ -1,96 +1,56 @@
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)
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)
6
7
 
7
8
  Run data migrations alongside schema migrations.
8
9
 
9
- Data migrations are stored in db/data. They act like schema
10
+ Data migrations are stored in `db/data`. They act like schema
10
11
  migrations, except they should be reserved for data migrations. For
11
12
  instance, if you realize you need to titleize all your titles, this
12
13
  is the place to do it.
13
14
 
14
- Why should I use this?
15
- ----------------------
16
-
17
- Its seems when a project hits a certain size, I get to manipulate data
18
- outside the application itself. Changing defaults, new validations,
19
- one-to-one to one-to-many... I found it a pain and dodgy to have to
20
- step up migrations one by one, run a ruby script of some sort, then
21
- resume migrations. It tanks a lot of the automation of deploy.
22
-
23
- If you don't use the one off scripts, you could do it as a regular
24
- migration. It'd be much better to keep concerns separate. The benefit
25
- of having them separate has to do with your data model.
26
-
27
- For instance, lets take an absurd example, to illustrate: You have
28
- your infamous [Rails blog](http://media.rubyonrails.org/video/rails-0-5.mov)
29
- that has posts with many comments. After some use, you decide you are
30
- going to be a trend setter, and want only one comment per post, and
31
- just the text. "Frist!!1!1" rules the day. Given that you:
32
- - write a migration to add a comment column to Post
33
- - write a migration to move the contents of the first comments to the Post
34
- - drop the column_id column from Post
35
- - drop the Comment model
36
- - fix all your test/controller/view mojo.
37
-
38
- You've just got bit. When you rake setup:development, the mess gets
39
- mad at you after it creates your database, and starts cranking through
40
- migrations. It gets to the part where you iterate over the comments
41
- and it blows up. You don't have a comment model anymore for it to
42
- even try and get 'all' from. You think you are smarter, and wrap the
43
- AR call in a conditional based on the environment. That's fine until
44
- you get that QA gal, and she wants her own thing. Then the UI people
45
- get tired of waiting for the full stack to load on page refreshes, so
46
- you have to edit past migrations...
47
-
48
- With Data Migrate, you have the control. You can generate your
49
- migrations as schema or data as you would as your work flow. For
50
- setting tasks that don't require any intermediate AR activity, like
51
- dev and test, you stick with db:migrate. For your prod, and qa, you
52
- 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
53
25
  test your migration, so you have the choice of `db:migrate:with_data` or
54
26
  `data:migrate` to just capture that data change.
55
27
 
56
- What's it do?
57
- -------------
28
+ ## What does it do?
58
29
 
59
- Data migrations are stored in db/data. They act like schema
30
+ Data migrations are stored in `db/data`. They act like schema
60
31
  migrations, except they should be reserved for data migrations. For
61
32
  instance, if you realize you need to titleize all yours titles, this
62
33
  is the place to do it. Running any of the provided rake tasks also
63
34
  creates a data schema table to mirror the usual schema migrations
64
- table to track all the goodness.
65
-
66
- Data migrations can be created at the same time as schema migrations,
67
- or independently. Database (db:) tasks have been added and extended
68
- to run on data migrations only, or in conjunction with the schema
69
- migration. For instance, `rake db:migrate:with_data` will run both
70
- schema and data migrations in the proper order.
35
+ table to track all migrations.
71
36
 
72
- Note: If a data and schema migration share the same version number, schema gets precedence when migrating up. Data does down.
37
+ ## Rails Support
73
38
 
74
- Rails Support
75
- --------------------
39
+ Support Rails 6.1 through 8.0
76
40
 
77
- Rails 3.1: Version 1.2 supports Rails 3.1.0 and higher **but** is not longer maintained.
41
+ For **Rails 6.0** support, please use gem version `9.1.x`:
78
42
 
79
- Rails 4: Version 2.0 supports Rails 4.0 and higher
80
-
81
- Rails 5: Not tested
43
+ ```ruby
44
+ gem 'data_migrate', '~> 9.1.0'
45
+ ```
82
46
 
83
- ### Important note
47
+ #### v1
84
48
 
85
- If you upgraded to Rails 4 while using `data_migrate` prior to version 2,
86
- the gem wrote data migration versions into
87
- `schema_migrations` table. After the fix, it was corrected to write into
88
- `data_migrations`.
49
+ If you've installed previous to v1.1.0, you'll want to delete the
50
+ `create_data_migrations_table` migration.
89
51
 
90
- This may cause some unintended consequences. See [#22](https://github.com/ilyakatz/data-migrate/issues/22)
52
+ ## Installation
91
53
 
92
- Installation
93
- ------------
94
54
  Add the gem to your project
95
55
 
96
56
  # Gemfile
@@ -99,13 +59,10 @@ Add the gem to your project
99
59
  Then `bundle install` and you are ready to go.
100
60
 
101
61
  So you know, when you use one of the provide rake tasks, a table
102
- called 'data_migrations' will be created in your database. This
103
- is to mirror the way the standard 'db' rake tasks work. If you've
104
- installed previous to v1.1.0, you'll want to delete the
105
- 'create\_data\_migrations_table' migration.
62
+ called `data_migrations` will be created in your database. This
63
+ is to mirror the way the standard `db` rake tasks work.
106
64
 
107
- Usage
108
- -----
65
+ ## Usage
109
66
 
110
67
  ### Generating Migrations
111
68
 
@@ -113,68 +70,119 @@ You can generate a data migration as you would a schema migration:
113
70
 
114
71
  rails g data_migration add_this_to_that
115
72
 
116
- By default, the migration also generates a schema migration by the same name.
117
- This allows you to do things like:
73
+ ### Rake Tasks
118
74
 
119
- rails g data_migration add_this_to_that this:string
75
+ $> rake -T data
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`
120
115
 
121
- If you need a data only migration, either run it as such, with the skip-schema-migration flag:
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
122
130
 
123
- rails g data_migration add_this_to_that --skip-schema-migration
131
+ ```
124
132
 
125
- ### Rake Tasks
133
+ ## Capistrano Support
126
134
 
127
- $> rake -T data
128
- rake data:forward # Pushes the schema to the next version (specify steps w/ STEP=n)
129
- rake data:migrate # Migrate data migrations (options: VERSION=x, VERBOSE=false)
130
- rake data:migrate:down # Runs the "down" for a given migration VERSION
131
- rake data:migrate:redo # Rollbacks the database one migration and re migrate up (options: STEP=x, VERSIO...
132
- rake data:migrate:status # Display status of data migrations
133
- rake data:migrate:up # Runs the "up" for a given migration VERSION
134
- rake data:rollback # Rolls the schema back to the previous version (specify steps w/ STEP=n)
135
- rake data:version # Retrieves the current schema version number for data migrations
136
- rake db:forward:with_data # Pushes the schema to the next version (specify steps w/ STEP=n)
137
- rake db:migrate:down:with_data # Runs the "down" for a given migration VERSION
138
- rake db:migrate:redo:with_data # Rollbacks the database one migration and re migrate up (options: STEP=x, VERSIO...
139
- rake db:migrate:status:with_data # Display status of data and schema migrations
140
- rake db:migrate:up:with_data # Runs the "up" for a given migration VERSION
141
- rake db:migrate:with_data # Migrate the database data and schema (options: VERSION=x, VERBOSE=false)
142
- rake db:rollback:with_data # Rolls the schema back to the previous version (specify steps w/ STEP=n)
143
- rake db:version:with_data # Retrieves the current schema version numbers for data and schema migrations
135
+ The gem comes with a capistrano task that can be used instead of `capistrano/rails/migrations`.
144
136
 
145
- 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.
137
+ Just add this line to your Capfile:
146
138
 
147
- 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.
139
+ ```ruby
140
+ require 'capistrano/data_migrate'
141
+ ```
148
142
 
149
- For more example, assume you have the 2 files:
150
- db/migrate/20110419021211_add_x_to_y.rb
151
- db/data/20110419021211_add_x_to_y.rb
143
+ From now on capistrano will run `rake db:migrate:with_data` in every deploy.
152
144
 
153
- Running `rake db:migrate:up:with_data VERSION=20110419021211` would execute the 'db/migrate' version.
154
- Running `rake db:migrate:up:with_data VERSION=20110419021211` would execute the 'db/migrate' version, followed by the 'db/data' version.
145
+ ## Rails Engines support
155
146
 
156
- Going down instead of up would be the opposite.
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:
157
150
 
158
- `rake db:migrate:status:with_data` provides and additional column to indicate which type of migration.
151
+ ```ruby
152
+ DataMigrate.configure do |config|
153
+ config.data_migrations_path = ['db/data'] + Dir['engines/**/db/data']
154
+ end
155
+ ```
159
156
 
160
- Capistrano Support
161
- ------------------
157
+ Then, in the Engine's `db/data` folder, you can add data migrations and run them as usual.
162
158
 
163
- The gem comes with a capistrano task that can be used instead of `capistrano/rails/migrations`.
159
+ ### Contributing
164
160
 
165
- Just add this line to your Capfile:
161
+ ## Testing
162
+
163
+ Run tests for a specific version of Rails
166
164
 
167
- ```ruby
168
- require 'capistrano/data_migrate'
165
+ ```
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
169
171
  ```
170
172
 
171
- From now on capistrano will run `rake db:migrate:with_data` in every deploy.
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"
172
181
 
182
+ ## Thanks
173
183
 
174
- Thanks
175
- ------
176
184
  [Andrew J Vargo](http://github.com/ajvargo) Andrew was the original creator and maintainer of this project!
177
185
 
178
- [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.
179
187
 
180
- You! Yes, you. Thanks for checking it out.
188
+ You! Yes, you. Thanks for checking it out.
@@ -1,15 +1,15 @@
1
1
  namespace :deploy do
2
2
 
3
3
  desc 'Runs rake data:migrate if migrations are set'
4
+ Rake::Task['deploy:migrate'].clear_actions
4
5
  task :migrate => [:set_rails_env] do
5
6
  on fetch(:migration_servers) do
6
7
  conditionally_migrate = fetch(:conditionally_migrate)
7
8
  info '[deploy:migrate] Checking changes in db/migrate or db/data' if conditionally_migrate
8
9
 
9
- if conditionally_migrate && (
10
- test("diff -q #{release_path}/db/migrate #{current_path}/db/migrate") ||
11
- test("diff -q #{release_path}/db/data #{current_path}/db/data")
12
- )
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
13
  info '[deploy:migrate] Skip `deploy:migrate` (nothing changed in db/migrate or db/data)'
14
14
  else
15
15
  info '[deploy:migrate] Run `rake db:migrate:with_data`'
@@ -0,0 +1,32 @@
1
+ module DataMigrate
2
+ class << self
3
+
4
+ def configure
5
+ yield config
6
+ end
7
+
8
+ def config
9
+ @config ||= Config.new
10
+ end
11
+ end
12
+
13
+ class Config
14
+ attr_accessor :data_migrations_table_name, :data_migrations_path, :data_template_path, :db_configuration, :spec_name
15
+
16
+ DEFAULT_DATA_TEMPLATE_PATH = "data_migration.rb"
17
+
18
+ def initialize
19
+ @data_migrations_table_name = "data_migrations"
20
+ @data_migrations_path = "db/data/"
21
+ @data_template_path = DEFAULT_DATA_TEMPLATE_PATH
22
+ @db_configuration = nil
23
+ @spec_name = nil
24
+ end
25
+
26
+ def data_template_path=(value)
27
+ @data_template_path = value.tap do |path|
28
+ raise ArgumentError, "File not found: '#{path}'" unless path == DEFAULT_DATA_TEMPLATE_PATH || File.exist?(path)
29
+ end
30
+ end
31
+ end
32
+ end