Skip to content

Commit

Permalink
fix #167 (#168)
Browse files Browse the repository at this point in the history
  • Loading branch information
smnorris committed Feb 19, 2024
1 parent 480e407 commit fa6c975
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Changes
=======

0.10.1 (2024-02-19)
------------------
- check that table to be refreshed exists when using bc2pg --refresh (#167)

0.10.0 (2024-02-19)
------------------
- store known primary keys in repository (data/primary_keys.json)
Expand Down
2 changes: 1 addition & 1 deletion bcdata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
"https://raw.githubusercontent.com/smnorris/bcdata/main/data/primary_keys.json"
)

__version__ = "0.10.1dev0"
__version__ = "0.10.1"
9 changes: 8 additions & 1 deletion bcdata/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,9 +395,16 @@ def bc2pg(
elif refresh and schema:
schema_target = schema
elif refresh and not schema:
schema_target, t = bcdata.validate_name(dataset).lower().split(".")
schema_target, table = bcdata.validate_name(dataset).lower().split(".")
if refresh:
db = Database(db_url)
schema = "bcdata"
if not table:
table = bcdata.validate_name(dataset).lower().split(".")
if schema_target + "." + table not in db.tables:
raise ValueError(
f"Cannot refresh, {schema_target}.{table} not found in database"
)
out_table = bcdata.bc2pg(
dataset,
db_url,
Expand Down
4 changes: 4 additions & 0 deletions bcdata/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ def refresh(self, schema, table):
)
self.execute(dbq)
self.drop_table("bcdata", table)
else:
raise ValueError(
f"Target table {schema}.{table} does not exist in database"
)

def define_table(
self,
Expand Down
17 changes: 17 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,20 @@ def test_bc2pg_refresh():
assert AIRPORTS_TABLE.lower() in DB_CONNECTION.tables
assert len(q) == 1
DB_CONNECTION.execute("drop table " + AIRPORTS_TABLE.lower())


def test_bc2pg_refresh_fails_table_does_not_exist():
runner = CliRunner()
result = runner.invoke(
cli,
[
"bc2pg",
AIRPORTS_TABLE,
"--db_url",
DB_URL,
"--count",
"1",
"--refresh",
],
)
assert result.exit_code == 1

0 comments on commit fa6c975

Please sign in to comment.