data_migrate 6.2.0 → 6.3.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: 406033afc1679b99c3126cbbe9d033db56db817bf98a14a2f7926517e5f54587
4
- data.tar.gz: d33213b5b15ab486fce6e0d1e276d77be5a5dc69768bebb8d26400b7fe3523a8
3
+ metadata.gz: 7fa861e31bdaa49b654d9c40b11b8a8871f5f8d5c3241d17e0072c43ecf4c0c2
4
+ data.tar.gz: 9151be3e992b0271ded30d0bde83a0b57c2236e701762881b75f27a0663ba4a9
5
5
  SHA512:
6
- metadata.gz: eddd59586a06045a5120af7c1bb44b7f9da3099fbbdcda532f7975fb4356ba2c82a4b08bc460104df880c0030c8037cdbac0300a29ca8c789f457a3d8a7127d1
7
- data.tar.gz: 062cf7e95ae5dd4ebc7ce321fe040726badba05aa049b83cc5a2b46ac0e52d654cda011582052d928af3bcd90c95b4c1883da32522e49793b3196ffff0960e2c
6
+ metadata.gz: 3a4004c4a456a1b323add0ee2f7b3012c164763476f0be5957a202afc7388e22a1bc521272c6c359c0c0c0f14dc08b7528edc2ba19a908ac56a692ac1cc76832
7
+ data.tar.gz: b8cc321107a19adf0ccae807d755f5743de9c97f8e0fb86db631473d4f169e8bbdd6f5a97cd6a187eb895417051c73379b1ad4cba390dca620835e874e4fa1b3
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 6.3.0
4
+
5
+ Add `abort_if_pending_migrations` rake tasks [tomgia](https://github.com/tomgia)
6
+
3
7
  ## 6.2.0
4
8
 
5
9
  Add `rake data:schema:load` [timkrins](https://github.com/timkrins)
data/README.md CHANGED
@@ -82,26 +82,29 @@ You can generate a data migration as you would a schema migration:
82
82
  ### Rake Tasks
83
83
 
84
84
  $> rake -T data
85
- rake data:dump # Create a db/data_schema.rb file that stores the current data version
86
- rake data:forward # Pushes the schema to the next version (specify steps w/ STEP=n)
87
- rake data:migrate # Migrate data migrations (options: VERSION=x, VERBOSE=false)
88
- rake data:migrate:down # Runs the "down" for a given migration VERSION
89
- rake data:migrate:redo # Rollbacks the database one migration and re migrate up (options: STEP=x, VERSION=x)
90
- rake data:migrate:status # Display status of data migrations
91
- rake data:migrate:up # Runs the "up" for a given migration VERSION
92
- rake data:rollback # Rolls the schema back to the previous version (specify steps w/ STEP=n)
93
- rake data:schema:load # Load data_schema.rb file into the database without running the data migrations
94
- rake data:version # Retrieves the current schema version number for data migrations
95
- rake db:forward:with_data # Pushes the schema to the next version (specify steps w/ STEP=n)
96
- rake db:migrate:down:with_data # Runs the "down" for a given migration VERSION
97
- rake db:migrate:redo:with_data # Rollbacks the database one migration and re migrate up (options: STEP=x, VERSION=x)
98
- rake db:migrate:status:with_data # Display status of data and schema migrations
99
- rake db:migrate:up:with_data # Runs the "up" for a given migration VERSION
100
- rake db:migrate:with_data # Migrate the database data and schema (options: VERSION=x, VERBOSE=false)
101
- rake db:rollback:with_data # Rolls the schema back to the previous version (specify steps w/ STEP=n)
102
- rake db:schema:load:with_data # Load both schema.rb and data_schema.rb files into the database
103
- rake db:structure:load:with_data # Load both structure.sql and data_schema.rb files into the database
104
- 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
+
105
108
 
106
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.
107
110
 
@@ -69,7 +69,7 @@ module DataMigrate
69
69
  def self.pending_data_migrations
70
70
  data_migrations = DataMigrate::DataMigrator.migrations(data_migrations_path)
71
71
  sort_migrations(DataMigrate::DataMigrator.new(:up, data_migrations ).
72
- pending_migrations.map {|m| { version: m.version, kind: :data }})
72
+ pending_migrations.map {|m| { version: m.version, name: m.name, kind: :data }})
73
73
  end
74
74
 
75
75
  def self.pending_schema_migrations
@@ -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.2.0".freeze
2
+ VERSION = "6.3.0".freeze
3
3
  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
@@ -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
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.2.0
4
+ version: 6.3.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-12-09 00:00:00.000000000 Z
13
+ date: 2020-03-11 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails