Recently Heroku dropped their free tier which was a go-to platform for many pet projects. My simple Hanami flashcard application (I wrote about it in my previous article) got deleted and I still wanted to continue learning Italian, so I started looking for an alternative to Heroku.
A colleague recommended Railway.app to me, so I decided to give it a shot.
Eventually I managed to migrate the application, but there were a few problems that I experienced, so I thought to share with you how I managed to solve them.
The first deploy immediately failed. When I checked the deploy logs I've noticed that the application failed to connect to the Postgres database and well... that's understandable, because I didn't add the database to my project.
What I had to do was to click "+New" in my project and select a Postgres database.
Adding a Postgres to my project automatically injected necessary environment variable:
The next problem I faced was that the application wouldn't start due to missing environment variables.
So, what I did was that I went to my Heroku project settings and copy pasted the variables:
It turned out that Railway's deployment would only spin up the server without precompiling the assets which was different from Heroku and gave me a lot of headache before I managed to fix that.
What worked for me in the end was to:
SERVE_STATIC_ASSETSenviromnent variable as
- Add a file called
Procfileto the root directory of GitHub repository. The file has the following content
web: bundle exec hanami assets precompile && bundle exec hanami server -p $PORT
-p $PORT param.
$PORT variable is provided by default by Railway and it's super important to set it when starting the server, because otherwise Railway won't know where your application lives.
My app's database contained over a thousand of language flashcards and I didn't want to loose them.
So, what I've done is I went to Heroku's PostgreSQL "Durability" tab and downloaded an export file of my database:
Having that URL, I launched pgAdmin on my computed, connected to the database, clicked "Restore" and picked the previously exported Heroku database file:
The migration wasn't as seamless as expected, but eventually everthing seems to be working fine. Note that my application is a Hanami 1.3. application, so things may have changed in recently released 2.0. version.