[PostgreSQL] If you want to delete the Rails app, delete the database first!

Introduction

If you repeatedly create and erase sample apps during learning, Suddenly, I was wondering, "Can I just delete the folder?"

When I looked it up, It seems that ** DB (database) ** must be deleted before ** folder ** can be deleted! Make a note of the two methods below.

-** DB deletion → App folder deletion ** -** How to delete the DB after deleting the application folder **

environment

① Delete DB → Delete application folder

In the folder of the corresponding application

$ rails db:drop

Go to the parent directory

$ rm -rf app name

It seems good to be sure to delete it according to the procedure of ① above. Here's what to do if you've deleted the app folder first.

(2) How to delete the DB after deleting the application folder

$ psql -l     (List DB names
#Execution result (when you want to delete the sample application)

                             List of databases
             Name      | Owner | Encoding | Collate | Ctype | Access privileges 
-----------------------+-------+----------+---------+-------+-------------------
 sample_development    | user  | UTF8     | C       | C     | 
 sample_test           | user  | UTF8     | C       | C     | 
 postgres              | user  | UTF8     | C       | C     | 
 template0             | user  | UTF8     | C       | C     | =c/user           +
                       |       |          |         |       | user=CTc/user
 template1             | user  | UTF8     | C       | C     | =c/user           +
                       |       |          |         |       | user=CTc/user
(5 rows)
$ psql postgres      (Log in to PostgreSQL

---
(postgres=#) \du     (Check users and permissions
(postgres=#) \q      (Login from PostgreSQL
---

$ dropdb -U user name DB name you want to delete

* DB that should not be deleted (default)

postgres template0 template1

I have removed this supposed default postgres. .. (Great reflection) I uninstalled PostgreSQL because it was just a learning app. When I checked after reinstalling, the above three DBs were there from the beginning! !!

I will write down the procedure after deleting the above default with caution.

How to uninstall

$ ls /usr/local/Cellar/postgresql     (Check installed PostgreSQL version
$ brew info postgresql     (Check the latest version at the moment

$ brew uninstall --force postgresql     (Uninstall all versions

$ ls -l /usr/local/var/postgres     (Display configuration files, logs, data, etc.
$ rm -rf /usr/local/var/postgres     (Delete configuration files, logs, data, etc.

Subsequent installations are the same as when installing for the first time.

at the end

While learning, the number of sample apps was increasing, I was able to solve it this way. I would appreciate it if you could point out any mistakes.

Reference article

Ruby on Rails deletion related summary Forcibly delete database in PostgreSQL (https://qiita.com/sayama0402/items/b3d96c25ecb60733beb9) [MacOS] How to uninstall all versions of PostgreSQL ~ Homebrew Edition PostgreSQL documentation "dropdb"

Recommended Posts

[PostgreSQL] If you want to delete the Rails app, delete the database first!
If you want to modify database columns etc.
If you want to recreate the instance in cloud9
What to do if you can't use the rails command
If you want to include the parent class in Lombok's @builder
If you want to change the Java development environment from Eclipse
The first thing to do before you can use Rails6 Ajax
Basic Rails commands you want to learn
[Rails] rails new to create a database with PostgreSQL
When you want to use the method outside
How to delete the database when recreating the application
The code I used to connect Rails 3 to PostgreSQL 10
[Java / PostgreSQL] Connect the WEB application to the database
Unify the Rails app time zone to Japan time
If you want to satisfy the test coverage of private methods in JUnit
If you are using Android Room and want to change the column definition
If you want to step up Ruby → Udemy "Introduction to Ruby on Rails for the first time-Learn Ruby and Rails from the basics and publish your web application online"
[rails] After option useful when you want to change the order of DB columns
If you want to know the options when configuring Ruby, see `RbConfig :: CONFIG ["configure_args "]`
If you want to separate Spring Boot + Thymeleaf processing
For those who want to use MySQL for the database in the environment construction of Rails6 ~.
I want to know the answer of the rock-paper-scissors app
I want to dark mode with the SWT app
If you want to use Mockito with Kotlin, use mockito-kotlin
Create an app that uses the weather API to determine if you need an umbrella.
Completely delete the migration file that you failed to delete
I want to add a delete function to the comment function
[Rails] What to do if you accidentally install bundle in the production environment in your local environment
[Rails] What to do if you can't get an error message with the errors method
Solution if you delete the migration file in the up state
I tried to introduce Bootstrap 4 to the Rails 6 app [for beginners]
I want to push an app made with Rails 6 to GitHub
If you want to study programming at university, go to Australia
[# 3 Java] Read this if you want to study Java! ~ Carefully selected ~
I want to create a form to select the [Rails] category
# What to do if you accidentally do rails db: migrate: drop
When you want to change the MySQL password of docker-compose
[Rails] How to display information stored in the database in view
[PostgreSQL] The story that you have to cut the session properly
Migrate GitBucket database to postgreSQL
[Rails] Delete the migration file
[Swift] When you want to know if the number of characters in a String matches a certain number ...
If you just want to run your containers in the cloud, Azure Container Instances is easy
If you are new to Rails and want to make your own validation, stop by this finger.
If you want to mock a method in RSpec, you should use the allow method for mock and the singleton method.
What to do if the app is not created with the latest Rails version installed when rails new
The story of the first Rails app refactored with a self-made helper
I want to give edit and delete permissions only to the poster
[Rails / Routing] How to refer to the controller in the directory you created
I want to create a chat screen for the Swift chat app!
Super beginner builds Rails6 + Postgresql environment with Docker to the end
When you want to ZIP download the image data saved locally
What to do if the Rails page doesn't appear in Rails tutorial 1.3.2
What to do if Cloud9 is full in the Rails tutorial
Rails' Private methods hurt if you feel the same as Java!
[Rails] How to reset the database in production environment (Capistrano version)
What to do if you forget the root password in CentOS7
What to do if you cannot roll back the migration (UnknownMigrationVersionError)
[Rails] What to do if you can't get parameters with form_with
When you want to add a string type column with a limited length with the `rails generate migration` command
If you leave the Next.js app open in Chrome, you will get a "/ _next / webpack-hmr" Routing error in the Rails app.