comments 2

#4 Migration from Parse to Heroku

In this tutorial I will show how to migrate our iOS Parse application to Heroku step by step:

  • In the first step we will migrate Parse DB to Self-Hosted MongoDB
  • then we will set up Local Parse Server
  • and finally we’ll deploy Parse Server to Heroku

During creating this post I mainly based on Parse Server Guide, where you can find more general information about migration.

But before we get started…

First let’s setup MongoDB on MongoLab. This is the easiest way to migrate our data from Parse, alternative way is to set up mongoDB locally, but in this tutorial I have decided to show everything based on MongoLab.

Set up database on MongoLab

Go to MongoLab, if you don’t have account yet, create one and then choose 500 MB(for free):

MongoDBSandBox
MongoDBSandBox

Important: Don’t forget to add a new user to your database:)

set configuration for database according to requirements which you can find on Parse Guide website:

  • MongoDB version 2.6.X or 3.0.X – necessary
  • The failIndexKeyTooLong parameter must be set to false. – necessary
  • An SSL connection is recommended (but not required). – optional
  • We strongly recommend that your MongoDB servers be hosted in the US-East region for minimal latency. – optional

Install mongo locally:

I tried to set failIndexKeyTooLong parameter via:

an then in console appeared:

it means that you only can modify parameters when you have admin privileges, but I neither couldn’t login with admin privileges nor create user with root role (maybe I miss something). For sure it is possible if your database is set up locally. It will be great to hear your experience with databases!:)

Anyway, a very nice tool to manage tou mongoDB database you can download from here🙂

Information how to make SSL connection you can find here.

After setting up database we are ready to:

Migrate Parse DB to Self-Hosted MongoDB

MongoDBonMongoLab
MongoDBonMongoLab

Login to your Parse account and select your app, then go to:
App Settings → General → Migrate to external database:

ParseMigrateApp
ParseMigrateApp

then in text field enter your databaseURI which you achieved after setting up database on MongoLab:

then after pressing Begin the migration button, process should start:

ParseMigrationProcess
ParseMigrationProcess

In this stage your app is still hitting api.parse.com, but is using your MongoDB instance. Now you are responsible for your own imports, exports, backups, indexes, monitoring, and other database administration.

Set Up Local Parse Server

In this step we will go one step further, and we will setup Parse Server locally:

ParseLocalParseServer
ParseLocalParseServer
Prerequirements before we start next step:

Make sure that you have Node and Express, if not, then in console type:

if you upgraded/updated npm version, it could be helpful to rebuild everything by typing:

If you want to remove node and install everything from zero this Gist can help you.

ok, now we can start setting up local server:

Install Parse Server:

Create .js file and add the following code:

of course don’t forget to copy your appID, masterKey from your Parse account (Security & Keys Tab) and databaseURI from your MongoLab website.

Run app:

and now you should have local server on your host: http://localhost:1337/

Now if you would open this site in browser you could get response from server:

The reason is simple: we can’t forget to send our request with necessary parameters as in example below:

ParsePostman
ParsePostman

or just type in console:

everything should work (i hope so:) ). If yes then in response we should see our requested entities.

our next big and final step is to…

Deploy Parse Server to Heroku

MigartionToHeroku
MigartionToHeroku
Prerequirements:
  • First of all create account on Heroku if you don’t have it yet.

  • Install the Heroku Toolbelt it is CLI tool for creating and managing Heroku apps. Once installed, you can use the heroku command from your command shell:

Create a Express application:

Basing on the project from Github I have created a similar, simplified one. Project uses the parse-server module on Express. You can download it from here.

After downloading open index.js and set necessary values for following keys:

  • databaseURI
  • appId
  • masterKey
Deploy application to Heroku:

Locate your project directory in console and then type:

Above command prepares Heroku to receive your source code, and additionally a git remote (called heroku) is also created and associated with your local git repository.

Then to connect with self generating git we have to just type:

Finally commit your code to the repository and deploy it to Heroku:

and we should get endpoint to our service:

HerokuPushToMaster
HerokuPushToMaster

but before we test connection, we should also:

Add mongolab addon:

here you can get some information like: "Please verify your account to install this add-on plan (please enter a credit card) For more information, see https://devcenter.heroku.com/categories/billing Verify now at https://heroku.com/verify"

This means that even we use free addons we have to connect our account to our credit or debit card, we can do this on billings section after logging in on heroku webpage.

We are at home!!!

Now our service should be available on new URL:

https://appName.herokuapp.com/parse/classes/Cars

Test your remote Parse Server with iOS application

Firstly to didFinishLaunchingWithOptions with AppDelegate.swift copy following code:

then for example to viewDidLoad() copy and paste following code:

if in console you got this error:

"[Error]: The resource could not be loaded because the App Transport Security policy requires the use of a secure connection. (Code: 100, Version: 1.12.0)"

The recipe for resolving this issue you can find here.

If everything works, then we should just see: "Object has been saved" in Xcode console.

Voilà!!! 🙂

Sumarizing

After Migration everything should be transparent to our iOS application:)

When I have finished writing this post I have also discovered different tutorial on the same subject: Guide: How To Migrate Your Parse App To Parse Server With Heroku And MongoLab
which is much more detailed. If you are looking for more information about migration I think it can be really helpfull!:)

It would be great yo hear your opinion and your preferences on how you deal with migration prase:)

Have a nice day!:)

2 Comments

    • Maciej Piotrowski

      Hey,

      what exactly seems to be the problem? Did you mean that you have a Javascript code written for Parse.com platform that you cannot use after migration? Have you tried seeking for help from Parse.com support?

      Best regards,
      swifting.io

Leave a Reply


*