seed_dump 0.4.2 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +9 -0
- data/README.rdoc +4 -0
- data/VERSION +1 -1
- data/lib/seed_dump/perform.rb +14 -3
- data/seed_dump.gemspec +5 -3
- data/test/models/abstract_sample.rb +3 -0
- data/test/models/child_sample.rb +4 -0
- data/test/seed_dump_test.rb +12 -2
- data/test/test_helper.rb +7 -1
- metadata +5 -3
data/CHANGELOG.rdoc
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
== Seed Dump
|
2
2
|
|
3
|
+
== 0.4.3 / 2013-05-11
|
4
|
+
|
5
|
+
* Handle abstract_class setting in ActiveRecord [craigjackson]
|
6
|
+
* added MAX option [OlegPasko]
|
7
|
+
|
8
|
+
== 0.4.2 / 2012-11-02
|
9
|
+
|
10
|
+
* Fix for bug resulting from top-level class redefinition [rroblak]
|
11
|
+
|
3
12
|
== 0.4.1 / 2012-08-01
|
4
13
|
|
5
14
|
* include TIMESTAMPS by default
|
data/README.rdoc
CHANGED
@@ -68,6 +68,10 @@ FILE:
|
|
68
68
|
|
69
69
|
LIMIT:
|
70
70
|
Dump no more then this amount of data, default: no limit
|
71
|
+
|
72
|
+
MAX:
|
73
|
+
Split one create action per model to several create actions with MAX elements in each, default: no limit
|
74
|
+
It usefull for large data dumping to reduce memory usage
|
71
75
|
|
72
76
|
MODEL(S):
|
73
77
|
A model name or a comma seperated list of models, default: all models
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.3
|
data/lib/seed_dump/perform.rb
CHANGED
@@ -27,6 +27,7 @@ module SeedDump
|
|
27
27
|
@opts['models'] = env['MODELS'] || (env['MODEL'] ? env['MODEL'] : "")
|
28
28
|
@opts['file'] = env['FILE'] || "#{Rails.root}/db/seeds.rb"
|
29
29
|
@opts['append'] = (env['APPEND'].true? && File.exists?(@opts['file']) )
|
30
|
+
@opts['max'] = env['MAX'] && env['MAX'].to_i > 0 ? env['MAX'].to_i : nil
|
30
31
|
@ar_options = env['LIMIT'].to_i > 0 ? { :limit => env['LIMIT'].to_i } : {}
|
31
32
|
@indent = " " * (env['INDENT'].nil? ? 2 : env['INDENT'].to_i)
|
32
33
|
@opts['models'] = @opts['models'].split(',').collect {|x| x.underscore.singularize.camelize }
|
@@ -106,15 +107,25 @@ module SeedDump
|
|
106
107
|
if @opts['without_protection']
|
107
108
|
options = ', :without_protection => true '
|
108
109
|
end
|
109
|
-
|
110
|
-
|
110
|
+
|
111
|
+
if @opts['max']
|
112
|
+
splited_rows = rows.each_slice(@opts['max']).to_a
|
113
|
+
maxsarr = []
|
114
|
+
splited_rows.each do |sr|
|
115
|
+
maxsarr << "\n#{model}.create([\n" << sr.join(",\n") << "\n]#{options})\n"
|
116
|
+
end
|
117
|
+
maxsarr.join('')
|
118
|
+
else
|
119
|
+
"\n#{model}.create([\n" << rows.join(",\n") << "\n]#{options})\n"
|
120
|
+
end
|
121
|
+
|
111
122
|
end
|
112
123
|
|
113
124
|
def dumpModels
|
114
125
|
@seed_rb = ""
|
115
126
|
@models.sort.each do |model|
|
116
127
|
m = model.constantize
|
117
|
-
if m.ancestors.include?(ActiveRecord::Base)
|
128
|
+
if m.ancestors.include?(ActiveRecord::Base) && !m.abstract_class
|
118
129
|
puts "Adding #{model} seeds." if @opts['verbose']
|
119
130
|
|
120
131
|
if @opts['skip_callbacks']
|
data/seed_dump.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "seed_dump"
|
8
|
-
s.version = "0.4.
|
8
|
+
s.version = "0.4.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Rob Halff"]
|
12
|
-
s.date = "
|
12
|
+
s.date = "2013-05-11"
|
13
13
|
s.description = "Dump (parts) of your database to db/seeds.rb to get a headstart creating a meaningful seeds.rb file"
|
14
14
|
s.email = "rob.halff@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -29,6 +29,8 @@ Gem::Specification.new do |s|
|
|
29
29
|
"lib/true.rb",
|
30
30
|
"seed_dump.gemspec",
|
31
31
|
"test/fixtures/samples.yml",
|
32
|
+
"test/models/abstract_sample.rb",
|
33
|
+
"test/models/child_sample.rb",
|
32
34
|
"test/models/nested/sample.rb",
|
33
35
|
"test/models/sample.rb",
|
34
36
|
"test/seed_dump_test.rb",
|
@@ -36,7 +38,7 @@ Gem::Specification.new do |s|
|
|
36
38
|
]
|
37
39
|
s.homepage = "http://github.com/rhalff/seed_dump"
|
38
40
|
s.require_paths = ["lib"]
|
39
|
-
s.rubygems_version = "1.8.
|
41
|
+
s.rubygems_version = "1.8.25"
|
40
42
|
s.summary = "{Seed Dumper for Rails}"
|
41
43
|
|
42
44
|
if s.respond_to? :specification_version then
|
data/test/seed_dump_test.rb
CHANGED
@@ -18,14 +18,14 @@ class SeedDumpTest < ActiveSupport::TestCase
|
|
18
18
|
@env['MODEL_DIR'] = 'test/models/*.rb'
|
19
19
|
@sd.setup @env
|
20
20
|
@sd.loadModels
|
21
|
-
assert_equal ["Sample"], @sd.models
|
21
|
+
assert_equal ["AbstractSample", "ChildSample", "Sample"], @sd.models
|
22
22
|
end
|
23
23
|
|
24
24
|
test "support nested models" do
|
25
25
|
@env['MODEL_DIR'] = 'test/models/**/*.rb'
|
26
26
|
@sd.setup @env
|
27
27
|
@sd.loadModels
|
28
|
-
assert_equal ["Nested::Sample", "Sample"], @sd.models
|
28
|
+
assert_equal ["AbstractSample", "ChildSample", "Nested::Sample", "Sample"], @sd.models
|
29
29
|
end
|
30
30
|
|
31
31
|
test "without timestamps" do
|
@@ -55,5 +55,15 @@ class SeedDumpTest < ActiveSupport::TestCase
|
|
55
55
|
assert @sd.last_record.include?("id"), "WITH_ID must include id"
|
56
56
|
end
|
57
57
|
|
58
|
+
test "skip abstract model" do
|
59
|
+
@env['MODELS'] = "AbstractSample"
|
60
|
+
@env['MODEL_DIR'] = 'test/models/*.rb'
|
61
|
+
@env['TIMESTAMPS'] = false
|
62
|
+
@sd.setup @env
|
63
|
+
@sd.loadModels
|
64
|
+
@sd.dumpModels
|
65
|
+
assert_equal [], @sd.last_record
|
66
|
+
end
|
67
|
+
|
58
68
|
|
59
69
|
end
|
data/test/test_helper.rb
CHANGED
@@ -9,7 +9,13 @@ require 'active_record'
|
|
9
9
|
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
|
10
10
|
|
11
11
|
ActiveRecord::Schema.define(:version => 1) do
|
12
|
-
|
12
|
+
create_table "child_samples", :force => true do |t|
|
13
|
+
t.string "name"
|
14
|
+
t.datetime "created_at", :null => false
|
15
|
+
t.datetime "updated_at", :null => false
|
16
|
+
end
|
17
|
+
|
18
|
+
create_table "samples", :force => true do |t|
|
13
19
|
t.string "string"
|
14
20
|
t.text "text"
|
15
21
|
t.integer "integer"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: seed_dump
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-05-11 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Dump (parts) of your database to db/seeds.rb to get a headstart creating
|
15
15
|
a meaningful seeds.rb file
|
@@ -32,6 +32,8 @@ files:
|
|
32
32
|
- lib/true.rb
|
33
33
|
- seed_dump.gemspec
|
34
34
|
- test/fixtures/samples.yml
|
35
|
+
- test/models/abstract_sample.rb
|
36
|
+
- test/models/child_sample.rb
|
35
37
|
- test/models/nested/sample.rb
|
36
38
|
- test/models/sample.rb
|
37
39
|
- test/seed_dump_test.rb
|
@@ -56,7 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
56
58
|
version: '0'
|
57
59
|
requirements: []
|
58
60
|
rubyforge_project:
|
59
|
-
rubygems_version: 1.8.
|
61
|
+
rubygems_version: 1.8.25
|
60
62
|
signing_key:
|
61
63
|
specification_version: 3
|
62
64
|
summary: ! '{Seed Dumper for Rails}'
|