Fork me on GitHub
#datahike
<
2024-01-01
>
silian18:01:01

Happy New Year all. When trying to connect to local copy of postgres db, I am getting error:

Execution error (ExceptionInfo) at datahike.connector/ensure-stored-config-consistency (connector.cljc:127).
Configuration does not match stored configuration.
I can see from error messages that :stored-config is the credentials for my production postgres db. I am trying to create a local db to experiment with, without corrupting or overwriting data in production.

silian18:01:56

I created the copy using the heroku CLI which provides pg:pull to copy a db. (I believe it runs pg_dump.)

timo21:01:01

hey @U02U1T66REZ. Hmm, I know this problem.... don't know exactly how to get around it. It is a check that validates the connection. I did not implement this validation and don't exactly know how to get around it. I guess the config you were using in prod is stored inside the dump. Maybe @U1C36HC6N can chime in.

silian21:01:48

Thanks timo. I suppose I can try to find this row in local and just delete? (Afraid this might corrupt somehow.)

silian21:01:18

What is best practice to keep local and production instances of a Datahike db?

silian21:01:44

I would like to continue developing with Datahike but don't want to experiment on production db. What is best practice to create copy of prod to experiment with?

timo21:01:36

so the exception you are seeing above is expected. it's a way to globally identify databases that you can connect to. There should be a way to use a dump, not sure how though.

timo21:01:08

@U1C36HC6N wants to improve documentation and there were a lot of changes as of recently so it is needed

timo21:01:33

@U8KKDKPG8 might have an idea as well on how to use a dump from prod locally

👍 1
silian21:01:32

I suppose I could re-create the entire db by replaying all transactions. (I recall seeing this somewhere in docs, I think in migrate namespace.)

whilo18:01:25

@U02U1T66REZ Yes, this is always possible.

whilo18:01:07

We can relax this validation, it is mostly there to avoid accidentally overwriting existing DB's with the wrong configuration. @U02U1T66REZ What are your respective DB configs that clash?

silian22:01:28

I created a copy of production postgres db via heroku CLI pg:pull (which employs pg_dump). Local config I was attempting to connect to:

(def local-cfg
        {:store {:backend :jdbc
                 :dbtype "postgresql"
                 :host "localhost"
                 :port 5432
                 :user "postgres"
                 :password "whatever"
                 :dbname "from-heroku"}})
But the backup somewhere stores the production credentials, which look like this (sensitive redacted):
(def cfg
        {:store {:backend :jdbc
                 :dbtype "postgresql"
                 :host "ec2..."
                 :port 5432
                 :user "..."
                 :password "..."
                 :dbname "..."}})

whilo00:01:46

Hmm, I see. I think the host is the problem here.

silian01:01:59

How :host is specified?

silian01:01:49

Sorry if I'm not understanding

whilo01:01:39

I think this is where the consistency check failed. Could you use the "ec2...http://amazonaws.com" address in both cases (instead of localhost)?

silian01:01:02

Hmm, I think I am not being clear. The redacted values in cfg are my production credentials, which I know not to share and have replaced here with "..." The local db shows up in the Postgres GUI app I use to run a local Postgres server. When I try to connect to that local db, wouldn't the :host have to be "localhost"?

silian01:01:41

The cfg map that connects to production db is actually something like:

(def cfg 
  {:store 
    {:backend :jdbc
     :dbtype "postgresql" 
     :host "ec2..."  
     :port 5432  
     :user "ddxjb2hijdllx"  
     :password ; random string
     :dbname ; random string 
}})

silian02:01:19

IIUC, if I use the http://amazonaws.com EC2 address it will connect to the production db, which is not what I want. I want to connect to my local copy to experiment, etc.

whilo14:01:05

Then they are different databases and should never clash, i.e. for some reason during your connection it sees the other db. I am not sure why this is happening.

silian15:01:04

Yes, when I (def conn (d/connect local-cfg)) I get the error ensure-stored-config-consistency. I will try again and include more of the error output perhaps.

timo15:01:02

@U1C36HC6N isn't the stored-config stored in the konserve store which is a pg_dump from the prod-db? As I understand it we need a way to change the dump to accept the new configuration, isn't that the case here?

alekcz15:01:50

Yip that's correct. Doing a pg_dump would copy the config across. Hence the error. We'd need something like a create-new-from. Like a one time overide. Also, if I remember correctly the cache is part of the config check (accidentally I presume) which we need to fix.

whilo16:01:23

I see, we haven't covered this case yet. Maybe we should allow overriding the consistency check and setting a new config.

whilo16:01:41

@U02U1T66REZ Are you comfortable with open PRs?

whilo16:01:00

Ideally we want people to be able to hack Datahike to their needs.

👍 1
whilo16:01:41

Where hack means adapt 😉 We are not hacking around in the codebase, but it should be able to explore modifications easily.

silian16:01:21

I've never done one but that shouldn't stop me!

❤️ 1
timo16:01:04

Great! If you need help just ask here or put up the PR and we can discuss it there

silian23:01:08

I am attempting to use migrate instructions. I was able to create a successful export (an eavt-dump). I now see:

;; ... setup new-conn (recreate with correct schema)
(import-db new-conn "/tmp/eavt-dump")
What does ... setup new-conn (recreate with correct schema) mean? Is correct schema created automatically with import-db or I am required to actually d/transact all over again?

1
silian23:01:13

(I can [somewhat] inspect the eavt-dump file and I see schema transaction statements.)