Skip to content

Latest commit

 

History

History
77 lines (49 loc) · 1.91 KB

heroku-to-aws-migration.md

File metadata and controls

77 lines (49 loc) · 1.91 KB

Heroku To AWS Migration Guide

When migrating an app from Heroku to AWS, you should take into account the following steps:

  1. Uncomment the .ebextensions files. Delete the 01_cron.config file if you don't schedule jobs with whenever. (Sidekiq Scheduler gem is recommended, but if you already started using whenever just uncomment the lines in this file an keep it).

  2. (OPTIONAL If you use only one DB with different Schemas)

Add this line in the config/database.yml file

production:
  ...
  schema_search_path: 'desired_schema'
  1. Copy the environment variables from Heroku to AWS

  2. Commit and Deploy

Migrate the database

  1. Create and download a backup from the Heroku Postgres database (It may take some minutes depending of the database size)
pg_dump HEROKU_DATABASE_URL -f dump.sql

Where HEROKU_DATABASE_URL is a String with the format: postgres://user::password@HOST:port/database_name

If it throws you an error like this:

pg_dump: server version: 9.X.X; pg_dump version: 9.X.X
pg_dump: aborting because of server version mismatch

Install the newest version of postgres with:

sudo apt-get install postgresql

or

sudo apt-get install postgresql-9.X

for the specific version and make the new link:

sudo ln -s /usr/lib/postgresql/9.X/bin/pg_dump /usr/bin/pg_dump --force
  1. (OPTIONAL If you use only one DB with different Schemas)

Connect to the database and create the Schema

psql RDS_DATABASE_URL
CREATE SCHEMA desired_schema;

Where RDS_DATABASE_URL is a String with the format: postgres://user::password@HOST:port/database_name Use \dn to see the existing schemas

Then open the dump.sql file and replace "public" with "desired_schema" everywhere.

  1. Restore the database in AWS
psql RDS_DATABASE_URL -f dump.sql

Ignore the errors of existing role or relations.