Comments (2)
This snippet exhibits the expected behavior described above, when using lib/pq
directly:
package main
import (
"database/sql"
"os"
"testing"
_ "github.com/lib/pq"
"github.com/stretchr/testify/require"
)
func Test(t *testing.T) {
// $PGHOST is not defined in either the environment nor DATABASE_URL,
// so lib/pq will use a default value in its place.
t.Setenv("PGPORT", "16431")
t.Setenv("PGUSER", "some-user")
t.Setenv("PGPASSWORD", "some-password")
t.Setenv("DATABASE_URL", "postgres:///postgres?sslmode=disable")
db, err := sql.Open("postgres", os.Getenv("DATABASE_URL"))
require.NoError(t, err)
t.Cleanup(func() { assert.NoError(t, db.Close()) })
row := db.QueryRow("SELECT current_database(), version()")
require.NoError(t, row.Err())
var dbName, version string
require.NoError(t, row.Scan(&dbName, &version))
assert.Equal(t, "postgres", dbName)
assert.NotEmpty(t, version)
}
from dbmate.
dbmate's pg driver doesn't use the environment variables as default connection parameter values the way the libpq
C client library does, but I think that would be a useful enhancement, if you'd like to contribute it.
I don't know if this is so much a bug as it is a feature request for dbmate, but that's not especially important.
This is how lib/pq
handles supporting the environment variables, which may be interesting:
https://github.com/lib/pq/blob/3d613208bca2e74f2a20e04126ed30bcb5c4cc27/conn.go#L2002-L2082
I suppose if we're adding this capability in now, we should keep in mind what the latest Postgres 16 libpq
C client library documents as available vs. what the underlying lib/pq
Go client library supports, both as environment variables and connection string parameter keys. Ultimately, we can only support what the underlying lib/pq
implements, and not what the libpq
C client documents, so that's important to be aware of.
from dbmate.
Related Issues (20)
- Migration table is not found HOT 3
- Dbmate Unable to Create SchemaMigrations Table HOT 6
- Postgres Schemas with special characters have DBMate create migration tables then cannot find it again
- ClickHouse Cloud https connection doesn't work HOT 2
- Getting pq: syntax error at or near "transaction" when running migration with transaction:false HOT 7
- The migration lock is not released after terminating the migration HOT 2
- Comments (on columns) that include line breaks are never created. HOT 1
- dbmate requires each migration to define a down block with '-- migrate:down' when it defined HOT 5
- No Zookeeper configuration in server config
- Support all DSN variants for clickhouse DATABASE_URL HOT 8
- Wait for Postgres to be ready HOT 3
- Add a section to the README documenting how environment variables are used by dbmate
- Table aliases don't work with ClickHouse HOT 2
- Add `--wait-interval` and `$DBMATE_WAIT_INTERVAL` to make wait interval configurable at runtime HOT 7
- The latest release is missing all the binaries HOT 2
- Could not open extension control file "/share/extension/http.control" HOT 2
- Embedded FS on Windows HOT 2
- `make docker-all` timeout when run locally. HOT 1
- DBMate always delets my database anytime I run a migration HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dbmate.