leafo / lapis

A web framework for Lua and OpenResty written in MoonScript
http://leafo.net/lapis/
MIT License
3.12k stars 247 forks source link

Lapis Migrate Can't Connect to DB #656

Closed cycomachead closed 4 years ago

cycomachead commented 5 years ago

This seems odd to me. running lapis migrate doesn't connect to the DB. But I have the app running and using the same credentials and everything is being read just fine.

$ lapis migrate development --trace
k: database   v: snapcloud
k: host   v: 127.0.0.1:5432
k: password   v: snap-cloud-password
k: user   v: cloud
/usr/local/bin/lua5.1: /usr/local/share/lua/5.1/lapis/db/postgres.lua:61: host or service not provided, or not known
stack traceback:
    [C]: in function 'assert'
    /usr/local/share/lua/5.1/lapis/db/postgres.lua:61: in function </usr/local/share/lua/5.1/lapis/db/postgres.lua:52>
    (tail call): ?
    (tail call): ?
    (tail call): ?
    ...usr/local/share/lua/5.1/lapis/db/postgres/schema.lua:47: in function 'entity_exists'
    /usr/local/share/lua/5.1/lapis/db/migrations.lua:73: in function 'run_migrations'
    /usr/local/share/lua/5.1/lapis/cmd/actions.lua:282: in function </usr/local/share/lua/5.1/lapis/cmd/actions.lua:273>
    (tail call): ?
    (tail call): ?
    (tail call): ?
    ...local/lib/luarocks/rocks-5.1/lapis/1.7.0-1/bin/lapis:4: in main chunk
    [C]: ?

It's worth noting that the following works fine as work around:

$ lapis exec 'migrations = require("lapis.db.migrations")
migrations.run_migrations(require("migrations"))'
... SQL shown...
leafo commented 5 years ago

are you sure the environment you're running migrate with has connection information? the error seems like the config for that environment is missing connection information

cycomachead commented 5 years ago

Definitely the config/environment is working. I can run lapis server and things connect. I was running the app while trying to migrate. (Is that potentially a problem?) lapis exec seems to read the same environment.

leafo commented 4 years ago

Going to close this old issue. I'm assuming there was a mistake about how environment was specified. I've updated the docs on how the default environment is selected to help clear up any future issues with others.