Move rails app on heroku to another account (db is postgresql)
Install heroku cli. https://devcenter.heroku.com/ja/articles/heroku-cli
At the time of article creation
heroku --version
heroku/7.47.6 darwin-x64 node-v12.16.2
#Log in to your current account
heroku login
#Download source
heroku git:clone -a Current app name
cd current app name
#Remove git remote
git remote rm heroku
#Check git remote
git remote -v
#Make a note of any environment variables you have set(Basic authentication password, etc.)
heroku config -a App name
#Log out
heroku logout
#Ruby if needed,Rails version change, source correction, etc.
#Log in to your new account
heroku login
#Create an app for a new account
heroku create migration app name
#Check git remote (should be set automatically when creating)
git remote -v
#Deploy app
git push heroku master
#Set environment variables (if needed)
heroku config:set BASIC_AUTH_PASSWORD="password" -a Migration app name
heroku config:set BASIC_AUTH_USERNAME="user" -a Migration app name
#Check environment variables
heroku config
#Add-ons added (if needed)
heroku addons:create heroku-postgresql:hobby-basic
heroku addons:create papertrail:choklad
#Confirm that it is registered with addon
heroku addons
#Log out
heroku logout
Open the heroku app settings screen in your web browser Resources-> Change dyno types-> Hobby etc.
Notify that you cannot take responsibility even if you touch the app after this (if necessary)
#Log in to your current account
heroku login
#Put into maintenance mode
heroku maintenance:on -a Current app name
#Stop workers (if any)
heroku ps:scale worker=0 -a Current app name
#Check the current number of data, etc. (if necessary)
heroku run rails c -a Current app name
MyModel.count
#Manual backup
heroku pg:backups capture -a Current app name
#Check the backup result
heroku pg:backups -a Current app name
#Get a backup dump file locally
heroku pg:backups:download -a Current app name
#Log out of your current account
heroku logout
#Upload dump (example is s3)
#Upload to s3 the way you like
#Change file to public (public access)
#Get the URL of the file
#Log in to your new account
heroku login
#Restoration
heroku pg:backups restore 'https://kwgch-upload.s3-ap-northeast-1.amazonaws.com/db_migration/latest.dump' DATABASE_URL
#Check the number of migrations
heroku run rails c
MyModel.count
#Start worker (if any)
heroku ps:scale worker=1
What's good
Resume the current app
#Turn off maintenance mode
heroku maintenance:off -a Current app
#Keep the worker running (if any)
heroku ps:scale worker=1 -a Current app
Current account Current app name → Backup app name
New account Migration app name → Current app name
(If necessary)
We recommend that you create a runbook and carry out rehearsals before moving to production. Pair operation is preferable to touching by one person.
Recommended Posts