Can I somehow execute my db/seeds.rb file from my rails app?
You can call Rails.application.load_seed. That’s all rake db:seed does.
You can call Rails.application.load_seed. That’s all rake db:seed does.
It is not possible to get the automatic seed back out from the generator. I normally generate seeds like this: seed = random.randrange(sys.maxsize) rng = random.Random(seed) print(“Seed was:”, seed) This way it is time-based, so each time you run the script (manually) it will be different, but if you are using multiple generators they won’t … Read more
If you have to use the model you need a loop: foreach($users as $user){ User::create($user); } Otherwise you can just use DB::table() and insert: DB::table(‘users’)->insert($users); Actually you can also call insert() on the model (the resulting query is the same) User::insert($users); Note if you choose the insert method you loose special Eloquent functionality such as … Read more
The command to reset the identity property is DBCC CHECKIDENT (tablename, RESEED, new_reseed_value) When you want to set the column identity to 12345 you run this DBCC CHECKIDENT (beer, RESEED, 12345) When you want to delete test rows and restore the value to the previous value, you do the following. DELETE FROM beer WHERE beer_id … Read more
Start by creating a separate directory to hold your custom seeds – this example uses db/seeds. Then, create a custom task by adding a rakefile to your lib/tasks directory: # lib/tasks/custom_seed.rake namespace :db do namespace :seed do Dir[Rails.root.join(‘db’, ‘seeds’, ‘*.rb’)].each do |filename| task_name = File.basename(filename, ‘.rb’) desc “Seed ” + task_name + “, based on … Read more
Updating since these answers are slightly outdated (although some still apply). Simple feature added in rails 2.3.4, db/seeds.rb Provides a new rake task rake db:seed Good for populating common static records like states, countries, etc… http://railscasts.com/episodes/179-seed-data *Note that you can use fixtures if you had already created them to also populate with the db:seed task … Read more
Try this: context.People.AddOrUpdate(p => new { p.FirstName, p.LastName }, people);
The main python module that is run should import random and call random.seed(n) – this is shared between all other imports of random as long as somewhere else doesn’t reset the seed.
The db:seed rake task primarily just loads the db/seeds.rb script. Therefore just execute that file to load the data. load “#{Rails.root}/db/seeds.rb” # or Rails.application.load_seed Where to place that depends on what testing framework you are using and whether you want it to be loaded before every test or just once at the beginning. You could … Read more
One option is http://davidbau.com/seedrandom which is a seedable RC4-based Math.random() drop-in replacement with nice properties.