fixturease 0.2.5 → 0.2.6
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.
- data/Rakefile +1 -1
- data/bin/fixturease.rb +21 -0
- metadata +2 -2
data/Rakefile
CHANGED
data/bin/fixturease.rb
CHANGED
@@ -11,6 +11,26 @@ else
|
|
11
11
|
|
12
12
|
$reload_fixtures = false
|
13
13
|
|
14
|
+
def reset_sequence!(mod)
|
15
|
+
if (adapter = YAML::load_file(ENV['RAILS_ROOT']+'/config/database.yml')[ENV['RAILS_ENV']]['adapter']) == "mysql"
|
16
|
+
ActiveRecord::Base.connection.rollback_db_transaction
|
17
|
+
ActiveRecord::Base.send :decrement_open_transactions
|
18
|
+
klass = mod.is_a?(Class) ? mod : mod.singularize.camelize.constantize
|
19
|
+
max_id = klass.find(:first,:order => "id DESC").id
|
20
|
+
ActiveRecord::Base.connection.execute "ALTER TABLE #{klass.table_name} AUTO_INCREMENT=#{max_id}"
|
21
|
+
ActiveRecord::Base.send :increment_open_transactions
|
22
|
+
ActiveRecord::Base.connection.begin_db_transaction
|
23
|
+
else
|
24
|
+
puts "Database adapter #{adapter} is not yet supported. Sorry"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def reset_sequences!
|
29
|
+
Dir[ENV['RAILS_ROOT']+'/'+ENV['FIXTURES_ROOT']+'/*.yml'].each do |fixture_file|
|
30
|
+
reset_sequence! File.basename(fixture_file,".yml")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
14
34
|
def load_fixtures!
|
15
35
|
$reload_fixtures = true
|
16
36
|
require 'active_record/fixtures'
|
@@ -56,6 +76,7 @@ else
|
|
56
76
|
ActiveRecord::Base.send :increment_open_transactions
|
57
77
|
ActiveRecord::Base.connection.begin_db_transaction
|
58
78
|
load_fixtures! if ENV['LOAD_FIXTURES']=='yes'
|
79
|
+
reset_sequences!
|
59
80
|
at_exit do
|
60
81
|
vars = {}
|
61
82
|
instance_variables.each {|varname| vars[instance_variable_get(varname)]=varname.gsub(/^@/,"") if instance_variable_get(varname).is_a? ActiveRecord::Base}
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
|
|
3
3
|
specification_version: 1
|
4
4
|
name: fixturease
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.2.
|
7
|
-
date: 2007-01-
|
6
|
+
version: 0.2.6
|
7
|
+
date: 2007-01-21 00:00:00 +02:00
|
8
8
|
summary: Easy fixture creation tool
|
9
9
|
require_paths:
|
10
10
|
- lib
|