data_migrate 6.5.0 → 6.6.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c9494a8b6cdea5a4f06a66f520d98e5845abfae2262c9c98c2cea1d493a89de5
4
- data.tar.gz: 28819c7dde00d8a96486e39b6555340881f65278e14fb07814805106d61b972c
3
+ metadata.gz: b5b08f7465fcf3fba0054816fa8b07b07216ba3831114b0a8d477e24caa7ba98
4
+ data.tar.gz: 556f3785c1b198cc36daac457809b95fe79754276b2ad4f1056ab1f7dfbd748d
5
5
  SHA512:
6
- metadata.gz: ab4a15ed15d0a54253644470bb800b24cc3465922b929e7e53b67b1ad868594ba40e40a57552438a93af544b308552b635972d00f5b1c4795022f328a0cbd3ee
7
- data.tar.gz: 0f8c135679143d45d34d0e49f1b86f0ff82876ffcd7d223160aa51d4f56ea99f6ad2dc18d13b38223355669334b89ae0f50fa2c42e858e04e69212ab75fe5e74
6
+ metadata.gz: 3df442c3c71eb087476c1c66a0ad1b0d74672b98a6ada2fb9349874f28a3bb3321ba3bc856278f63756d778e9ea7568771788d6e94a255f6f92a0d673f9782a8
7
+ data.tar.gz: f56faf7e4dd10ef8a1c9e0698190ee5a6cdf2217e1bbdc1a153bc64b3b43e32d3d0065b81fe2e15f9811fe6a5ba3ee40f722d0009da1e00586f7be97349210cc
data/.gitignore CHANGED
@@ -3,6 +3,8 @@
3
3
  *.lock
4
4
  gemfiles/.bundle
5
5
  spec/db/test.db
6
+ spec/db/other_test.db
7
+ spec/db/data_schema.rb
6
8
  .vscode/
7
9
  .DS_Store
