Fill Database with ActiveRecord

Rails ActiveRecord is a quite powerfull tool even without Rails itself. Since it gets all the needed information from the Database it can actually be used for all kinds of operations on the Database itself via scripting. In a current project there was the need to generate a lot of data on a table to use for testing, since the table was modified during the testing it made sense to write a script which auto generates the data based on the current table configuration.

This can be achieved by leveraging ActiveRecord, like this

https://gist.github.com/3017432.js?file=argen.rb

This can be expanded to all kinds of SQL types by extending the mapping hash, as well as the needed data generate methods. By doing so it can incoperate also database specific types like hashes by identifying the via their characteristic SQL type, i.e. md5 hash is char(40).

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s