data_migrate 6.0.7 → 6.5.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: c9494a8b6cdea5a4f06a66f520d98e5845abfae2262c9c98c2cea1d493a89de5
4
+ data.tar.gz: 28819c7dde00d8a96486e39b6555340881f65278e14fb07814805106d61b972c
5
5
  SHA512:
6
- metadata.gz: 1075302951b2cd717758d63bcec5e1ee5a70d2871ed81d3b6a3312b6978fb42087eb896b104afeff9add287f3d932fb2856a31b407e352fc4349d454ebdb7605
7
- data.tar.gz: f2cec3fb11588a0b1ab70c2958c36a75a5f37837189aa26b20d6eaacf3a9fca84f3bf18ff8bd0eda6c411b91a1d2050e7a76fb794ff9dc40dcbb71007f2202ca
6
+ metadata.gz: ab4a15ed15d0a54253644470bb800b24cc3465922b929e7e53b67b1ad868594ba40e40a57552438a93af544b308552b635972d00f5b1c4795022f328a0cbd3ee
7
+ data.tar.gz: 0f8c135679143d45d34d0e49f1b86f0ff82876ffcd7d223160aa51d4f56ea99f6ad2dc18d13b38223355669334b89ae0f50fa2c42e858e04e69212ab75fe5e74
@@ -1,9 +1,6 @@
1
1
  name: Ruby Gem
2
2
 
3
3
  on:
4
- pull_request:
5
- branches:
6
- - master
7
4
  push:
8
5
  branches:
9
6
  - master
@@ -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
@@ -1,5 +1,26 @@
1
1
  # Changelog
2
2
 
