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.
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.
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.
Rails defaults to using a SQLite database when creating a new project, but you can always change it later.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With