[RUBY] [Rails] Reset the database in the production environment

Introduction

[Premise]

・ Develop applications using Rails ・ Use AWS ・ Create a web server on EC2

Reset existing database

If you ever wanted to reset the DB when developing in your own local environment

I was recreating the DB using riset.



 After deploying this time, because I made various changes to the migration file etc.
 I thought about resetting it once in the production environment and rebuilding it.

## Database reset in production environment

```ruby
RAILS_ENV=production DISABLE_DATABASE_ENVIRONMENT_CHECK=1 bundle exec rails db:drop

You can reset the DB in production with this command (Is it possible to reset the DB in the production environment?)

Reflect the contents of the database again

   rails db:create RAILS_ENV=production
   rails db:migrate RAILS_ENV=production
   rails db:seed RAILS_ENV=production

In the above description, if you have any improvement plans or suggestions such as if there is such a risk, I would appreciate it if you could let me know in the comments.

We hope you find this helpful.

Recommended Posts

[Rails] Reset the database in the production environment
[Rails] How to reset the database in production environment (Capistrano version)
Create a database in a production environment
Display the background image in the production environment
Rails5.1 + puma SSL connection in local production environment
500 Internal Server Error occurs in Rails production environment
I get Mysql2 :: Error :: ConnectionError in the production environment
SSL in the local environment of Docker / Rails / puma
[Error] The app is not displayed in the production environment
For those who want to use MySQL for the database in the environment construction of Rails6 ~.
[Rails] How to delete production environment MySQL data after putting it in the development environment
[Rails] How to display information stored in the database in view
About the symbol <%%> in Rails erb
[Rails 6] Customize Bootstrap in Rails + Bootstrap 5.0.0-alpha environment
[Rails] What to do if you accidentally install bundle in the production environment in your local environment
[Rails] How to execute "rails db: create" etc. in production environment EC2
Can't output PDF in production environment (EC2, Amazon Linux) with Rails
I want to display the images under assets/images in the production environment
When log data accumulates in Rails and the environment stops working
Install Rails in the development environment and create a new application
How to reflect seeds.rb in production environment
The identity of params [: id] in rails
Prepare the format environment with "Rails" (VScode)
Rails refactoring story learned in the field
Prepare the security check environment for Rails 6
Creating a Servlet in the Liberty environment
Show Better Errors in Rails + Docker environment
Image is not displayed in production environment
Rails6: Extract the image in Action Text
Launching the production environment with docker + rails (ver5.2) and errors that occurred
Puma --Nignx is an escape route when rails s -e production -d doesn't work in the environment
[Order method] Set the order of data in Rails
Rails database basics
[Rails] Run LINEBot in local environment using ngrok
(Capistrano) After deploying, I get a We're sorry… error in the production environment.
What to do when rails db: seed does not reflect in the database
[Rails] Show multi-level categories in the breadcrumb trail
Group_by in Rails
Implement the Like feature in Ajax with Rails.
[Rails] Added in devise: username not added to database
[Rails] I want to reset everything because the data in the local environment is strange! What to do before that
[Rails] How to use PostgreSQL in Vagrant environment
How to check Rails commands in the terminal
[Rough explanation] How to separate the operation of the production environment and the development environment with Rails
Migration error after Activerecord association in Rails5 + Docker environment (2)
How to set the display time to Japan time in Rails
Sharing research on ER diagram automation in Rails environment
[Ruby on Rails Tutorial] Error in the test in Chapter 3
Prepare the execution environment of Tomcat in IntelliJ Community
Docker the development environment of Ruby on Rails project
Migration error after Activerecord association in Rails5 + Docker environment
Regarding overcapacity when setting Rails tutorial environment in Cloud 9
[Ruby On Rails] How to reset DB in Heroku
[Ruby / Rails] Set a unique (unique) value in the class
[Java] Get the file in the jar regardless of the environment
Questions about implementing the Like feature (Ajax) in Rails
Database environment construction with Docker in Spring boot (IntellJ)
Beginners use ubuntu in windows to prepare rails environment
[Rails] How to display an image in the view
[Ruby on Rails] credential does not work in production environment even though I saved production.key
Model association in Rails