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

cockroachdb: database is never created #150

Open
dakraus opened this issue Dec 6, 2022 · 1 comment
Open

cockroachdb: database is never created #150

dakraus opened this issue Dec 6, 2022 · 1 comment

Comments

@dakraus
Copy link

dakraus commented Dec 6, 2022

In case CockroachDB is used as backend and KIND_ENDPOINT points at a non-existing database, the PostgreSQL driver does not create the corresponding database.

Steps to reproduce:

  • Point KINE_ENDPOINT at non-existing database in file test-run-cockroachdb (e.g. KINE_ENDPOINT="postgres://root@$ip:$port/kine?sslmode=disable$extra_params")
  • Run tests with scripts/test
  • kine fails with:
[cockroachdb-v20.2] time="2022-11-29T12:51:42Z" level=info msg="starting metrics server path /metrics"
[cockroachdb-v20.2] time="2022-11-29T12:51:42Z" level=info msg="Configuring postgres database connection pooling: maxIdleConns=2, maxOpenConns=0, connMaxLifetime=0s"
[cockroachdb-v20.2] time="2022-11-29T12:51:42Z" level=info msg="Configuring database table schema and indexes, this may take a moment..."
[cockroachdb-v20.2] time="2022-11-29T12:51:42Z" level=trace msg="SETUP EXEC : CREATE TABLE IF NOT EXISTS kine ( id SERIAL PRIMARY KEY, name VARCHAR(630), created INTEGER, deleted INTEGER, create_revision INTEGER, prev_revision INTEGER, lease INTEGER, value bytea, old_value bytea );"
[cockroachdb-v20.2] time="2022-11-29T12:51:42Z" level=fatal msg="building kine: pq: no database or schema specified"

Reason:
It seems that (at least in my local setup), the following code is causing this behavior:

err = db.Ping()
// check if database already exists
if _, ok := err.(*pq.Error); !ok {
return err
}

db.Ping() in this case returns nil instead of an error and therefore the following type assertion fails and nil is returned to the caller.

@brandond
Copy link
Member

brandond commented Dec 6, 2022

Hmm, so CockroachDB allows pinging a nonexistent DB. That seems like a problem, but I'm not quite sure how to handle it since we're just using the generic postgres driver, which cockroachdb claims to be compliant with.

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

No branches or pull requests

2 participants