seed-fu 2.0.0 → 2.0.1.rails31

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
- Version 2.0.0 (In Development)
2
- ------------------------------
1
+ Version 2.0.1
2
+ -------------
3
+
4
+ Bug fixes:
5
+
6
+ * Update the primary key sequence in PostgreSQL tables after seeding data. This ensures that id conflicts do not occur when records are subsequently added to the table.
7
+
8
+ * Raise ActiveRecord::RecordNotSaved if any of the saves fail (but they won't fail due to validation since saves are done without validation, so this guards against callbacks failing etc.)
9
+
10
+ Version 2.0.0
11
+ -------------
3
12
 
4
13
  Features:
5
14
 
data/README.md CHANGED
@@ -137,7 +137,7 @@ If you need to programmatically generate seed files, for example to convert a CS
137
137
  Bugs / Feature requests
138
138
  -----------------------
139
139
 
140
- Please report them [on Lighthouse](http://mbleigh.lighthouseapp.com/projects/10223-seed-fu).
140
+ Please report them on [Github Issues](https://github.com/mbleigh/seed-fu/issues).
141
141
 
142
142
  Contributors
143
143
  ------------
data/lib/seed-fu.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'active_record'
2
+ require 'active_support/core_ext/module/attribute_accessors'
2
3
  require 'seed-fu/railtie' if defined?(Rails) && Rails.version >= "3"
3
4
 
4
5
  module SeedFu
@@ -32,9 +32,11 @@ module SeedFu
32
32
  # Insert/update the records as appropriate. Validation is skipped while saving.
33
33
  # @return [Array<ActiveRecord::Base>] The records which have been seeded
34
34
  def seed
35
- @model_class.transaction do
35
+ records = @model_class.transaction do
36
36
  @data.map { |record_data| seed_record(record_data.symbolize_keys) }
37
37
  end
38
+ update_id_sequence
39
+ records
38
40
  end
39
41
 
40
42
  private
@@ -59,9 +61,11 @@ module SeedFu
59
61
  def seed_record(data)
60
62
  record = find_or_initialize_record(data)
61
63
  return if @options[:insert_only] && !record.new_record?
62
- record.send(:attributes=, data, false)
64
+
63
65
  puts " - #{@model_class} #{data.inspect}" unless @options[:quiet]
64
- record.save(:validate => false)
66
+
67
+ record.send(:attributes=, data, false)
68
+ record.save(:validate => false) || raise(ActiveRecord::RecordNotSaved)
65
69
  record
66
70
  end
67
71
 
@@ -73,5 +77,18 @@ module SeedFu
73
77
  def constraint_conditions(data)
74
78
  Hash[@constraints.map { |c| [c, data[c.to_sym]] }]
75
79
  end
80
+
81
+ def update_id_sequence
82
+ if @model_class.connection.adapter_name == "PostgreSQL"
83
+ quoted_id = @model_class.connection.quote_column_name(@model_class.primary_key)
84
+ quoted_sequence = "'" + @model_class.sequence_name + "'"
85
+ @model_class.connection.execute(
86
+ "SELECT pg_catalog.setval(" +
87
+ "#{quoted_sequence}," +
88
+ "(SELECT MAX(#{quoted_id}) FROM #{@model_class.quoted_table_name}) + 1" +
89
+ ");"
90
+ )
91
+ end
92
+ end
76
93
  end
77
94
  end
@@ -1,4 +1,4 @@
1
1
  module SeedFu
2
2
  # The current version of Seed Fu
3
- VERSION = '2.0.0'
3
+ VERSION = '2.0.1'
4
4
  end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: seed-fu
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
4
+ prerelease: true
5
5
  segments:
6
6
  - 2
7
7
  - 0
8
- - 0
9
- version: 2.0.0
8
+ - 1
9
+ - rails31
10
+ version: 2.0.1.rails31
10
11
  platform: ruby
11
12
  authors:
12
13
  - Michael Bleigh
@@ -15,7 +16,7 @@ autorequire:
15
16
  bindir: bin
16
17
  cert_chain: []
17
18
 
18
- date: 2010-11-05 00:00:00 +00:00
19
+ date: 2010-12-26 00:00:00 +00:00
19
20
  default_executable:
20
21
  dependencies:
21
22
  - !ruby/object:Gem::Dependency
@@ -28,15 +29,32 @@ dependencies:
28
29
  - !ruby/object:Gem::Version
29
30
  segments:
30
31
  - 3
32
+ - 1
31
33
  - 0
32
- - 0
33
- version: 3.0.0
34
+ - beta
35
+ version: 3.1.0.beta
34
36
  type: :runtime
35
37
  version_requirements: *id001
36
38
  - !ruby/object:Gem::Dependency
37
- name: rspec
39
+ name: activesupport
38
40
  prerelease: false
39
41
  requirement: &id002 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ segments:
47
+ - 3
48
+ - 1
49
+ - 0
50
+ - beta
51
+ version: 3.1.0.beta
52
+ type: :runtime
53
+ version_requirements: *id002
54
+ - !ruby/object:Gem::Dependency
55
+ name: rspec
56
+ prerelease: false
57
+ requirement: &id003 !ruby/object:Gem::Requirement
40
58
  none: false
41
59
  requirements:
42
60
  - - ~>
@@ -44,14 +62,39 @@ dependencies:
44
62
  segments:
45
63
  - 2
46
64
  - 0
65
+ version: "2.0"
66
+ type: :development
67
+ version_requirements: *id003
68
+ - !ruby/object:Gem::Dependency
69
+ name: pg
70
+ prerelease: false
71
+ requirement: &id004 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ segments:
47
77
  - 0
48
- version: 2.0.0
78
+ version: "0"
49
79
  type: :development
50
- version_requirements: *id002
80
+ version_requirements: *id004
81
+ - !ruby/object:Gem::Dependency
82
+ name: mysql2
83
+ prerelease: false
84
+ requirement: &id005 !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ segments:
90
+ - 0
91
+ version: "0"
92
+ type: :development
93
+ version_requirements: *id005
51
94
  - !ruby/object:Gem::Dependency
52
95
  name: sqlite3
53
96
  prerelease: false
54
- requirement: &id003 !ruby/object:Gem::Requirement
97
+ requirement: &id006 !ruby/object:Gem::Requirement
55
98
  none: false
56
99
  requirements:
57
100
  - - ">="
@@ -60,7 +103,7 @@ dependencies:
60
103
  - 0
61
104
  version: "0"
62
105
  type: :development
63
- version_requirements: *id003
106
+ version_requirements: *id006
64
107
  description: Seed Fu is an attempt to once and for all solve the problem of inserting and maintaining seed data in a database. It uses a variety of techniques gathered from various places around the web and combines them to create what is hopefully the most robust seed data system around.
65
108
  email:
66
109
  - michael@intridea.com
@@ -104,11 +147,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
104
147
  required_rubygems_version: !ruby/object:Gem::Requirement
105
148
  none: false
106
149
  requirements:
107
- - - ">="
150
+ - - ">"
108
151
  - !ruby/object:Gem::Version
109
152
  segments:
110
- - 0
111
- version: "0"
153
+ - 1
154
+ - 3
155
+ - 1
156
+ version: 1.3.1
112
157
  requirements: []
113
158
 
114
159
  rubyforge_project: