data_migrater 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +32 -0
- data/lib/data_migrater.rb +3 -0
- data/lib/data_migrater/logger.rb +49 -0
- data/lib/data_migrater/version.rb +1 -1
- data/lib/generators/data_migrater/install_generator.rb +1 -3
- data/lib/generators/data_migrater/templates/db/data_migrate/data_migrate.rb.erb +7 -0
- data/spec/csv/data_csv_spec.rb +31 -0
- data/spec/logger/data_logger_spec.rb +63 -0
- data/spec/spec_helper.rb +2 -13
- data/spec/support/common.rb +7 -0
- data/spec/support/database_cleaner.rb +5 -0
- data/spec/support/methods.rb +3 -0
- data/spec/support/migrate.rb +5 -0
- metadata +60 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a13040b011706340281f05ccfd9bec1d0f1dccbd
|
4
|
+
data.tar.gz: d125de74e4823997d445badbb4b1fc9e35c10265
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 62f37e23c30eacde7c410c3d27f5f82d73a9fadd6ac52d2ea526db44c852b3a8faaf48c99b85ff43c4b81829d6f2c20bc1dcbf0d688716dca4156e6a0a6a49f7
|
7
|
+
data.tar.gz: 429b22415c18dff3dfd8991c2894d662db8a8aae6d1919312e8e7b3db134a090e790201e1f661efac9e8ac9006a7e9904cb1b1d4722b1513683b8b0eb86eb1be
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -30,6 +30,38 @@ rails g data_migrater:create name
|
|
30
30
|
Check your `db/data_migrate` folder, the data migration will be there.
|
31
31
|
Next time your application run, all pending data migration will be execute.
|
32
32
|
|
33
|
+
## Custom Logger
|
34
|
+
|
35
|
+
You can send your log to a file including the module `DataMigrater::Logger`.
|
36
|
+
|
37
|
+
```
|
38
|
+
class MyDataMigration
|
39
|
+
include DataMigrater::Logger
|
40
|
+
|
41
|
+
def execute
|
42
|
+
logger.info "going to log/my_data_migration.log"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
```
|
46
|
+
|
47
|
+
By default, the class name is used and the file goes to `log` folder. You can change it:
|
48
|
+
|
49
|
+
```
|
50
|
+
class MyDataMigration
|
51
|
+
include DataMigrater::Logger
|
52
|
+
|
53
|
+
data_logger path: "db/data_migrate/log/global.log"
|
54
|
+
|
55
|
+
def execute
|
56
|
+
logger.info "going to db/data_migrate/log/global.log"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
```
|
60
|
+
|
61
|
+
#### Options
|
62
|
+
|
63
|
+
`path`: Where the log will be written.
|
64
|
+
|
33
65
|
## Test
|
34
66
|
|
35
67
|
Before send pull request, check if specs is passing.
|
data/lib/data_migrater.rb
CHANGED
@@ -2,7 +2,10 @@ module DataMigrater
|
|
2
2
|
end
|
3
3
|
|
4
4
|
require 'data_migration'
|
5
|
+
|
5
6
|
require 'data_migrater/collection'
|
7
|
+
# require 'data_migrater/csv'
|
8
|
+
require 'data_migrater/logger'
|
6
9
|
require 'data_migrater/migration'
|
7
10
|
require 'data_migrater/migrator'
|
8
11
|
require 'data_migrater/version'
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module DataMigrater
|
2
|
+
module Logger
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
def logger
|
7
|
+
return @logger if @logger
|
8
|
+
|
9
|
+
@logger = ::Logger.new(path)
|
10
|
+
|
11
|
+
@logger.formatter = formatter
|
12
|
+
|
13
|
+
@logger
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def default_path
|
19
|
+
"log/#{self.class.name.underscore}.log"
|
20
|
+
end
|
21
|
+
|
22
|
+
def formatter
|
23
|
+
-> (severity, datetime, _progname, message) do
|
24
|
+
"[#{datetime}] #{severity} #{self.class.name}: #{message}\n"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def options
|
29
|
+
self.class.options
|
30
|
+
end
|
31
|
+
|
32
|
+
def path
|
33
|
+
return default_path unless options
|
34
|
+
|
35
|
+
options.fetch :path, default_path
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class_methods do
|
40
|
+
def data_logger(options = {})
|
41
|
+
@options = options
|
42
|
+
end
|
43
|
+
|
44
|
+
def options
|
45
|
+
@options
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
class Dummy
|
4
|
+
include DataMigrater::CSV
|
5
|
+
|
6
|
+
data_logger path: "dummy.log"
|
7
|
+
|
8
|
+
def log
|
9
|
+
logger.info "done!"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
RSpec.describe Dummy, "#data_logger" do
|
14
|
+
subject { Dummy.new }
|
15
|
+
|
16
|
+
context "with a given :path" do
|
17
|
+
it "caches the options" do
|
18
|
+
expect(described_class.options).to eq(path: "dummy.log")
|
19
|
+
end
|
20
|
+
|
21
|
+
it "has the right format" do
|
22
|
+
subject.log
|
23
|
+
|
24
|
+
expect(read).to match /\[\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} -\d{4}\] INFO Dummy: done!\n/
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def read
|
29
|
+
File.readlines(described_class.options[:path]).last
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe "#data_logger" do
|
4
|
+
context "with :path" do
|
5
|
+
before do
|
6
|
+
stub_const "Dummy", Class.new
|
7
|
+
|
8
|
+
Dummy.class_eval { include DataMigrater::Logger }
|
9
|
+
Dummy.class_eval { data_logger path: "custom.log" }
|
10
|
+
end
|
11
|
+
|
12
|
+
after :suite do
|
13
|
+
delete :dummy
|
14
|
+
end
|
15
|
+
|
16
|
+
subject { Dummy.new }
|
17
|
+
|
18
|
+
it "logs on the given path file with right content" do
|
19
|
+
subject.logger.info "done!"
|
20
|
+
|
21
|
+
result = /\[\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} -\d{4}\] INFO Dummy: done!\n/
|
22
|
+
|
23
|
+
expect(File.readlines("custom.log").last).to match result
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context "with no :path" do
|
28
|
+
before do
|
29
|
+
stub_const "Dummy", Class.new
|
30
|
+
|
31
|
+
Dummy.class_eval { include DataMigrater::Logger }
|
32
|
+
Dummy.class_eval { data_logger }
|
33
|
+
end
|
34
|
+
|
35
|
+
subject { Dummy.new }
|
36
|
+
|
37
|
+
it "logs on log folder with class name with right content" do
|
38
|
+
subject.logger.info "done!"
|
39
|
+
|
40
|
+
result = /\[\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} -\d{4}\] INFO Dummy: done!\n/
|
41
|
+
|
42
|
+
expect(File.readlines("log/dummy.log").last).to match result
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context "with no :data_logger" do
|
47
|
+
before do
|
48
|
+
stub_const "Dummy", Class.new
|
49
|
+
|
50
|
+
Dummy.class_eval { include DataMigrater::Logger }
|
51
|
+
end
|
52
|
+
|
53
|
+
subject { Dummy.new }
|
54
|
+
|
55
|
+
it "logs on log folder with class name with right content" do
|
56
|
+
subject.logger.info "done!"
|
57
|
+
|
58
|
+
result = /\[\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} -\d{4}\] INFO Dummy: done!\n/
|
59
|
+
|
60
|
+
expect(File.readlines("log/dummy.log").last).to match result
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,20 +1,9 @@
|
|
1
1
|
ENV['RAILS_ENV'] ||= 'test'
|
2
2
|
|
3
|
-
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
4
|
-
|
5
3
|
require 'active_record/railtie'
|
6
4
|
require 'data_migrater'
|
5
|
+
require 'pry-byebug'
|
7
6
|
|
8
7
|
ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ':memory:'
|
9
8
|
|
10
|
-
|
11
|
-
create_table :data_migrations do |t|
|
12
|
-
t.string :version, null: false
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
RSpec.configure do |config|
|
17
|
-
config.before do
|
18
|
-
DataMigration.destroy_all
|
19
|
-
end
|
20
|
-
end
|
9
|
+
Dir[File.expand_path('support/**/*.rb', __dir__)].each { |file| require file }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: data_migrater
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GetNinjas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-03-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -53,7 +53,7 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name: rspec
|
56
|
+
name: guard-rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
@@ -67,7 +67,35 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: pry-byebug
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec-rails
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec
|
71
99
|
requirement: !ruby/object:Gem::Requirement
|
72
100
|
requirements:
|
73
101
|
- - ">="
|
@@ -94,6 +122,20 @@ dependencies:
|
|
94
122
|
- - ">="
|
95
123
|
- !ruby/object:Gem::Version
|
96
124
|
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rubocop
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
97
139
|
- !ruby/object:Gem::Dependency
|
98
140
|
name: sqlite3
|
99
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -119,6 +161,7 @@ files:
|
|
119
161
|
- README.md
|
120
162
|
- lib/data_migrater.rb
|
121
163
|
- lib/data_migrater/collection.rb
|
164
|
+
- lib/data_migrater/logger.rb
|
122
165
|
- lib/data_migrater/migration.rb
|
123
166
|
- lib/data_migrater/migrator.rb
|
124
167
|
- lib/data_migrater/version.rb
|
@@ -129,10 +172,16 @@ files:
|
|
129
172
|
- lib/generators/data_migrater/templates/db/data_migrate/data_migrate.rb.erb
|
130
173
|
- lib/generators/data_migrater/templates/db/migrate/create_data_migrations.rb
|
131
174
|
- spec/collection_spec.rb
|
175
|
+
- spec/csv/data_csv_spec.rb
|
132
176
|
- spec/data_migration_spec.rb
|
177
|
+
- spec/logger/data_logger_spec.rb
|
133
178
|
- spec/migrater_spec.rb
|
134
179
|
- spec/migration_spec.rb
|
135
180
|
- spec/spec_helper.rb
|
181
|
+
- spec/support/common.rb
|
182
|
+
- spec/support/database_cleaner.rb
|
183
|
+
- spec/support/methods.rb
|
184
|
+
- spec/support/migrate.rb
|
136
185
|
homepage: https://github.com/getninjas/data_migrater
|
137
186
|
licenses:
|
138
187
|
- MIT
|
@@ -153,13 +202,19 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
153
202
|
version: '0'
|
154
203
|
requirements: []
|
155
204
|
rubyforge_project:
|
156
|
-
rubygems_version: 2.
|
205
|
+
rubygems_version: 2.6.8
|
157
206
|
signing_key:
|
158
207
|
specification_version: 4
|
159
208
|
summary: A Data Migrator gem
|
160
209
|
test_files:
|
161
210
|
- spec/collection_spec.rb
|
211
|
+
- spec/csv/data_csv_spec.rb
|
162
212
|
- spec/data_migration_spec.rb
|
213
|
+
- spec/logger/data_logger_spec.rb
|
163
214
|
- spec/migrater_spec.rb
|
164
215
|
- spec/migration_spec.rb
|
165
216
|
- spec/spec_helper.rb
|
217
|
+
- spec/support/common.rb
|
218
|
+
- spec/support/database_cleaner.rb
|
219
|
+
- spec/support/methods.rb
|
220
|
+
- spec/support/migrate.rb
|