0.01
No commit activity in last 3 years
No release in over 3 years
Manage your seed scripts by versioning them
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

>= 3
~> 0.9
>= 2
 Project Readme

Project not maintained!

Versioned Seeds is not maintained anymore. Take a look at seedbank or seed_migration instead ;)

Versioned Seeds Build Status

Versioned Seeds is an alternative to Rails seeds. It allows to store your seeds in several files and prevent from re-seeding.

Rails seeds are great when you create a project but what about new ones when the project is already running ? When you have to import some data from a CSV file ?

Versioned Seeds provides a simple, conventions based, way to do that.

Installation

Add this line to your Gemfile :

gem 'versioned_seeds'

If you're using Git, as you should, be sure to call this in your shell :

$ echo ".versionned_seeds" >> .gitignore

Usage

Get current version

You can get the last imported seeds version :

$ rake vs:status
Last seeds: 0

Configuration

VersionedSeeds can be configured using an initializer:

VersionedSeeds.configuration do |config|
  # Path where are stored seed files
  # VersionedSeeds will look for [root_path]/db/seeds/*.rb
  # Defaults to Rails.root
  config.root_path = '...'

  # Path of the .versioned_seeds file where the list of
  # already loaded seed files is stored
  config.list_path = '...' #
end

Generate a seeding script

The generator will simply generate a timestamped file where you can put anything you want :

$ rails g versioned_seeds:seed_file some_seeding_script
      create  db/seeds/20111205155806_some_seeding_script.rb

Loading the scripts

Given two seeds files :

# db/seeds/20111205155801_create_users.rb
User.create!(:username => 'admin', :password => 'password', :admin => true)
User.create!(:username => 'user1', :password => 'password')

# db/seeds/20111205155802_import_articles.rb
require 'csv'

CSV.foreach('/some/file.csv') do |line|
  # ...
end

You can import only the first one by using the vs:next task :

$ rake vs:next
Loading: 20111205155801_create_users.rb

$ rake vs:status
Last seeds: 20111205155801

Or load all files using the vs:all task :

$ rake vs:all
Loading: 20111205155801_create_users.rb
Loading: 20111205155802_import_articles.rb

$ rake vs:status
Last seeds: 20111205155802

Every script imported once will never be loaded again.