How to do rake db:seed in using neo4j gem in rails 4

Neo4j is a graph database, using neo4j gem(https://github.com/neo4jrb/neo4j) we can easily use neo4j database in our ruby on rails application (http://programminginrubyonrails.blogspot.in/2014/12/neo-4j-with-rails.html).

Till now neo4j gem does not support rake db tasks. You can check all the supported task by typing
rake -T in your console.

Now we can create our own custom rake task to seed some  data in neo4j.

Step 1: Create a file under lib/tasks name it seed.rake
Step 2: Put the below code in seed.rake.

namespace :db do
  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
end

That's it. now you can run rake db:seed from your terminal.. Simple :) 

Comments

Post a Comment

Popular posts from this blog

Insert Bulk data using active record import

Swap primary keys between two records in the same table in Postgres

How to add a bootstrap table with fixed header and scrollable body