Hi Guys, Is there any way to export db data to fixtures files? (like the reverse of "rake db:fixtures:load") Thanks, Arthur -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Yeah there are a few plugins to do that. There''s one called ar_fixtures that should work just fine. I don''t know if it''s supported any more but I know it still works fine. On Mon, Dec 1, 2008 at 8:14 PM, Arthur Chan <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hi Guys, > > Is there any way to export db data to fixtures files? > > (like the reverse of "rake db:fixtures:load") > > Thanks, > Arthur > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Brian Hogan wrote:> Yeah there are a few plugins to do that. There''s one called > ar_fixtures that should work just fine. I don''t know if it''s > supported any more but I know it still works fine. > > On Mon, Dec 1, 2008 at 8:14 PM, Arthur ChanThanks Brian, it seems to be what I want. :) -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I''m curious as to what you are using this for. On Dec 2, 1:00 am, Arthur Chan <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Brian Hogan wrote: > > Yeah there are a few plugins to do that. There''s one called > > ar_fixtures that should work just fine. I don''t know if it''s > > supported any more but I know it still works fine. > > > On Mon, Dec 1, 2008 at 8:14 PM, Arthur Chan > > Thanks Brian, it seems to be what I want. :) > > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Bobnation wrote:> I''m curious as to what you are using this for. > > On Dec 2, 1:00�am, Arthur Chan <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>It is difficult to handle the data with relationships between different tables. So, it is better to start the creation of fixtures from using existing data. Also, it is useful for us to generate demo site. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I just modified the plugin (the ar_fixtures.rake file) to allow output
all tables:
<code>
# arthur: if "rake db:data:dump MODEL=ALL" then load the following
models
# put all your tables need to export here
all_modelsS = [''Album'', ''Asset'',...
''UserContact'', ''UserInfo'',
''User'']
def env_or_raise(var_name, human_name)
if ENV[var_name].blank?
raise "No #{var_name} value given. Set #{var_name}=#{human_name}"
# arthur: allow the ALL input
elsif var_name == ''MODEL'' && ENV[var_name] ==
''ALL''
return all_models
else
return ENV[var_name]
end
#else
# return ENV[var_name]
#end
end
# arthur: check if all model is needed
def all_models
return all_modelsS if ENV[''MODEL''] ==
''ALL''
input = env_or_raise(''MODEL'', ''ModelName'')
return [input]
end
def model_or_raise
return env_or_raise(''MODEL'', ''ModelName'')
end
def limit_or_nil_string
ENV[''LIMIT''].blank? ? ''nil'' :
ENV[''LIMIT'']
end
namespace :db do
namespace :fixtures do
desc "Dump data to the test/fixtures/ directory. Use MODEL=ModelName
and LIMIT (optional)"
task :dump => :environment do
# arthur, allow all models input
all_models.each do | model|
eval "#{model}.to_fixture(#{limit_or_nil_string})"
end
# eval "#{model_or_raise}.to_fixture(#{limit_or_nil_string})"
end
end
namespace :data do
desc "Dump data to the db/ directory. Use MODEL=ModelName and LIMIT
(optional)"
task :dump => :environment do
# arthur, allow all models input
all_models.each do | model|
eval "#{model}.dump_to_file(nil, #{limit_or_nil_string})"
puts "#{model} has been dumped to the db folder."
end
end
desc "Load data from the db/ directory. Use MODEL=ModelName"
task :load => :environment do
# arthur, allow all models input
all_models.each do | model|
eval "#{model}.load_from_file"
end
#eval "#{model_or_raise}.load_from_file"
end
end
end
</code>
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---