data_migrate 6.0.7 → 6.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b07f90de015dd791891bb123bb7ab577cf63e7eab3d3c4ffac79fc1bde1ec688
4
- data.tar.gz: 8b161c0ff1c89696bde0bcd94d5ff9e5a9b4be94148c29e99d034f783161c884
3
+ metadata.gz: 18145281c69f3a789a8fc2de0873b3ddbed3c1ccec3faed5de71a9ed2dad6e58
4
+ data.tar.gz: 93e91ecc167ad2fb8cf2ef664adf405e9d47868ead4ce0f24057269c9139dea0
5
5
  SHA512:
6
- metadata.gz: 1075302951b2cd717758d63bcec5e1ee5a70d2871ed81d3b6a3312b6978fb42087eb896b104afeff9add287f3d932fb2856a31b407e352fc4349d454ebdb7605
7
- data.tar.gz: f2cec3fb11588a0b1ab70c2958c36a75a5f37837189aa26b20d6eaacf3a9fca84f3bf18ff8bd0eda6c411b91a1d2050e7a76fb794ff9dc40dcbb71007f2202ca
6
+ metadata.gz: 3ff5ee90e37051fb6668ae63a2640c41cc8be3e301a6c5bb7b58a5581f81de71b54ecab7f66b0136c88733d9f4314b2e85e5c739da4ba9939607d7e0cde8c8b6
7
+ data.tar.gz: a328b2ddc325d69d98197ae2ae5db29932377e1c0bf1947ab08297bc5973ed167fbbc42ed70d35993fb02250efab721cdb0a4fb6789339da6f02af10a1664093
data/.travis.yml CHANGED
@@ -5,7 +5,6 @@ rvm:
5
5
  - 2.6.2
6
6
  script: bundle exec rspec
7
7
  gemfile:
8
- - gemfiles/rails_5.0.gemfile
9
8
  - gemfiles/rails_5.1.gemfile
10
9
  - gemfiles/rails_5.2.gemfile
11
10
  - gemfiles/rails_6.0.gemfile
data/Appraisals CHANGED
@@ -11,5 +11,5 @@ appraise 'rails-5.2' do
11
11
  end
12
12
 
13
13
  appraise 'rails-6.0' do
14
- gem 'rails', '~> 6.0.0.beta3'
14
+ gem 'rails', '~> 6.0.0'
15
15
  end
data/Changelog.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Changelog
2
2
 
3
+ ## 6.1.0
4
+
5
+ Fixing `rake db:schema:load:with_data` for Rails 6
6
+
7
+ Note:
8
+
9
+ Rails 5.0 is no longer maintained. The gem will still work but it is not being
10
+ actively tested.
11
+
3
12
  ## 6.0.5
4
13
 
