emilpriver / geni

Standalone database migration tool which works for Postgres, MariaDB, MySQL, Sqlite and LibSQL(Turso).
MIT License
192 stars 2 forks source link

Always shows Waiting for database to be ready #162

Closed dheeth closed 2 months ago

dheeth commented 2 months ago

Not sure what's the issue here but I am not able to run migrations for postgres.

is it because user of my postgres instance is postgres itself?

There is no mode to see verbose or debug

export DATABASE_URL="postgres://postgres:migrate@migrations-test:5432/orchestrator?sslmode=disable"

I am trying to do it in my test setup of docker containers

dheeth commented 2 months ago

I installed postgresql-client from the container I am trying to run the command and it says the postgresql url is accessible and able to connect to database

dheeth commented 2 months ago

Sometimes I get the error - [ERROR] error returned from database: syntax error at or near "-"

I tried changing the name of postgres host from migrations-test to mydb by adding entry in /etc/hosts but then it again gets stuck on Waiting for database to be ready

emilpriver commented 2 months ago

Hey, Waiting for database to be ready eccentially means that either the database is not up and running or the connection string is wrong.

Can you provide me with more information on how you run Geni? Is the docker container a standalone docker container and your running it from your computer? If so should the host be localhost

export DATABASE_URL="postgres://postgres:migrate@localhost:5432/orchestrator?sslmode=disable"

Dubbel check if the connection information is correct

dheeth commented 2 months ago

I have postgres in one container and then geni in another but both the containers are in same network and psql is able to connect to it from the container in which geni is running

dheeth commented 2 months ago

Verified the same connection information is working with other tools as expected

emilpriver commented 2 months ago

I am not able to help if I don't get more information. I am using geni and postgres in a docker container without any issues and this is my docker-compose file:

version: "3.9"
services:
  postgres:
    image: postgres:latest
    environment:
      - POSTGRES_DB=postgres
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
    ports:
      - "6432:5432"
  migration-postgres:
    image: ghcr.io/emilpriver/geni:v1.0.11
    environment:
      - DATABASE_URL=postgresql://postgres:postgres@postgres:5432/postgres
    volumes:
      - ./postgres/migrations:/migrations
    command: up

I think you need to dubble check that your setup is correct.

I am closing the issues as this don't seem to be related to Geni

emilpriver commented 2 months ago

Feel free to open if you are sure the issue is with Geni and not with your docker setup

dheeth commented 2 months ago

is there a way to increase verbosity so that I can check what's wrong with my database connection and what endpoint is it trying to hit?

emilpriver commented 2 months ago

No, it's not built into Geni but the endpoint your connecting to is the one your set as DATABASE_URL.

If your running geni in a docker container would I exec the container and try to connect to that host from that container. This is probably a issue with your docker network, adding stuff in /etc/hosts do I think is needed. Make sure that the postgtes container is actually public outside the network container.

dheeth commented 2 months ago

I have already tried /etc/hosts etc. Found the issue, did some hit and try and found out:

The orchestration for docker I am using is https://orbstack.dev There's some library issue

OrbStack ERROR: Dynamic loader not found: /lib64/ld-linux-x86-64.so.2

This usually means that you're running an x86 program on an arm64 OS without multi-arch libraries.
To fix this, you can:
  1. Use an Intel (amd64) container to run this program; or
  2. Install multi-arch libraries in this container.

This can also be caused by running a glibc executable in a musl distro (e.g. Alpine), or vice versa.

For more details and instructions, see https://go.orbstack.dev/multiarch

I was trying out multiple tools, dbmate etc. all worked fine. Not sure which library you need to run migrations.

Exposed container port of postgres and tried locally from mac to use geni and it worked fine with same connection url.

We are currently using golang-migrate/migrate which has structure same as geni i.e. separate files for up and down sql. That's why I wanted to try geni as well. The only issue for which I need geni is that it supports migrations table customization. Thanks for your time by the way

dheeth commented 2 months ago

I am using your arm64 build in the docker container, seems like the binary of arm is using some library of amd, not related to orbstack maybe

dheeth commented 2 months ago

Also, the error 12:40:27 [ERROR] error returned from database: syntax error at or near "-" is caused by

export DATABASE_MIGRATIONS_TABLE="geni-migrations"

table name can't have - it needs to be underscore. Messaging needs to be improved on these things

emilpriver commented 2 months ago

Also, the error 12:40:27 [ERROR] error returned from database: syntax error at or near "-" is caused by

export DATABASE_MIGRATIONS_TABLE="geni-migrations"

table name can't have - it needs to be underscore. Messaging needs to be improved on these things

This depends a bit on what database your using and I think this should be for the user to understand.

Good you found it. I might add a wiki soon and can add this information and improve the error message ☺️