Agile Web Development

Build it. Launch it. Love it.

Manage Fixtures

This plugin is a super lightweight tool used to export data into the test/fixtures directory.

So if you want to export all your data from your production server into your development environment, this will simplify the process without having to load up your database manager.

  [%] rake db:fixtures:export_all RAILS_ENV=development
  [%] rake db:fixtures:load

USAGE

Create YAML test fixtures from data in an existing database. Defaults to development database. Set RAILS_ENV to override.

  rake db:fixtures:export_all

Create YAML test fixtures for a specific table(s) from data in an existing database. Defaults to development database. Set RAILS_ENV to override.

  rake db:fixtures:export_for_tables TABLES=foo,bar

Create YAML text fixtures based on a specific SQL query

  rake db:fixtures:export_using_query SQL="select * from foo where id='bar'" FIXTURE_NAME=foo

AUTHORS

Chris McGrath Nathaniel Brown - nshb@inimit.com

BUGS

Please report any bugs or feature enhancements to http://dev.toolbocks.com

Vitals

Repository http://svn.toolbocks.com/plugins/manage_fixtures/
License Rails' (MIT)
Tags Tag_red fixtures yaml
Rating (82 votes)
Owner Chris McGrath, Nathaniel Brown
Created 9 June 2006

Comments

  • Craig Knox
    5 February 2007

    I'm not really sure why your rating is so low - I find this tool quite useful. Thanks!

  • Avatar
    Kevin Elliott
    13 February 2007

    All of my imports show "Total of my_objects records imported successfully" --- It does not seem to keep track of how many records actually get imported. I am using this under Rails 1.1.6. Has anyone seen this before? I was unable to discover why it is not storing the count to the success hash properly.

  • Avatar
    Kevin Elliott
    13 February 2007

    I have solved the problem with the tally. My solution was to pull the increment code out of the if statement that contains the execute. ActiveRecord::Base.connection.execute() does not return anything, so the condition is never true normally.

  • Joshua
    2 June 2007

    As Craig already mentioned, the rating is to low. this excellent plugin saved me a lot of time and worked like a charm.

  • Avatar
    8 July 2007

    Great plugin - makes adding new a test data seem fun compared to the old "keep switching files to make sure I get my foreign keys right" method. If you're a fan of test data, get this plugin!

  • kuahyeow
    21 August 2007

    This is a wonderful plugin. And the fact that it is so small is really a benefit.

  • Avatar
    viktor tron
    15 December 2007

    The rating might be low, cause the plugin is a bit buggy for import. It breaks on serialized values and didn't work for me for inherited models either single table or not.

    However, I had no problem using the rake db:fixtures:load TABLES=... builtin task for import and this plugin for export.

    A very valueble addition to fixture management would be to bootstrap fixtures (write out empty fixtures with attributes) for all db tables. see the annotate_models plugin

  • Avatar
    Paul Flewelling
    21 January 2008

    Hey, I really like the plugin.

    My only comment is that I have some large "static" tables that I wanted written to yaml in the correct order.

    I quickly changed the method that writes the yaml. Maybe a more succinct way to do this, but it works for me :-) Cheers Paul

    def write_yaml_fixtures_to_file(sql, fixture_name) i = "000" File.open("#{RAILS_ROOT}/test/fixtures/#{fixture_name}.yml", 'w' ) do |file|

    data = ActiveRecord::Base.connection.select_all(sql)
    data.each do |record|
      hash = Hash.new
      hash["#{fixture_name}_#{i.succ!}"] = record 
      file.write hash.to_yaml
    end
    

    end end

  • Avatar
    Paul Flewelling
    21 January 2008

    Forgot the gsub that I'm using to remove the delimiters that are placed between each yaml record when writing them in this way.

    file.write hash.to_yaml.gsub('---', '')

  • e-Jah
    22 February 2008

    Guys, your plugin is awesome !!! I just love you, you saved me !

    Thanks !

  • Mark
    15 May 2008

    This is really useful plugin. Many thanks for sharing.

  • Mark
    15 May 2008

    I used this to migrate from sqlite3 to mysql but the boolean fields didn't get migrated. They seemed to be returned to the default values. Luckily I didn't have too many to correct.

  • Marc
    2 July 2009

    Repo Link is dead

Add a comment