I want to drop and recreate a database of a running production server. In order to do that I want to run
rake db:drop and rake db:create
But to do that, the app needs to stop using the database that’s why I’d like to stop the server.
Does anyone know how to do that?
Thank you, Florian
I have a rake task I use for situations like these: fly.io-rails/mock.rake at main · superfly/fly.io-rails (github.com)
With this in place, I change SERVER_COMMAND to
bin/rails mock:server, run
fly deploy, then
fly ssh console, explore/make changes, then change SERVER_COMMAND back and run
fly deploy one last time.
The basic idea is that startup requires a server handing port 8080 so I provide one.
Great! You saved my day once again sir @rubys! Thank you, I’ll give it a try at once.
I actually tried doing something similar by making a
tail -f /dev/null but obviously this couldn’t work if it expects a server handling port 8080
I actually tried this, I can see the mock server running by going to the production url but running
fly ssh console -C "app/bin/rails db:drop DISABLE_DATABASE_ENVIRONMENT_CHECK=1" still gives me:
database "databse_name" is being accessed by other users
DETAIL: There are 2 other sessions using the database.
I restarted the fly database app and now and I still get
There is 1 other session using the database. I am guessing that as long as there is an app in the same network, it’s connecting to the database. I was thinking to just create a new database, but I don’t know how to change the details in
config/databse.yml on the fly rails server instance. I believe that the config for the database defaults to the app db name
bin/rake mock:server, it looks like
I tried rake, but the database is still being used…
I just went another route, instead of dropping the database, I went into the postgres command, deleted all tables and then ran the database dump again on the database and that worked for me.