Generate project in Hanami with PostgreSQL
In this blog post, I’ll show you how to setup a Hanami project with PostgreSQL as a database.
Setup
I’ll assume that you have ruby. If not - here you can find detailed instruction how to do it. I suggest to use ruby version manager, my favorite one is RVM.
Another prerequisite is gem dependency manager called Bundler.
gem install bundler
In this project I will also use PostgreSQL, so make sure you have it on your computer as well.
The next step is to install Hanami gem. You can do it by running this command:
gem install hanami
If this runs successfully, we can generate our first Hanami project:
hanami new shyshka --database=postgres
Now let’s go to the project folder and install gem dependencies using Bundler:
cd shyshka
bundle install
Our next step will be to generate the database. Database configuration can be found in .env.development
file and for test environment in .env.test
. After setting up correct credentials we can run this command:
bundle exec hanami db prepare
and this one to setup test environment database:
HANAMI_ENV=test bundle exec hanami db prepare
After that we can launch development server:
bundle exec hanami server
Now your web app is running and after typing http://localhost:2300
in your browser you should be able to see this:
Sum up
OK, that’s it for today. We managed to setup development environment, generate and run our first Hanami project with PostgreSQL as a database. In next post, we will learn how to add resources to the project and how to write tests. Code for Shyshka is open sourced and can be found here.
Thanks and see you soon!
Written on March 13, 2017