Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3. Creating a production database

How can I create a production database in Rails 3 and load a schema to it?

I tried the following approaches...

I.

rake db:create Rails.env='production' && rake db:schema:load Rails.env='production' 

II.

# config/environment.rb # Set the rails environment Rails.env='production' rake db:create && rake db:schema:load 

... but neither of them works.

Thanks.

Debian GNU/Linux 5.0.6;

Rails 3.0.0;

Sqlite3 3.7.2.

like image 378
Shamaoke Avatar asked Sep 11 '10 06:09

Shamaoke


People also ask

What is the production environment in rails?

The production environment is used when you deploy your application for the world to use. Rails comes with built-in support for SQLite, which is a lightweight serverless database application. While a busy production environment may overload SQLite, it works well for development and testing.

How many databases should I create in Ruby on rails?

Ruby on Rails recommends to create three databases - a database each for development, testing, and production environment. According to convention, their names should be − You should initialize all three of them and create a user and password for them with full read and write privileges.

How to create an animal database in rails?

If you want to create just the animals database you can run bin/rails db:create:animals. Migrations for multiple databases should live in their own folders prefixed with the name of the database key in the configuration. You also need to set the migrations_paths in the database configurations to tell Rails where to find the migrations.

Is your Rails application ready for multiple databases?

While Rails tries to do most of the work for you there are still some steps you'll need to do to get your application ready for multiple databases. Let's say we have an application with a single writer database and we need to add a new database for some new tables we're adding.


2 Answers

You can set the rails env off of the environment variable RAILS_ENV

RAILS_ENV=production bundle exec rake db:create db:schema:load 

should work

like image 110
Matt Briggs Avatar answered Oct 02 '22 15:10

Matt Briggs


Shouldn't this be

RAILS_ENV=production bundle exec rake db:create db:schema:load 
like image 33
Victor S Avatar answered Oct 02 '22 16:10

Victor S