MerginMaps / db-sync

A tool for two-way synchronization between Mergin Maps and a PostGIS database
https://merginmaps.com
MIT License
45 stars 20 forks source link

Script unable to create base schema #89

Closed realmiketalbot closed 1 year ago

realmiketalbot commented 1 year ago

I've been able to successfully authenticate to both Mergin and my PostgreSQL cluster, but the script appears to be having trouble creating the base schema. Here's my (redacted) command:

sudo docker run -it \
  -e MERGIN__USERNAME=mergin_username \
  -e MERGIN__PASSWORD=mergin_password \
  -e CONNECTIONS="[{driver='postgres', conn_info='host=mydbhost sslmode=require dbname=_mergin user=db_user password=db_password', modified='postgis_sync_test_main', base='postgis_sync_test_base', mergin_project='workspace/postgis_sync_test', sync_file='sync_db.gpkg'}]" \
  lutraconsulting/mergin-db-sync:latest \
  python3 dbsync_daemon.py --init-from-gpkg

The postgis_sync_test_main schema is created successfully but without tables, and I receive the following (redacted) error message:

== starting mergin-db-sync daemon == version 1.1.2 ==
Logging in to Mergin...
Processing Mergin Maps project 'workspace/postgis_sync_test'
Connecting to the database...
Downloading latest Mergin Maps project workspace/postgis_sync_test to /tmp/dbsync/postgis_sync_test
Traceback (most recent call last):
  File "dbsync_daemon.py", line 63, in <module>
    main()
  File "dbsync_daemon.py", line 33, in main
    dbsync.dbsync_init(mc, from_gpkg=True)
  File "/mergin-db-sync/dbsync.py", line 666, in dbsync_init
    init(conn, mc, from_gpkg)
  File "/mergin-db-sync/dbsync.py", line 568, in init
    raise DbSyncError(f"The 'modified' schema exists but the base schema is missing: {conn_cfg.base}")
dbsync.DbSyncError: The 'modified' schema exists but the base schema is missing: postgis_sync_test_base
realmiketalbot commented 1 year ago

Some other potentially useful info:

wonder-sk commented 1 year ago

hi @realmiketalbot - sorry to hear you are having troubles.

Your command to run db-sync looks sensible, but the error you have posted here (The 'modified' schema exists but the base schema is missing) looks like this is not the first time you have run the command - and this error is just due to a previously failed initialization. Could you please try to delete the postgis_sync_test_main schema and re-run db-sync? In the output you should the see a line saying The base and modified schemas do not exist yet, going to initialize them - and then if the init fails, some other error should show up instead. It would be useful to post that error here so we can find out what went wrong...

realmiketalbot commented 1 year ago

You're right - I was mistakenly looking at the error message from a subsequent run of the script.

I was able to find the issue from this error message:

The base and modified schemas do not exist yet, going to initialize them ...
Error: copy failed!
GEODIFF: NOTICE:  schema "postgis_sync_test_main" does not exist, skipping
Error: postgres cmd error: ERROR:  permission denied for function postgis_typmod_type

What fixed it was dropping and recreating the database, this time setting the owner to my mergin user on create, then running CREATE EXTENSION postgis. I see now that this is exactly what's in the documentation, but I'm not using a local PostgreSQL installation so I had skipped over that.

Thanks!