Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add instructions to setup PostgreSQL #251

Merged

Conversation

mzeleniuk
Copy link
Contributor

When generated a new Hanami project with PostgreSQL I was a bit confused how to setup a database on my local machine (I was not able to start hanami server because of database connection error). It's not well documented yet so I spend some time to find the answer.
I'm not sure where is the best place to show the setup instructions but I hope it will be helpful for new Hanami users.
Particularly closes #229.
Cheers!
postgresql setup

@TiteiKo
Copy link
Contributor

TiteiKo commented Dec 15, 2016

Hi @mzelenyuk and thank you for the time spent on this!

As I said in the issue, I think it should be a full guide page, detailing the configuration for the 3 mainly used DBs. The Getting Started guide should stay clear of this, and only have a link to the previously mentioned Guide.

Do you think you'd have time to make a new guide page and adapt what you wrote here as a section of that guide?

@mzeleniuk
Copy link
Contributor Author

Hi @TiteiKo! Yeah, I think a new Guide page for database configuration is the best case.
And sure, I'm able to do it if you'll help me with its title (I assume the "Database configuration" will be fine, what do you think?) and placement in right navigation list.

@TiteiKo
Copy link
Contributor

TiteiKo commented Dec 15, 2016

I'm not the best to answer this, so I'll let the amazing people of @hanami/documentation answer your questions!

@mzeleniuk
Copy link
Contributor Author

@TiteiKo Great, thanks!

@davydovanton
Copy link
Member

@mzelenyuk good idea 👍
But I think we need to create this section is more general (not only for psql DB).

What do you think, maybe will better to write something like this?

Before starting your server, you need to configure DB link in .env* files.
Open this file for each environment and update DB_URL for your DB.
For example, for psql, you need to do this and this ...

/cc @cllns

@mzeleniuk
Copy link
Contributor Author

@davydovanton Sounds good. We may consider to place each DB's specific content under its own header (see screenshot) and tell how to create a table for each environment to make database setup more easier for the beginners.

db config

@davydovanton
Copy link
Member

@mzelenyuk awesome 👍

@mzeleniuk
Copy link
Contributor Author

@davydovanton Thanks! So what's the plan now? Waiting for @cllns response?

@davydovanton
Copy link
Member

yep :)

@cllns
Copy link
Member

cllns commented Dec 16, 2016

Yes, I think this should be its own guide, not a part of the Getting Started guide.

We also have a Environment Variables guide planned, but I don't think people would know to look their for database configuration/info.

I think this should go under the 'Models' section.

@jodosha
Copy link
Member

jodosha commented Dec 17, 2016

@mzelenyuk Hi and thanks for this PR.


TL;DR: We can merge this PR to help new people confused by Postgres complexity, but in the long run we should use Sqlite for the getting started guide.


The less details we present in the getting started guide, the less we overwhelm newcomers.

While having an env vars guide is desirable as reference, we should remove env vars from the getting started guide.

To solve the problem that @mzelenyuk ran into, we should abandon Postgres in the getting started guide in favor of Sqlite. There are a few advantages:

  1. Sqlite is the default database when we generate a new project (hanami new bookshelf)
  2. Postgres is great, but we don't use its powerful features in the getting started guide
  3. Sqlite doesn't require developer's attention to fiddle with env vars and check if a server is running.

@TiteiKo
Copy link
Contributor

TiteiKo commented Dec 17, 2016

@jodosha The getting started guide already uses sqlite, see #238

@mzeleniuk mzeleniuk force-pushed the add-postgresql-setup-instructions branch from 892c615 to 8e6911a Compare December 19, 2016 10:19
@mzeleniuk
Copy link
Contributor Author

Done (see attached screenshots). By now it has a section only for PostgreSQL. We can add more sections later.
Also before merge may anyone check spelling one more time please? :)

database configuration page
navigation list


# Overview

Before starting your server, you need to configure database link in <code>.env*</code> files.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

configure the database link


## Prepare tables in database

After your database variables setup is done you need to create a table in your database before you're be able to launch a development server.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you need to create the database and run the migrations before being able to launch a development server.

% bundle exec hanami db prepare
```

To create a table in database for the test environment, enter:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To setup your test environment database, enter:

DATABASE_URL="postgres://username:password@localhost/bookshelf_test"
```

## Prepare tables in database
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be at the same level of title as Overview

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setup your database

@mzeleniuk
Copy link
Contributor Author

@TiteiKo Fixed. Thanks for help! :)

@cllns
Copy link
Member

cllns commented Dec 19, 2016

@mzelenyuk Can you rename this Models -> Database Configuration (or something like this, if that's too long for the layout) instead of Database Configuration -> Overview?

DB config only affects Models so I think it fits well in that group :)

@mzeleniuk
Copy link
Contributor Author

@cllns Yes, sure.

updated navigation list

@jodosha
Copy link
Member

jodosha commented Dec 21, 2016

@TiteiKo

The getting started guide already uses sqlite, see #238

Wonderful! 💯

@jodosha
Copy link
Member

jodosha commented Dec 21, 2016

@cllns @TiteiKo If you think this is ready, please merge it 😉

@TiteiKo
Copy link
Contributor

TiteiKo commented Dec 21, 2016

@cllns Good for me

Copy link
Contributor

@AlfonsoUceda AlfonsoUceda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, once you change these comments I'll be happy to merge ;)


```
# .env.development
DATABASE_URL="postgres://username:password@localhost/bookshelf_development"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mzelenyuk could you change postgres:// to postgresql://? We are generating postgresql:// because it supporter in MRI and JRuby ;)


```
# .env.test
DATABASE_URL="postgres://username:password@localhost/bookshelf_test"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the same here.

@mzeleniuk
Copy link
Contributor Author

@AlfonsoUceda Yes, sure! :)

@AlfonsoUceda AlfonsoUceda merged commit 82e7303 into hanami:build Jan 30, 2017
@AlfonsoUceda
Copy link
Contributor

Thanks @mzelenyuk ;)

@mzeleniuk mzeleniuk deleted the add-postgresql-setup-instructions branch January 31, 2017 09:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Database configuration guide
6 participants