8
10
  .idea/
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 6.6.0
4
+
5
+ Allow data dump connection to be configured [lewhit](https://github.com/lewhit)
6
+
3
7
  ## 6.4.0
4
8
 
5
9
  Add primary key to data_migrations table [aandis](https://github.com/aandis)
data/README.md CHANGED
@@ -122,6 +122,13 @@ You can override this setting in `config/initializers/data_migrate.rb`
122
122
  ```ruby
123
123
  DataMigrate.configure do |config|
124
124
  config.data_migrations_path = "db/awesomepath/"
125
+ config.db_configuration = {
126
+ 'host' => '127.0.0.1',
127
+ 'database' => 'awesome_database',
128
+ 'adapter' => 'mysql2',
129
+ 'username' => 'root',
130
+ 'password' => nil,
131
+ }
125
132
  end
126
133
 
127
134
  ```
@@ -12,10 +12,11 @@ module DataMigrate
12
12
  end
13
13
 
14
14
  class Config
15
- attr_accessor :data_migrations_path
15
+ attr_accessor :data_migrations_path, :db_configuration
16
16
 
17
17
  def initialize
18
18
  @data_migrations_path = "db/data/"
19
+ @db_configuration = nil
19
20
  end
20
21
  end
21
22
  end
@@ -6,6 +6,16 @@ module DataMigrate
6
6
  @migrations_paths ||= DataMigrate.config.data_migrations_path
7
7
  end
8
8
 
9
+ def dump
10
+ if ActiveRecord::Base.dump_schema_after_migration
11
+ filename = DataMigrate::DatabaseTasks.schema_file
12
+ ActiveRecord::Base.establish_connection(DataMigrate.config.db_configuration) if DataMigrate.config.db_configuration
13
+ File.open(filename, "w:utf-8") do |file|
14
+ DataMigrate::SchemaDumper.dump(ActiveRecord::Base.connection, file)
15
+ end
16
+ end
17
+ end
18
+
9
19
  def migrate
10
20
  DataMigrate::DataMigrator.assure_data_schema_table
11
21
  target_version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil
@@ -1,3 +1,3 @@
1
1
  module DataMigrate
2
- VERSION = "6.5.0".freeze
2
+ VERSION = "6.6.0".freeze
3
3
  end
@@ -3,6 +3,57 @@
3
3
  require "spec_helper"
4
4
 
5
5
  describe DataMigrate::Tasks::DataMigrateTasks do
6
+ describe :dump do
7
+ let(:db_config) do
8
+ {
9
+ adapter: "sqlite3",
10
+ database: "spec/db/other_test.db"
11
+ }
12
+ end
13
+
14
+ before do
15
+ allow(DataMigrate::DataMigrator).to receive(:db_config) { db_config }
16
+ allow(DataMigrate::DatabaseTasks).to receive(:db_dir).and_return("spec/db")
17
+ end
18
+
19
+ after do
20
+ ActiveRecord::Migration.drop_table("data_migrations")
21
+ end
22
+
23
+ context 'when not given a separate db config' do
24
+ it 'does not override the default connection' do
25
+ DataMigrate::Tasks::DataMigrateTasks.migrate
26
+ expect(ActiveRecord::Base).not_to receive(:establish_connection)
27
+ expect(DataMigrate::SchemaDumper).to receive(:dump)
28
+ DataMigrate::Tasks::DataMigrateTasks.dump
29
+ end
30
+ end
31
+
32
+ context 'when given ' do
33
+ let(:override_config) do
34
+ {
35
+ 'host' => '127.0.0.1',
36
+ 'database' => 'other_test',
37
+ 'adapter' => 'sqlite3',
38
+ 'username' => 'root',
39
+ 'password' => nil,
40
+ }
41
+ end
42
+
43
+ before do
44
+ DataMigrate.configure do |config|
45
+ config.db_configuration = override_config
46
+ end
47
+ end
48
+
49
+ it 'overrides the default connection' do
50
+ DataMigrate::Tasks::DataMigrateTasks.migrate
51
+ expect(ActiveRecord::Base).to receive(:establish_connection).with(override_config)
52
+ DataMigrate::Tasks::DataMigrateTasks.dump
53
+ end
54
+ end
55
+ end
56
+
6
57
  describe :migrate do
7
58
  let(:db_config) do
8
59
  {
@@ -10,12 +61,12 @@ describe DataMigrate::Tasks::DataMigrateTasks do
10
61
  database: "spec/db/test.db"
11
62
  }
12
63
  end
13
-
64
+
14
65
  before do
15
66
  allow(DataMigrate::DataMigrator).to receive(:db_config) { db_config }
16
67
  ActiveRecord::Base.establish_connection(db_config)
17
68
  end
18
-
69
+
19
70
  after do
20
71
  ActiveRecord::Migration.drop_table("data_migrations")
21
72
  end
@@ -54,9 +105,9 @@ describe DataMigrate::Tasks::DataMigrateTasks do
54
105
  }, {
55
106
  name: 'B',
56
107
  version: 2
57
- }]
108
+ }]
58
109
  end
59
-
110
+
60
111
  it "should abort with given message and print names and versions of pending migrations" do
61
112
  expect { subject }
62
113
  .to raise_error(SystemExit, message)
@@ -343,19 +343,14 @@ namespace :data do
343
343
 
344
344
  desc "Create a db/data_schema.rb file that stores the current data version"
345
345
  task dump: :environment do
346
- if ActiveRecord::Base.dump_schema_after_migration
347
- filename = DataMigrate::DatabaseTasks.schema_file
348
- File.open(filename, "w:utf-8") do |file|
349
- DataMigrate::SchemaDumper.dump(ActiveRecord::Base.connection, file)
350
- end
351
- end
346
+ DataMigrate::Tasks::DataMigrateTasks.dump
352
347
 
353
348
  # Allow this task to be called as many times as required. An example
354
349
  # is the migrate:redo task, which calls other two internally
355
350
  # that depend on this one.
356
351
  Rake::Task["data:dump"].reenable
357
352
  end
358
-
353
+
359
354
  namespace :schema do
360
355
  desc "Load data_schema.rb file into the database"
361
356
  task load: :environment do
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.5.0
4
+ version: 6.6.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: 2020-10-03 00:00:00.000000000 Z
13
+ date: 2020-12-15 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -288,7 +288,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
288
288
  - !ruby/object:Gem::Version
289
289
  version: '0'
290
290
  requirements: []
291
- rubygems_version: 3.1.2
291
+ rubygems_version: 3.1.4
292
292
  signing_key:
293
293
  specification_version: 4
294
294
  summary: Rake tasks to migrate data alongside schema changes.