Skip to content
Permalink
Browse files
Added db/seeds.rb as a default file for storing seed data for the dat…
…abase. Can be loaded with rake db:seed (or created alongside the db with db:setup). (This is also known as the "Stop Putting Gawd Damn Seed Data In Your Migrations" feature) [DHH]

Conflicts:

	railties/CHANGELOG
  • Loading branch information
dhh authored and lifo committed Aug 18, 2009
1 parent b9f668e commit f3c7bbeedd81d2f379c5e6a9e8739d3b3784ca5f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
@@ -199,11 +199,14 @@ task :copy_configs do

cp "configs/locales/en.yml", "#{PKG_DESTINATION}/config/locales/en.yml"

cp "configs/seeds.rb", "#{PKG_DESTINATION}/db/seeds.rb"

cp "environments/boot.rb", "#{PKG_DESTINATION}/config/boot.rb"
cp "environments/environment.rb", "#{PKG_DESTINATION}/config/environment.rb"
cp "environments/production.rb", "#{PKG_DESTINATION}/config/environments/production.rb"
cp "environments/development.rb", "#{PKG_DESTINATION}/config/environments/development.rb"
cp "environments/test.rb", "#{PKG_DESTINATION}/config/environments/test.rb"

end

task :copy_binfiles do
@@ -0,0 +1,7 @@
# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
# cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
# Major.create(:name => 'Daley', :city => cities.first)
@@ -125,6 +125,7 @@ def create_config_files(m)
create_database_configuration_file(m)
create_routes_file(m)
create_locale_file(m)
create_seeds_file(m)
create_initializer_files(m)
create_environment_files(m)
end
@@ -176,6 +177,10 @@ def create_routes_file(m)
m.file "configs/routes.rb", "config/routes.rb"
end

def create_seeds_file(m)
m.file "configs/seeds.rb", "db/seeds.rb"
end

def create_initializer_files(m)
%w(
backtrace_silencers
@@ -156,8 +156,8 @@ namespace :db do
Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby
end

desc 'Drops and recreates the database from db/schema.rb for the current environment.'
task :reset => ['db:drop', 'db:create', 'db:schema:load']
desc 'Drops and recreates the database from db/schema.rb for the current environment and loads the seeds.'
task :reset => [ 'db:drop', 'db:setup' ]

desc "Retrieves the charset for the current environment's database"
task :charset => :environment do
@@ -206,6 +206,15 @@ namespace :db do
end
end

desc 'Create the database, load the schema, and initialize with the seed data'
task :setup => [ 'db:create', 'db:schema:load', 'db:seed' ]

desc 'Load the seed data from db/seeds.rb'
task :seed => :environment do
seed_file = File.join(Rails.root, 'db', 'seeds.rb')
load(seed_file) if File.exist?(seed_file)
end

namespace :fixtures do
desc "Load fixtures into the current environment's database. Load specific fixtures using FIXTURES=x,y. Load from subdirectory in test/fixtures using FIXTURES_DIR=z. Specify an alternative path (eg. spec/fixtures) using FIXTURES_PATH=spec/fixtures."
task :load => :environment do

3 comments on commit f3c7bbe

@m3talsmith
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean we have a seed_fu like implementation in by default now? It sure looks like it?

@ayqazi
Copy link

@ayqazi ayqazi commented on f3c7bbe Sep 7, 2009

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it has the environment-specific seed support, nor multiple files for seeding - just one files.

I'm still going to use seed_fu, assuming it can safely override the db:seed task

@lawwantsin
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is one of those you do the first step, you gotta support it all kinda features... like everything else in rails.

Please sign in to comment.