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

GPKG working copy adds auto_int_pk for no reason if pk column isn't first column #455

Closed
olsen232 opened this issue Jul 9, 2021 · 0 comments

Comments

@olsen232
Copy link
Collaborator

olsen232 commented Jul 9, 2021

GPKG requires that tables have a single integer primary key.
GPKG doesn't require that that PK is in the first column.

If a dataset has data that doesn't conform to the GPKG requirement, we demote any of the PK columns that it does have to be not PK columns, but only UNIQUE NOT NULL, and we add a new PK column called auto_int_pk that conforms to GPKG spec.

We shouldn't be doing this in the case where the dataset already conforms to the GPKG requirement, even if the PK column is not the first column. The issue is that we weren't recognizing datasets as conformant when the PK wasn't the first column, and so were adding in the auto_int_pk column. More confusingly, the code that hide edits that were made automatically and necessarily by Kart, wasn't hiding this added column, so you would see spurious diffs like the following on a fresh checkout:

--- nz_primary_road_parcels:meta:schema.json
+++ nz_primary_road_parcels:meta:schema.json
  [
+   {
+     "id": "620a30b4-f793-53ff-0f6b-49003d59aa66",
+     "name": "auto_int_pk",
+     "dataType": "integer",
+     "primaryKeyIndex": 0,
+     "size": 32
+   },
    {
      "id": "b918dd54-73dc-4752-894a-1078e7360712",
      "name": "shape",
      "dataType": "geometry",
      "geometryType": "GEOMETRY",
      "geometryCRS": "EPSG:4167"
    },
-   {
-     "id": "e2c7c7c9-c017-4d66-894b-de4c599231e8",
-     "name": "id",
-     "dataType": "integer",
-     "primaryKeyIndex": 0,
-     "size": 32
-   },
+   {
+     "id": "be3f60fb-0890-f9ec-649d-1c41f4da0369",
+     "name": "id",
+     "dataType": "integer",
+     "size": 32
+   },
...
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

1 participant