Migrating from Heroku

This page describes how to migrate an application from Heroku to Nex!™. This page only focuses on the actual data migration for now as the migration of the application itself is no more than just following the standard Nex!™ deployment process.








1 - Export the database content into SQL statement

Launch a rails console on heroku

heroku run rails console

execute the following code snippet

ActiveRecord::Base.logger = nil
[Maestrano::Connector::Rails::IdMap, Maestrano::Connector::Rails::Organization, Maestrano::Connector::Rails::Synchronization, Maestrano::Connector::Rails::User, Maestrano::Connector::Rails::UserOrganizationRel].each do |clazz|
  limit = 100
  offset = 0
  count = clazz.count

  while offset < count
    clazz.limit(limit).offset(offset).all.each do |record|
      sql = clazz.arel_table.create_insert.tap do |im|
        im.insert(record.send(:arel_attributes_with_values_for_create, record.attribute_names))
      end.to_sql.gsub('"', '').gsub("'f'", '0').gsub("'t'", '1')
   
      puts "#{sql};"
    end
    offset += limit
  end
end; nil

and save the output into a file

2 - Import data into the Connector MySQL


MySQL Addon required

The step below assumes that you have already provisioned a mysql addon for your application.

You can run nex-cli addons:create mysql visionary-wombat-3 otherwise to create the addon.


Upload the MySQL dump to the connector:

# List containers
nex-cli cubes --app visionary-wombat-3

# Grab the ID of the first running container then upload the file
# The file will be uploaded in the /tmp directory of the container by default
nex-cli cubes:upload <container-id> dump.sql


SSH on the connector

nex-cli apps:ssh visionary-wombat-3


Install required packages

$ apt-get update
$ apt-get install mysql-client


And import the backup into the database

# Find MySQL details
$ echo $DATABASE_URL
> mysql2://[username]:[password]@[hostname]:[port]/app_db?reconnect=true

# Import data
$ mysql app_db -h $MYSQL_HOST -P $MYSQL_PORT -u$MYSQL_USER -p$MYSQL_PASSWORD < /tmp/dump.sql