AlexBrand
AlexBrand

Reputation: 12399

What is the best practice for adding records to a production DB once deployed to a VPS?

I just deployed my rails app to a Linode VPS, and was wondering what would be the best way of adding records to the DB.

I have tables such as Categories, which I'd like to populate.

I thought of the Taps gem, using a csv, or an sql dump file.

I'd like to know if there are any tools out there for this?

Thanks

Upvotes: 0

Views: 117

Answers (3)

JosephL
JosephL

Reputation: 5973

The Easy Reference Data gem is similar to db:seed, but will update records if entries already exist. It also has easy integration with Capistrano.

Full disclosure: The company I work for developed the gem.

Upvotes: 0

p1100i
p1100i

Reputation: 3740

For this puporse there are the so called seed file which is default in:

db/seeds.rb

You can add entries here ( there is an example in the seed file ), which you can generate after deployment with a rake task:

rake db:seed

You probably are using bundler as well, so use:

bundle exec rake db:seed

In case of large number of seeds you can always create multiple files, see this blogpost about handling large seed files.

However, if you are in a state, where the already existing data in the app is crucial and you are changing servers or database drivers you wanna take a look on yaml_db gem which gives a nice method to abstract the existing data away from your actual db driver and export it into a .yaml file which you can import later back e.g.: after deploying on a new server.

See Railscast - #179 about seeding.

Upvotes: 1

alup
alup

Reputation: 2981

The rails way would be to use seed data in db/seeds.rb and then populate it by using rake db:seed.

You could also use a sql dump file and restore by issueing mysql -u <user> -p <database_name> < <mysql_dump_file>

Upvotes: 0

Related Questions