Heroku app moving (rails)

Overview

Move rails app on heroku to another account (db is postgresql)

Premise

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

App migration

#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

Upgrade dyno (if needed)

Open the heroku app settings screen in your web browser Resources-> Change dyno types-> Hobby etc.

Transition start contact

Notify that you cannot take responsibility even if you touch the app after this (if necessary)

DB migration

#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

Operation check

What's good

If a problem occurs

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

If no problem occurs

App name change

Current account Current app name → Backup app name

New account Migration app name → Current app name

Transition end notification

(If necessary)

others

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

Heroku app moving (rails)
Deploy your Rails app on Heroku
Rails Heroku deployment procedure
rails heroku error log
[Rails] Heroku deployment flow
[Heroku] Associate AWS S3 with the deployed Rails app
[Rails] New app creation --Notes--
Incorporate circleCI into CircleCI Rails app
Rails (postgeresql. Ubuntu environment), heroku deployment
Incorporate Elasticsearch into your Rails app
Rails book review app RSpec introduction
Create a new app in Rails
Track Rails app errors with Sentry
Deploy Rails on Docker to heroku
App update reflected after heroku deployment
[Must-see for beginners] rails_12factor is not required to publish Rails app to Heroku
How to change app name in rails
I tried to introduce CircleCI 2.0 to Rails app
[Rails6] Create a new app with Rails [Beginner]
Deploy heroku with Rails6 (Cloud9 + Ubuntu) + MySQL
Change the default timezone for the rails app
Deploy to heroku with Docker (Rails 6, MySQL)
Try deploying a Rails app on EC2-Part 1-
Introduced Vue.js to an existing Rails app
[Rails Struggle/Rails Tutorial] Summary of Heroku commands
Upload Rails app image file to S3
Deploy to Heroku [Ruby on Rails] Beginner
MySQL is not running stably ... Rails app is not running.
Specify home view in rails app [root]
Try deploying Rails app to EC2-Part 2 (Deploy)-
Deploy a Java web app on Heroku
[Rails 5] Create a new app with Rails [Beginner]
[Portfolio] Bookmark management app [Ruby on Rails]
[AWS] Publish rails app with nginx + puma
[heroku] run rails db: migrate doesn't work
[Rails / Heroku] Error resolution procedure after push
Introduced Vuetify to an existing Rails app