Skip to content

Commit

Permalink
Merge pull request #967 from koordinates/fix-add-dataset-postgis
Browse files Browse the repository at this point in the history
Fix add-dataset for PostGIS working copies
  • Loading branch information
olsen232 committed Feb 9, 2024
2 parents e4b4de0 + a0e794c commit 32b00f8
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ _When adding new entries to the changelog, please include issue/PR numbers where
- Fixes a bug where even datasets marked as `--no-checkout` are checked out when the working copy is first created. [#954](https://github.com/koordinates/kart/pull/954)
- Fixes a bug where minor changes to auxiliary metadata (.aux.xml) files that Kart is supposed to ignore were preventing branch changes. [#957](https://github.com/koordinates/kart/pull/957)
- Improved performance when the user filters a diff request to only show certain features. [#962](https://github.com/koordinates/kart/pull/962)
- Clean up the empty directory if a clone fails outright [#963](https://github.com/koordinates/kart/issues/963)
- Clean up the empty directory if a clone fails outright. [#963](https://github.com/koordinates/kart/issues/963)
- Fixes `add-dataset` to work for PostGIS working copies. [#965](https://github.com/koordinates/kart/issues/965)

## 0.15.0

Expand Down
2 changes: 1 addition & 1 deletion kart/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def get_untracked_tables(repo):

if wc is not None and wc.session() is not None:
with wc.session() as sess:
wc_items = wc.adapter.list_tables(sess)
wc_items = wc.adapter.list_tables(sess, db_schema=wc.db_schema)
# Get all tables in working copy
all_tables = [table_name for table_name, title in wc_items.items()]
# Get tables shown in kart data ls
Expand Down
59 changes: 59 additions & 0 deletions tests/test_add_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
)
from kart.repo import KartRepo

import pytest

H = pytest.helpers.helpers()


def test_add_dataset_json_output__gpkg(cli_runner, data_working_copy):
new_table = "test_table"
Expand Down Expand Up @@ -190,3 +194,58 @@ def test_add_dataset_triggers__gpkg(cli_runner, data_working_copy):
}

assert output["kart.diff/v1+hexwkb"] == expected


def test_add_dataset__postgis(data_archive, cli_runner, new_postgis_db_schema):
with data_archive("points") as repo_path:
repo = KartRepo(repo_path)
H.clear_working_copy()
with new_postgis_db_schema() as (postgres_url, postgres_schema):
r = cli_runner.invoke(["create-workingcopy", postgres_url])
assert r.exit_code == 0, r.stderr

with repo.working_copy.tabular.session() as sess:
sess.execute(
f"""CREATE TABLE {postgres_schema}.dupe AS (SELECT * FROM {postgres_schema}.{H.POINTS.LAYER});"""
)
sess.execute(
f"""ALTER TABLE {postgres_schema}.dupe ADD PRIMARY KEY ({H.POINTS.LAYER_PK});"""
)

r = cli_runner.invoke(["status", "-ojson", "--list-untracked-tables"])
assert r.exit_code == 0, r.stderr

output = json.loads(r.stdout)
assert output["kart.status/v2"]["workingCopy"]["untrackedTables"] == [
"dupe"
]

r = cli_runner.invoke(
["add-dataset", "dupe", "-ojson", "-m" "test commit"],
env={
"GIT_AUTHOR_DATE": "2010-1-1T00:00:00Z",
"GIT_COMMITTER_DATE": "2010-1-1T00:00:00Z",
"GIT_AUTHOR_EMAIL": "user@example.com",
"GIT_COMMITTER_EMAIL": "committer@example.com",
},
)
assert r.exit_code == 0, r.stderr

output = json.loads(r.stdout)
COMMIT_SHA = output["kart.commit/v1"]["commit"]
ABBREV_COMMIT_SHA = output["kart.commit/v1"]["abbrevCommit"]
assert output == {
"kart.commit/v1": {
"commit": COMMIT_SHA,
"abbrevCommit": ABBREV_COMMIT_SHA,
"author": "user@example.com",
"committer": "committer@example.com",
"branch": "main",
"message": "test commit",
"changes": {
"dupe": {"meta": {"inserts": 2}, "feature": {"inserts": 2143}}
},
"commitTime": "2010-01-01T00:00:00Z",
"commitTimeOffset": "+00:00",
}
}

0 comments on commit 32b00f8

Please sign in to comment.