Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create DB in production environment in rails

I have searched for how to create db in production environment for rails and got 2 answers. Now I am confused with those answers.

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

What is the difference between these two? What does this schema means?

Why do we need db:schema:load?

Thanks in advance.

like image 684
Anna Avatar asked Sep 02 '14 04:09

Anna


People also ask

What does rails db create do?

Rails 5. db:create - Creates the database for the current RAILS_ENV environment. If RAILS_ENV is not specified it defaults to the development and test databases.

How does rails connect with db?

Configuring database. At this point, you need to let Rails know the username and password for the databases. You do this in the file database. yml, available in the library\config subdirectory of Rails Application you created. This file has live configuration sections for PostgreSQL databases.

What db does rails use?

Rails defaults to using a SQLite database when creating a new project, but you can always change it later.


1 Answers

RAILS_ENV=production rake db:create would create the database for the production environment,

whereas

RAILS_ENV=production rake db:schema:load would create tables and columns within the database according the schema.rb for the production environment.

task :load => [:environment, :load_config] do
  ActiveRecord::Tasks::DatabaseTasks.load_schema_current(:ruby, ENV['SCHEMA'])
end

task :create => [:load_config] do
  ActiveRecord::Tasks::DatabaseTasks.create_current
end

Take a look at this file for complete info on the topic.

like image 91
Andrey Deineko Avatar answered Sep 25 '22 07:09

Andrey Deineko