data_migrate 8.4.2 → 8.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/gempush.yml +1 -1
- data/Changelog.md +4 -0
- data/README.md +1 -0
- data/lib/data_migrate/config.rb +10 -1
- data/lib/data_migrate/version.rb +1 -1
- data/lib/data_migrate.rb +3 -0
- data/lib/generators/data_migrate.rb +15 -2
- data/lib/generators/data_migration/data_migration_generator.rb +5 -1
- data/spec/data_migrate/config_spec.rb +42 -3
- data/spec/generators/data_migration/data_migration_generator_spec.rb +47 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c0ed214d2b242e9802276616e52abc79dc40081b413f6c38cdcbc5414d5897e9
|
4
|
+
data.tar.gz: f4045cba836825fa34a0da775d38999ea472f2fb8624537e8ffc216f01204e85
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c98becc1b27f1afc98a8e45c4c81ea35195a992f2ff7433d8891b542cc05063dde7ffd1655ba521e14e700e477acc23345b15a893e2a900c508fc0b72c69302c
|
7
|
+
data.tar.gz: 04560cc96cf6696b032b7a9d6892d70b772801b62910899ea2c360d7a17b98e8ab58bcd535e9a1fbdd40aa07c8633e92f5f52db8f9a6340c00788919eb5acf5b
|
data/Changelog.md
CHANGED
data/README.md
CHANGED
@@ -108,6 +108,7 @@ You can override this setting in `config/initializers/data_migrate.rb`
|
|
108
108
|
```ruby
|
109
109
|
DataMigrate.configure do |config|
|
110
110
|
config.data_migrations_path = 'db/awesomepath/'
|
111
|
+
config.data_template_path = Rails.root.join("lib", "awesomepath", "custom_data_migration.rb")
|
111
112
|
config.db_configuration = {
|
112
113
|
'host' => '127.0.0.1',
|
113
114
|
'database' => 'awesome_database',
|
data/lib/data_migrate/config.rb
CHANGED
@@ -12,12 +12,21 @@ module DataMigrate
|
|
12
12
|
end
|
13
13
|
|
14
14
|
class Config
|
15
|
-
attr_accessor :data_migrations_path, :db_configuration, :spec_name
|
15
|
+
attr_accessor :data_migrations_path, :data_template_path, :db_configuration, :spec_name
|
16
|
+
|
17
|
+
DEFAULT_DATA_TEMPLATE_PATH = "data_migration.rb"
|
16
18
|
|
17
19
|
def initialize
|
18
20
|
@data_migrations_path = "db/data/"
|
21
|
+
@data_template_path = DEFAULT_DATA_TEMPLATE_PATH
|
19
22
|
@db_configuration = nil
|
20
23
|
@spec_name = nil
|
21
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.exists?(path)
|
29
|
+
end
|
30
|
+
end
|
22
31
|
end
|
23
32
|
end
|
data/lib/data_migrate/version.rb
CHANGED
data/lib/data_migrate.rb
CHANGED
@@ -1,9 +1,22 @@
|
|
1
1
|
require 'rails/generators/named_base'
|
2
|
+
|
2
3
|
module DataMigrate
|
3
4
|
module Generators
|
4
5
|
class DataMigrationGenerator < Rails::Generators::NamedBase #:nodoc:
|
5
|
-
|
6
|
-
|
6
|
+
class << self
|
7
|
+
def source_root
|
8
|
+
build_data_migrate_source_root
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def build_data_migrate_source_root
|
14
|
+
if DataMigrate.config.data_template_path == DataMigrate::Config::DEFAULT_DATA_TEMPLATE_PATH
|
15
|
+
File.expand_path(File.join(File.dirname(__FILE__), generator_name, 'templates'))
|
16
|
+
else
|
17
|
+
File.expand_path(File.dirname(DataMigrate.config.data_template_path))
|
18
|
+
end
|
19
|
+
end
|
7
20
|
end
|
8
21
|
end
|
9
22
|
end
|
@@ -14,7 +14,7 @@ module DataMigrate
|
|
14
14
|
|
15
15
|
def create_data_migration
|
16
16
|
set_local_assigns!
|
17
|
-
migration_template
|
17
|
+
migration_template template_path, data_migrations_file_path
|
18
18
|
end
|
19
19
|
|
20
20
|
protected
|
@@ -26,6 +26,10 @@ module DataMigrate
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
+
def template_path
|
30
|
+
DataMigrate.config.data_template_path
|
31
|
+
end
|
32
|
+
|
29
33
|
def migration_base_class_name
|
30
34
|
"ActiveRecord::Migration[#{ActiveRecord::Migration.current_version}]"
|
31
35
|
end
|
@@ -1,12 +1,16 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe DataMigrate::Config do
|
4
|
-
|
5
4
|
it "sets default data_migrations_path path", :no_override do
|
6
5
|
expect(DataMigrate.config.data_migrations_path).to eq "db/data/"
|
7
6
|
end
|
8
7
|
|
8
|
+
it "sets default data_template_path path", :no_override do
|
9
|
+
expect(DataMigrate.config.data_template_path).to eq DataMigrate::Config::DEFAULT_DATA_TEMPLATE_PATH
|
10
|
+
end
|
11
|
+
|
9
12
|
describe "data migration path configured" do
|
13
|
+
subject { DataMigrate.config.data_migrations_path }
|
10
14
|
before do
|
11
15
|
@before = DataMigrate.config.data_migrations_path
|
12
16
|
DataMigrate.configure do |config|
|
@@ -20,8 +24,43 @@ describe DataMigrate::Config do
|
|
20
24
|
end
|
21
25
|
end
|
22
26
|
|
23
|
-
it do
|
24
|
-
|
27
|
+
it "equals the custom data migration path" do
|
28
|
+
is_expected.to eq "db/awesome/"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "data template path configured" do
|
33
|
+
subject { DataMigrate.config.data_template_path }
|
34
|
+
|
35
|
+
before do
|
36
|
+
@before = DataMigrate.config.data_template_path
|
37
|
+
DataMigrate.configure do |config|
|
38
|
+
config.data_template_path = data_template_path
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
let(:data_template_path) do
|
43
|
+
File.join(DataMigrate.root, "generators", "data_migration", "templates", "data_migration.rb")
|
44
|
+
end
|
45
|
+
|
46
|
+
after do
|
47
|
+
DataMigrate.configure do |config|
|
48
|
+
config.data_template_path = @before
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
it "equals the custom data template path" do
|
53
|
+
is_expected.to eq data_template_path
|
54
|
+
end
|
55
|
+
|
56
|
+
context "when path does not exist" do
|
57
|
+
subject { DataMigrate.config.data_template_path = invalid_path }
|
58
|
+
|
59
|
+
let(:invalid_path) { "lib/awesome/templates/data_migration.rb" }
|
60
|
+
|
61
|
+
it "checks that file exists on setting config var" do
|
62
|
+
expect { subject }.to raise_error { ArgumentError.new("File not found: '#{data_template_path}'") }
|
63
|
+
end
|
25
64
|
end
|
26
65
|
end
|
27
66
|
end
|
@@ -4,7 +4,8 @@ require 'rails/generators/migration'
|
|
4
4
|
require 'generators/data_migration/data_migration_generator'
|
5
5
|
|
6
6
|
describe DataMigrate::Generators::DataMigrationGenerator do
|
7
|
-
|
7
|
+
subject { DataMigrate::Generators::DataMigrationGenerator }
|
8
|
+
|
8
9
|
describe :next_migration_number do
|
9
10
|
it "next migration" do
|
10
11
|
Timecop.freeze("2016-12-03 22:15:26 -0800") do
|
@@ -19,14 +20,18 @@ describe DataMigrate::Generators::DataMigrationGenerator do
|
|
19
20
|
end
|
20
21
|
|
21
22
|
describe :migration_base_class_name do
|
22
|
-
|
23
|
+
subject { generator.send(:migration_base_class_name) }
|
24
|
+
|
25
|
+
let(:generator) { DataMigrate::Generators::DataMigrationGenerator.new(['my_migration']) }
|
26
|
+
|
23
27
|
it "returns the correct base class name" do
|
24
|
-
|
28
|
+
is_expected.to eq("ActiveRecord::Migration[#{ActiveRecord::Migration.current_version}]")
|
25
29
|
end
|
26
30
|
end
|
27
31
|
|
28
32
|
describe :create_data_migration do
|
29
|
-
|
33
|
+
subject { DataMigrate::Generators::DataMigrationGenerator.new(['my_migration']) }
|
34
|
+
|
30
35
|
let(:data_migrations_file_path) { 'abc/my_migration.rb' }
|
31
36
|
|
32
37
|
context 'when custom data migrations path has a trailing slash' do
|
@@ -35,7 +40,7 @@ describe DataMigrate::Generators::DataMigrationGenerator do
|
|
35
40
|
end
|
36
41
|
|
37
42
|
it 'returns correct file path' do
|
38
|
-
|
43
|
+
is_expected.to receive(:migration_template).with(
|
39
44
|
'data_migration.rb', data_migrations_file_path
|
40
45
|
)
|
41
46
|
|
@@ -49,7 +54,7 @@ describe DataMigrate::Generators::DataMigrationGenerator do
|
|
49
54
|
end
|
50
55
|
|
51
56
|
it 'returns correct file path' do
|
52
|
-
|
57
|
+
is_expected.to receive(:migration_template).with(
|
53
58
|
'data_migration.rb', data_migrations_file_path
|
54
59
|
)
|
55
60
|
|
@@ -57,4 +62,40 @@ describe DataMigrate::Generators::DataMigrationGenerator do
|
|
57
62
|
end
|
58
63
|
end
|
59
64
|
end
|
65
|
+
|
66
|
+
describe ".source_root" do
|
67
|
+
subject { described_class.source_root }
|
68
|
+
|
69
|
+
let(:default_source_root) do
|
70
|
+
File.expand_path(
|
71
|
+
File.dirname(File.join(DataMigrate.root, "generators", "data_migration", "templates", "data_migration.rb"))
|
72
|
+
)
|
73
|
+
end
|
74
|
+
|
75
|
+
it { is_expected.to eq default_source_root }
|
76
|
+
|
77
|
+
context "when DateMigrate.config.data_template_path is set" do
|
78
|
+
before do
|
79
|
+
@before = DataMigrate.config.data_template_path
|
80
|
+
DataMigrate.configure do |config|
|
81
|
+
config.data_template_path = data_template_path
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
let(:data_template_path) do
|
86
|
+
File.join(DataMigrate.root, "generators", "data_migration", "templates", "data_migration.rb")
|
87
|
+
end
|
88
|
+
let(:expected_source_root) { File.dirname(data_template_path) }
|
89
|
+
|
90
|
+
after do
|
91
|
+
DataMigrate.configure do |config|
|
92
|
+
config.data_template_path = @before
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
it "reads directory from config data template path" do
|
97
|
+
is_expected.to eq expected_source_root
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
60
101
|
end
|
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: 8.
|
4
|
+
version: 8.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:
|
13
|
+
date: 2023-01-02 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activerecord
|