I guess the attachment didn't make it through, so here it is (fixtures.rake):
# make hash.to_yaml sort by keys # http://code.whytheluckystiff.net/syck/ticket/3 class Hash def to_yaml( opts = {} ) YAML::quick_emit( object_id, opts ) do |out| out.map( taguri, to_yaml_style ) do |map| sorted_keys = keys sorted_keys = begin sorted_keys.sort rescue sorted_keys.sort_by {|k| k.to_s} rescue sorted_keys end sorted_keys.each do |k| map.add( k, fetch(k) ) end end end end end class String def to_unix self.gsub(/\r\n/, "\n") end end namespace "iowaruby" do desc 'Create YAML test fixtures from data in an existing database. Defaults to development database. Set RAILS_ENV to override.' task :extract_fixtures => :environment do sql = "select * from %s order by id" skip_tables = ["schema_info", "sessions", "users"] ActiveRecord::Base.establish_connection (ActiveRecord::Base.connection.tables - skip_tables).each do | table_name| puts "Extracting #{table_name}" i = "000" File.open("#{RAILS_ROOT}/fixtures/#{table_name}.yml", 'w') do | file| data = ActiveRecord::Base.connection.select_all(sql % table_name) file.write data.inject({}) { |hash, record| hash["#{table_name}_#{i.succ!}"] = record hash }.to_yaml.to_unix end end end desc 'Load fixtures into a database. Defaults to development database. Set RAILS_ENV to override.' task :load_fixtures => :environment do require 'active_record/fixtures' ActiveRecord::Base.establish_connection Dir.glob(File.join(RAILS_ROOT, 'fixtures', '*.{yml,csv}')).each do |fixture_file| puts "Loading #{File.basename(fixture_file, '.*')}" Fixtures.create_fixtures(['fixtures'], File.basename (fixture_file, '.*')) end end end On Nov 9, 2007, at 12:46 PM, David W. Body wrote: > Hi, > > We use the attached rake file to version control Radiant changes > via yml files. I think this is close to what you are describing. > > --David W. Body / Iowa Ruby Brigade > > > > On Oct 30, 2007, at 8:40 PM, Richard Hurt wrote: > >> !!! WARNING WARNING WARNING !!! >> I know next to nothing about rake migrations so the following text >> might >> just as well be labled SPAM. :) >> !!! WARNING WARNING WARNING !!! >> >> Is there anyway to hook into a db:migration task to export/import >> the known >> radiant tables? That way we could at least grab the radiant stuff >> with a >> standard rake migration. If rake is anything like ant (for Java) >> it should >> be able to be extended to do this sort of thing. I envision >> something like >> the following: >> >> ## Export the development envrionment >> rake development db:migrate:export > mysite.db.tar >> >> ## [Optional] Store site in version control >> svn commit -m "Keep this in case we need it later" mysite.db.tar >> >> ## Import into the production environment >> rake production db:migrate:import < mysite.db.tar >> >> This is what we used to do with all of our environments when I was a >> corporate slave. Is this type of thing possible with rake? Am I >> barking up >> the wrong tree? >> >> Thanx! >> Richard > > _______________________________________________ > Radiant mailing list > Post: [email protected] > Search: http://radiantcms.org/mailing-list/search/ > Site: http://lists.radiantcms.org/mailman/listinfo/radiant _______________________________________________ Radiant mailing list Post: [email protected] Search: http://radiantcms.org/mailing-list/search/ Site: http://lists.radiantcms.org/mailman/listinfo/radiant