5
14
  Fixing `needs_migration?` method for Rails 5.2 and up [EnomaDebby](https://github.com/EnomaDebby)
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  source "http://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in data_migrate.gemspec
4
- gem 'rails', path: "~/ws/rails"
4
+ gem 'rails', '~> 6.0.0'
5
5
  gem 'sqlite3', "~> 1.4"
6
6
  gemspec
data/README.md CHANGED
@@ -14,45 +14,12 @@ is the place to do it.
14
14
 
15
15
  ![Travis](./screenshot.png)
16
16
 
17
- # Why should I use this?
18
-
19
- Its seems when a project hits a certain size, I get to manipulate data
20
- outside the application itself. Changing defaults, new validations,
21
- one-to-one to one-to-many... I found it a pain and dodgy to have to
22
- step up migrations one by one, run a ruby script of some sort, then
23
- resume migrations. It tanks a lot of the automation of deploy.
24
-
25
- If you don't use the one off scripts, you could do it as a regular
26
- migration. It'd be much better to keep concerns separate. The benefit
27
- of having them separate has to do with your data model.
28
-
29
- For instance, lets take an absurd example, to illustrate: You have
30
- a blog application that has posts with many comments.
31
- After some use, you decide you are going to be a trend setter,
32
- and want only one comment per post, and just the text.
33
-
34
- Given that you:
35
-
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
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
56
23
  dev and test, you stick with `db:migrate`. For production and QA, you
57
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
@@ -65,7 +32,7 @@ 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
 
@@ -175,14 +142,15 @@ Run tests for a specific version of Rails
175
142
 
176
143
  ```
177
144
  bundle exec appraisal install
178
- bundle exec appraisal rails-5.0 rspec
145
+ bundle exec appraisal rails-5.1 rspec
179
146
  bundle exec appraisal rails-5.2 rspec
147
+ bundle exec appraisal rails-6.0 rspec
180
148
  ```
181
149
 
182
150
  ## Thanks
183
151
 
184
152
  [Andrew J Vargo](http://github.com/ajvargo) Andrew was the original creator and maintainer of this project!
185
153
 
186
- [Jeremy Durham](http://jeremydurham.com/) for fleshing out the idea with me, and providing guidance.
154
+ [Jeremy Durham](http://jeremydurham.com/) for fleshing out the idea and providing guidance.
187
155
 
188
156
  You! Yes, you. Thanks for checking it out.
@@ -3,5 +3,6 @@
3
3
  source "http://rubygems.org"
4
4
 
5
5
  gem "rails", "5.1.7"
6
+ gem "sqlite3", "~> 1.4"
6
7
 
7
8
  gemspec path: "../"
@@ -3,5 +3,6 @@
3
3
  source "http://rubygems.org"
4
4
 
5
5
  gem "rails", "~> 5.2.3"
6
+ gem "sqlite3", "~> 1.4"
6
7
 
7
8
  gemspec path: "../"
@@ -2,7 +2,7 @@
2
2
 
3
3
  source "http://rubygems.org"
4
4
 
5
- gem "rails", "~> 6.0.0.rc2"
5
+ gem "rails", "~> 6.0.0"
6
6
  gem "sqlite3", "~> 1.4"
7
7
 
8
8
  gemspec path: "../"
@@ -8,6 +8,33 @@ module DataMigrate
8
8
  class DatabaseTasks
9
9
  extend ActiveRecord::Tasks::DatabaseTasks
10
10
 
11
+ class << self
12
+ def schema_file_type(_format = nil)
13
+ "data_schema.rb"
14
+ end
15
+
16
+ def dump_filename(namespace, format = ActiveRecord::Base.schema_format)
17
+ filename = if namespace == "primary"
18
+ schema_file_type(format)
19
+ else
20
+ "#{namespace}_#{schema_file_type(format)}"
21
+ end
22
+
23
+ ENV["DATA_SCHEMA"] || File.join(schema_location, filename)
24
+ end
25
+
26
+ def schema_location
27
+ db_dir
28
+ end
29
+
30
+ def check_schema_file(filename)
31
+ unless File.exist?(filename)
32
+ message = +%{#{filename} doesn't exist yet. Run `rake data:migrate` to create it, then try again.}
33
+ Kernel.abort message
34
+ end
35
+ end
36
+ end
37
+
11
38
  # This overrides ActiveRecord::Tasks::DatabaseTasks
12
39
  def self.schema_file(_format = nil)
13
40
  File.join(db_dir, "data_schema.rb")
@@ -1,3 +1,3 @@
1
1
  module DataMigrate
2
- VERSION = "6.0.7".freeze
2
+ VERSION = "6.1.0".freeze
3
3
  end
@@ -51,9 +51,7 @@ describe DataMigrate::DataMigrator do
51
51
  end
52
52
 
53
53
  it do
54
- expect(
55
- ActiveRecord::Base.connection.table_exists?("data_migrations")
56
- ).to eq false
54
+ ActiveRecord::Migration.drop_table("data_migrations") rescue nil
57
55
  subject.assure_data_schema_table
58
56
  expect(
59
57
  ActiveRecord::Base.connection.table_exists?("data_migrations")
@@ -39,6 +39,7 @@ describe DataMigrate::DatabaseTasks do
39
39
  data_migrations_path
40
40
  }
41
41
  allow(DataMigrate::DataMigrator).to receive(:db_config) { db_config }
42
+ ActiveRecord::Base.configurations[:test] =db_config
42
43
  ActiveRecord::Base.establish_connection(db_config)
43
44
  end
44
45
 
@@ -58,7 +59,7 @@ describe DataMigrate::DatabaseTasks do
58
59
  end
59
60
 
60
61
  before do
61
- ActiveRecord::Base.establish_connection(db_config)
62
+ # ActiveRecord::Base.establish_connection(db_config)
62
63
  ActiveRecord::SchemaMigration.create_table
63
64
 
64
65
  allow(DataMigrate::SchemaMigration).to receive(:migrations_paths) {
@@ -86,6 +87,35 @@ describe DataMigrate::DatabaseTasks do
86
87
  end
87
88
  end
88
89
 
90
+ describe :load_schema_current do
91
+ before do
92
+ allow(DataMigrate::DataMigrator).to receive(:full_migrations_path).and_return(migration_path)
93
+ end
94
+
95
+ it "loads the current schema file" do
96
+ if Rails::VERSION::MAJOR < 6
97
+ skip("Not implemented for Rails lower than 6")
98
+ end
99
+ allow(subject).to receive(:schema_location).and_return("spec/db/data/schema/")
100
+
101
+ subject.load_schema_current
102
+ versions = DataMigrate::DataSchemaMigration.normalized_versions
103
+ expect(versions.count).to eq(2)
104
+ end
105
+
106
+ it "loads schema file that has not been update with latest data migrations" do
107
+ if Rails::VERSION::MAJOR < 6
108
+ skip("Not implemented for Rails lower than 6")
109
+ end
110
+
111
+ allow(subject).to receive(:schema_location).and_return("spec/db/data/partial_schema/")
112
+
113
+ subject.load_schema_current
114
+ versions = DataMigrate::DataSchemaMigration.normalized_versions
115
+ expect(versions.count).to eq(1)
116
+ end
117
+ end
118
+
89
119
  describe :forward do
90
120
 
91
121
  it "run forward default amount of times" do
@@ -0,0 +1,2 @@
1
+ # encoding: UTF-8
2
+ DataMigrate::Data.define(version: 20091231235959)
@@ -0,0 +1,2 @@
1
+ # encoding: UTF-8
2
+ DataMigrate::Data.define(version: 20171231235959)
data/spec/spec_helper.rb CHANGED
@@ -10,9 +10,16 @@ RSpec.configure do |config|
10
10
  mocks.verify_partial_doubles = true
11
11
  end
12
12
 
13
+ config.after(:each) do
14
+ DataMigrate.configure do |config|
15
+ config.data_migrations_path = @prev_data_migrations_path
16
+ end
17
+ end
18
+
13
19
  config.before(:each) do |example|
14
20
  if example.metadata[:no_override]
15
21
  else
22
+ @prev_data_migrations_path = DataMigrate.config.data_migrations_path
16
23
  if Rails::VERSION::MAJOR == 6
17
24
  DataMigrate.configure do |config|
18
25
  config.data_migrations_path = "spec/db/6.0"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: data_migrate
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.7
4
+ version: 6.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew J Vargo
@@ -197,7 +197,6 @@ files:
197
197
  - data_migrate.gemspec
198
198
  - gemfiles/rails_4.1.gemfile
199
199
  - gemfiles/rails_4.2.gemfile
200
- - gemfiles/rails_5.0.gemfile
201
200
  - gemfiles/rails_5.1.gemfile
202
201
  - gemfiles/rails_5.2.gemfile
203
202
  - gemfiles/rails_6.0.gemfile
@@ -250,6 +249,8 @@ files:
250
249
  - spec/db/data/20091231235959_some_name.rb
251
250
  - spec/db/data/20171231235959_super_update.rb
252
251
  - spec/db/data/20181128000207_excluded_file.rb.other_ext
252
+ - spec/db/data/partial_schema/data_schema.rb
253
+ - spec/db/data/schema/data_schema.rb
253
254
  - spec/db/migrate/4.2/20131111111111_late_migration.rb
254
255
  - spec/db/migrate/4.2/20202020202011_db_migration.rb
255
256
  - spec/db/migrate/5.0/20131111111111_late_migration.rb
@@ -1,7 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "http://rubygems.org"
4
-
5
- gem "rails", "5.0.7.2"
6
-
7
- gemspec path: "../"