3
+ ## 6.4.0
4
+
5
+ Add primary key to data_migrations table [aandis](https://github.com/aandis)
6
+
7
+ ## 6.3.0
8
+
9
+ Add `abort_if_pending_migrations` rake tasks [tomgia](https://github.com/tomgia)
10
+
11
+ ## 6.2.0
12
+
13
+ Add `rake data:schema:load` [timkrins](https://github.com/timkrins)
14
+
15
+ ## 6.1.0
16
+
17
+ Fixing `rake db:schema:load:with_data` for Rails 6
18
+
19
+ Note:
20
+
21
+ Rails 5.0 is no longer maintained. The gem will still work but it is not being
22
+ actively tested.
23
+
3
24
  ## 6.0.5
4
25
 
5
26
  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
 
@@ -115,25 +82,29 @@ You can generate a data migration as you would a schema migration:
115
82
  ### Rake Tasks
116
83
 
117
84
  $> rake -T data
118
- rake data:dump # Create a db/data_schema.rb file that stores the current data version
119
- rake data:forward # Pushes the schema to the next version (specify steps w/ STEP=n)
120
- rake data:migrate # Migrate data migrations (options: VERSION=x, VERBOSE=false)
121
- rake data:migrate:down # Runs the "down" for a given migration VERSION
122
- rake data:migrate:redo # Rollbacks the database one migration and re migrate up (options: STEP=x, VERSION=x)
123
- rake data:migrate:status # Display status of data migrations
124
- rake data:migrate:up # Runs the "up" for a given migration VERSION
125
- rake data:rollback # Rolls the schema back to the previous version (specify steps w/ STEP=n)
126
- rake data:version # Retrieves the current schema version number for data migrations
127
- rake db:forward:with_data # Pushes the schema to the next version (specify steps w/ STEP=n)
128
- rake db:migrate:down:with_data # Runs the "down" for a given migration VERSION
129
- rake db:migrate:redo:with_data # Rollbacks the database one migration and re migrate up (options: STEP=x, VERSION=x)
130
- rake db:migrate:status:with_data # Display status of data and schema migrations
131
- rake db:migrate:up:with_data # Runs the "up" for a given migration VERSION
132
- rake db:migrate:with_data # Migrate the database data and schema (options: VERSION=x, VERBOSE=false)
133
- rake db:rollback:with_data # Rolls the schema back to the previous version (specify steps w/ STEP=n)
134
- rake db:schema:load:with_data # Load both schema.rb and data_schema.rb files into the database
135
- rake db:structure:load:with_data # Load both structure.sql and data_schema.rb files into the database
136
- rake db:version:with_data # Retrieves the current schema version numbers for data and schema migrations
85
+ rake data:abort_if_pending_migrations # Raises an error if there are pending data migrations
86
+ rake data:dump # Create a db/data_schema.rb file that stores the current data version
87
+ rake data:forward # Pushes the schema to the next version (specify steps w/ STEP=n)
88
+ rake data:migrate # Migrate data migrations (options: VERSION=x, VERBOSE=false)
89
+ rake data:migrate:down # Runs the "down" for a given migration VERSION
90
+ rake data:migrate:redo # Rollbacks the database one migration and re migrate up (options: STEP=x, VERSION=x)
91
+ rake data:migrate:status # Display status of data migrations
92
+ rake data:migrate:up # Runs the "up" for a given migration VERSION
93
+ rake data:rollback # Rolls the schema back to the previous version (specify steps w/ STEP=n)
94
+ rake data:schema:load # Load data_schema.rb file into the database without running the data migrations
95
+ rake data:version # Retrieves the current schema version number for data migrations
96
+ rake db:abort_if_pending_migrations:with_data # Raises an error if there are pending migrations or data migrations
97
+ rake db:forward:with_data # Pushes the schema to the next version (specify steps w/ STEP=n)
98
+ rake db:migrate:down:with_data # Runs the "down" for a given migration VERSION
99
+ rake db:migrate:redo:with_data # Rollbacks the database one migration and re migrate up (options: STEP=x, VERSION=x)
100
+ rake db:migrate:status:with_data # Display status of data and schema migrations
101
+ rake db:migrate:up:with_data # Runs the "up" for a given migration VERSION
102
+ rake db:migrate:with_data # Migrate the database data and schema (options: VERSION=x, VERBOSE=false)
103
+ rake db:rollback:with_data # Rolls the schema back to the previous version (specify steps w/ STEP=n)
104
+ rake db:schema:load:with_data # Load both schema.rb and data_schema.rb file into the database
105
+ rake db:structure:load:with_data # Load both structure.sql and data_schema.rb file into the database
106
+ rake db:version:with_data # Retrieves the current schema version numbers for data and schema migrations
107
+
137
108
 
138
109
  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.
139
110
 
@@ -175,14 +146,15 @@ Run tests for a specific version of Rails
175
146
 
176
147
  ```
177
148
  bundle exec appraisal install
178
- bundle exec appraisal rails-5.0 rspec
149
+ bundle exec appraisal rails-5.1 rspec
179
150
  bundle exec appraisal rails-5.2 rspec
151
+ bundle exec appraisal rails-6.0 rspec
180
152
  ```
181
153
 
182
154
  ## Thanks
183
155
 
184
156
  [Andrew J Vargo](http://github.com/ajvargo) Andrew was the original creator and maintainer of this project!
185
157
 
186
- [Jeremy Durham](http://jeremydurham.com/) for fleshing out the idea with me, and providing guidance.
158
+ [Jeremy Durham](http://jeremydurham.com/) for fleshing out the idea and providing guidance.
187
159
 
188
160
  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: "../"
@@ -76,17 +76,8 @@ module DataMigrate
76
76
 
77
77
  def create_table(sm_table)
78
78
  ActiveRecord::Base.connection.create_table(sm_table, id: false) do |schema_migrations_table|
79
- schema_migrations_table.column :version, :string, null: false
79
+ schema_migrations_table.string :version, primary_key: true
80
80
  end
81
-
82
- suffix = ActiveRecord::Base.table_name_suffix
83
- prefix = ActiveRecord::Base.table_name_prefix
84
- index_name = "#{prefix}unique_data_migrations#{suffix}"
85
-
86
- options = {unique: true, name: index_name}
87
- options[:length] = 191 if ActiveRecord::Base.connection_config[:adapter] == "mysql2"
88
-
89
- ActiveRecord::Base.connection.add_index sm_table, :version, options
90
81
  end
91
82
 
92
83
  def table_exists?(connection, table_name)
@@ -6,8 +6,8 @@ module DataMigrate
6
6
  ActiveRecord::Base.table_name_prefix + 'data_migrations' + ActiveRecord::Base.table_name_suffix
7
7
  end
8
8
 
9
- def index_name
10
- "#{table_name_prefix}unique_data_migrations#{table_name_suffix}"
9
+ def primary_key
10
+ "version"
11
11
  end
12
12
  end
13
13
  end
@@ -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")
@@ -42,7 +69,7 @@ module DataMigrate
42
69
  def self.pending_data_migrations
43
70
  data_migrations = DataMigrate::DataMigrator.migrations(data_migrations_path)
44
71
  sort_migrations(DataMigrate::DataMigrator.new(:up, data_migrations ).
45
- pending_migrations.map {|m| { version: m.version, kind: :data }})
72
+ pending_migrations.map {|m| { version: m.version, name: m.name, kind: :data }})
46
73
  end
47
74
 
48
75
  def self.pending_schema_migrations
@@ -14,8 +14,8 @@ module DataMigrate
14
14
  ActiveRecord::Base.table_name_prefix + "data_migrations" + ActiveRecord::Base.table_name_suffix
15
15
  end
16
16
 
17
- def index_name
18
- "#{table_name_prefix}unique_data_migrations#{table_name_suffix}"
17
+ def primary_key
18
+ "version"
19
19
  end
20
20
  end
21
21
 
@@ -14,8 +14,8 @@ module DataMigrate
14
14
  ActiveRecord::Base.table_name_prefix + 'data_migrations' + ActiveRecord::Base.table_name_suffix
15
15
  end
16
16
 
17
- def index_name
18
- "#{table_name_prefix}unique_data_migrations#{table_name_suffix}"
17
+ def primary_key
18
+ "version"
19
19
  end
20
20
  end
21
21
 
@@ -7,7 +7,7 @@ module DataMigrate
7
7
  sort_migrations(
8
8
  ActiveRecord::Migrator.new(:up, all_migrations).
9
9
  pending_migrations.
10
- map {|m| { version: m.version, kind: :schema }}
10
+ map {|m| { version: m.version, name: m.name, kind: :schema }}
11
11
  )
12
12
  end
13
13
 
@@ -7,7 +7,7 @@ module DataMigrate
7
7
  sort_migrations(
8
8
  ActiveRecord::Migrator.new(:up, all_migrations).
9
9
  pending_migrations.
10
- map {|m| { version: m.version, kind: :schema }}
10
+ map {|m| { version: m.version, name: m.name, kind: :schema }}
11
11
  )
12
12
  end
13
13
 
@@ -16,6 +16,16 @@ module DataMigrate
16
16
  DataMigrate::DataMigrator.migrate(migrations_paths, ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
17
17
  end
18
18
  end
19
+
20
+ def abort_if_pending_migrations(migrations, message)
21
+ if migrations.any?
22
+ puts "You have #{migrations.size} pending #{migrations.size > 1 ? 'migrations:' : 'migration:'}"
23
+ migrations.each do |pending_migration|
24
+ puts " %4d %s" % [pending_migration[:version], pending_migration[:name]]
25
+ end
26
+ abort message
27
+ end
28
+ end
19
29
  end
20
30
  end
21
31
  end
@@ -1,3 +1,3 @@
1
1
  module DataMigrate
2
- VERSION = "6.0.7".freeze
2
+ VERSION = "6.5.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")
@@ -9,8 +9,8 @@ describe DataMigrate::DataSchemaMigration do
9
9
  end
10
10
 
11
11
  describe :index_name do
12
- it "returns correct index name" do
13
- expect(subject.index_name).to eq("unique_data_migrations")
12
+ it "returns correct primary key name" do
13
+ expect(subject.primary_key).to eq("version")
14
14
  end
15
15
  end
16
16
  end
@@ -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
@@ -14,6 +14,6 @@ describe subject do
14
14
  it "uses correct index name" do
15
15
  expect(subject).to receive(:table_name_prefix) { "" }
16
16
  expect(subject).to receive(:table_name_suffix) { "" }
17
- expect(subject.index_name).to eq("unique_data_migrations")
17
+ expect(subject.primary_key).to eq("version")
18
18
  end
19
19
  end
@@ -3,23 +3,23 @@
3
3
  require "spec_helper"
4
4
 
5
5
  describe DataMigrate::Tasks::DataMigrateTasks do
6
- let(:db_config) do
7
- {
8
- adapter: "sqlite3",
9
- database: "spec/db/test.db"
10
- }
11
- end
12
-
13
- before do
14
- allow(DataMigrate::DataMigrator).to receive(:db_config) { db_config }
15
- ActiveRecord::Base.establish_connection(db_config)
16
- end
17
-
18
- after do
19
- ActiveRecord::Migration.drop_table("data_migrations")
20
- end
21
-
22
6
  describe :migrate do
7
+ let(:db_config) do
8
+ {
9
+ adapter: "sqlite3",
10
+ database: "spec/db/test.db"
11
+ }
12
+ end
13
+
14
+ before do
15
+ allow(DataMigrate::DataMigrator).to receive(:db_config) { db_config }
16
+ ActiveRecord::Base.establish_connection(db_config)
17
+ end
18
+
19
+ after do
20
+ ActiveRecord::Migration.drop_table("data_migrations")
21
+ end
22
+
23
23
  it do
24
24
  expect {
25
25
  DataMigrate::Tasks::DataMigrateTasks.migrate
@@ -32,4 +32,36 @@ describe DataMigrate::Tasks::DataMigrateTasks do
32
32
  }.to output(/20171231235959 SuperUpdate: migrating/).to_stdout
33
33
  end
34
34
  end
35
+
36
+ describe :abort_if_pending_migrations do
37
+ subject { DataMigrate::Tasks::DataMigrateTasks.abort_if_pending_migrations(migrations, message) }
38
+
39
+ let(:message) { "ABORT_MESSAGE" }
40
+
41
+ context "when there are no pending migrations" do
42
+ let(:migrations) { [] }
43
+
44
+ it "shouldn't do anything" do
45
+ expect { subject }.to_not raise_error
46
+ end
47
+ end
48
+
49
+ context "when there are pending migrations" do
50
+ let(:migrations) do
51
+ [{
52
+ name: "A",
53
+ version: 1
54
+ }, {
55
+ name: 'B',
56
+ version: 2
57
+ }]
58
+ end
59
+
60
+ it "should abort with given message and print names and versions of pending migrations" do
61
+ expect { subject }
62
+ .to raise_error(SystemExit, message)
63
+ .and output("You have 2 pending migrations:\n 1 A\n 2 B\n").to_stdout
64
+ end
65
+ end
66
+ end
35
67
  end
@@ -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)
@@ -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"
@@ -223,6 +223,14 @@ namespace :db do
223
223
  end
224
224
  end
225
225
 
226
+ namespace :abort_if_pending_migrations do
227
+ desc "Raises an error if there are pending migrations or data migrations"
228
+ task with_data: :environment do
229
+ message = %{Run `rake db:migrate:with_data` to update your database then try again.}
230
+ DataMigrate::Tasks::DataMigrateTasks.abort_if_pending_migrations(pending_migrations, message)
231
+ end
232
+ end
233
+
226
234
  namespace :schema do
227
235
  namespace :load do
228
236
  desc "Load both schema.rb and data_schema.rb file into the database"
@@ -327,6 +335,12 @@ namespace :data do
327
335
  puts "Current data version: #{DataMigrate::DataMigrator.current_version}"
328
336
  end
329
337
 
338
+ desc "Raises an error if there are pending data migrations"
339
+ task abort_if_pending_migrations: :environment do
340
+ message = %{Run `rake data:migrate` to update your database then try again.}
341
+ DataMigrate::Tasks::DataMigrateTasks.abort_if_pending_migrations(pending_data_migrations, message)
342
+ end
343
+
330
344
  desc "Create a db/data_schema.rb file that stores the current data version"
331
345
  task dump: :environment do
332
346
  if ActiveRecord::Base.dump_schema_after_migration
@@ -341,6 +355,16 @@ namespace :data do
341
355
  # that depend on this one.
342
356
  Rake::Task["data:dump"].reenable
343
357
  end
358
+
359
+ namespace :schema do
360
+ desc "Load data_schema.rb file into the database"
361
+ task load: :environment do
362
+ DataMigrate::DatabaseTasks.load_schema_current(
363
+ :ruby,
364
+ ENV["DATA_SCHEMA"]
365
+ )
366
+ end
367
+ end
344
368
  end
345
369
 
346
370
  def pending_migrations
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.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew J Vargo
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2019-11-21 00:00:00.000000000 Z
13
+ date: 2020-10-03 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -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
@@ -287,7 +288,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
287
288
  - !ruby/object:Gem::Version
288
289
  version: '0'
289
290
  requirements: []
290
- rubygems_version: 3.0.3
291
+ rubygems_version: 3.1.2
291
292
  signing_key:
292
293
  specification_version: 4
293
294
  summary: Rake tasks to migrate data alongside schema changes.
@@ -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: "../"