DHI/terracotta

Postgres driver.create fails when database exists

Closed this issue · 5 comments

When calling driver.create, postgres driver throws an exception when a database exists, because it attempts to create one and the sql query returns an error.

Since it's not possible to obtain the driver in a different way, and the idea is to have a persistent storage, it would be great to have the driver creation only perform necessary steps:

  • create database when there isn't one
  • create tables only when they are not present

You are right that Terracotta requires a non-existing database that is then created and populated. Could you elaborate why that is a problem?

I'm building a service that has a bunch of initial cogs that take time to ingest.

This set of files is going to increase in time.

I wanted to retain the existing database or ingested files so that I don't need to re-ingest them every time the service is restarted or a new instance is created and when new files come in. I wanted to reuse that existing database.

Because the service uses postgres for other things, I was hoping to keep everything in postgres instead of inside an sqlite file.

I see. There's no need to call driver.create more than once. If the database already exists you can just skip it and use the other methods of driver to operate on it (such as ingesting new data). The database will be persistent.

Thanks. I think I was misled by the error message that asked me to make sure that I called the driver.create and then I failed to read the whole API doc, focusing on troubleshooting the details.

I was also hoping that I could make docker create the database and then Terracotta would just initialize it. I guess I just overly complicated this.

Sorry for wasting your time.

np, great to hear you sorted things out!