amberframework / amber

A Crystal web framework that makes building applications fast, simple, and enjoyable. Get started with quick prototyping, less bugs, and blazing fast performance.
https://amberframework.org
MIT License
2.57k stars 206 forks source link

Cannot connect to database while following Getting Started guide but with the provided Docker Compose db #1232

Closed ZimbiX closed 3 years ago

ZimbiX commented 3 years ago

Description

Following Amber's Getting Started guide, but using the provided Docker Compose db service instead of installing Postgres, results in an error, since the database does not expose its port:

$ docker-compose up -d db
$ amber db create migrate
Connection unsuccessful: postgres://postgres:password@localhost:5432/postgres

I wasn't sure whether to file this issue here or on the docs repo, since it probably affects both. I chose here because I reckon there's a code change required: to expose the port.

Steps to Reproduce

Follow the Getting Started guide for the most part:

  1. Install dependencies:

    1. Install crystal and amber:

      $ yay -S amber
    2. Install a database:

      Instead of the linked official Postgres installation guide, prepare to make use of the included Docker Compose Postgres db service by installing Docker Compose and Docker:

      $ yay -S docker-compose
  2. Generate a new Amber application

    $ amber new pet-tracker && cd pet-tracker
  3. Generate a resource

    $ amber g scaffold Pet name:string breed:string age:integer
  4. Create and migrate the database

    First, start the db Docker Compose service:

    $ docker-compose up -d db

    Now attempt to migrate it:

    $ amber db create migrate
    Connection unsuccessful: postgres://postgres:password@localhost:5432/postgres

Expected behavior: The database gets migrated

Actual behavior: Error shown

Reproduces how often: Always

Versions

$ amber --version
Amber CLI (amberframework.org) - v0.35.0

$ crystal --version
Crystal 0.35.1 (2020-06-21)

LLVM: 10.0.0
Default target: x86_64-pc-linux-gnu

$ uname -a
Linux ZimbiX-GreenSync 5.8.8-arch1-1 #1 SMP PREEMPT Wed, 09 Sep 2020 18:59:45 +0000 x86_64 GNU/Linux

Resolution

I propose that:

I have other suggestions regarding the Docker Compose setup; I might make separate issues for those.

eliasjpr commented 3 years ago

@ZimbiX thanks for bringing this up. This looks like a very simple change and backwards compatible. You can go ahead and open the PR and we will review it. Please ensure that any documentation is updated with this change.

Thank you @ZimbiX

kcutshah30 commented 3 years ago

Are there any updates?

eliasjpr commented 3 years ago

Addressed with https://github.com/amberframework/amber/pull/1257