koordinates / kart

Distributed version-control for geospatial and tabular data
https://kartproject.org
Other
527 stars 41 forks source link

Change PostGis Table name #890

Open geoteixeira opened 1 year ago

geoteixeira commented 1 year ago

Hello I have a project running on kart. The data is in postgis, now i need to change the postgis table name. I have looked into kart and it shows me the path to the working copy location but i cannot edit it. Any help? Thanks

geoteixeira commented 1 year ago

I mean i can change the postgis table name, however when i then try to pull/push changes from one repository to other it shows error. Writing the table name back to original sintax, it will work fine again.

olsen232 commented 1 year ago

Can you share the error you are seeing?

geoteixeira commented 1 year ago

Hi here it is:

127: Impossível localizar o procedimento especificado. From X:/CMC/INFO_GEOREFERENCIADA/POLICIA MUNICIPAL/TOPONIMIA NUMEROS POLICIA/Versionamento_Numeros_Policia_OS/.kart

geoteixeira commented 1 year ago

From what i can see it says "numeros_policia_landbase.numeracao_policia" does not exist". What i did was just changing the name of the destination table, because i do not want to have two tables with same name on postgis database. If i change destination table to origin name it works fine.

olsen232 commented 1 year ago

Ok, I found a bug or a regression - Kart should allow you to rename or delete a table without crashing. It should just detect that table as deleted, and you can commit that change if you want. This works with eg a GPKG working copy, but not with postgres - this is the bug / regression.

Kart does not detect table renames in the working copy - that is, it doesn't find try to detect that a new table with name X is the same as the old table with name Y, by comparing the contents of tables. This is less a bug, more a missing feature. For this reason, renaming any of the tables that Kart has already written the working copy won't work well in Kart: Kart will think you've deleted old table and added a new one, and the history of the old table won't be connected to the new table. This is probably not what you want.

Kart always checks out a table using the name of the Kart dataset - if Kart has stored a dataset numeracao_policia, it will try to create / update a table by that name in the working copy. This might be awkward for you if the working copy is in the same PG database as you originally updated the table from, so you can indeed end up with two tables of the same name. However, Kart has two features to mitigate this:

Firstly, you can configure the working copy schema. Every time you create a Kart repo, you can choose where to put the working copy. If you choose to put the working copy in a PG database, you can select a PG schema. You can choose any schema you like, but kart suggests one called <repository-name>_kart, which shouldn't collide with other tables. "Schema" here means one of the nested namespaces that PG allows you to create ie postgres:<hostname>/<database-name>/<schema>/<table-name>

Secondly, you can, if you so choose, rename the dataset as you import it. Eg kart import <import-source> <name-of-existing-table-to-import>:<name-of-newly-imported-dataset>