Skip to content

Commit

Permalink
[DH-5512] Fix refresh endpoint and uri validation (#413)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcjc712 authored Feb 28, 2024
1 parent 8e45fb9 commit ea3e009
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
21 changes: 8 additions & 13 deletions dataherald/db_scanner/sqlalchemy.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,28 +64,23 @@ def refresh_tables(
metadata: dict = None,
) -> list[TableDescription]:
stored_tables = repository.find_by({"db_connection_id": str(db_connection_id)})
stored_tables_list = [table.table_name for table in stored_tables]

rows = []
for table_description in stored_tables:
if table_description.table_name not in tables:
table_description.status = TableDescriptionStatus.DEPRECATED.value
rows.append(repository.save_table_info(table_description))
else:
rows.append(TableDescription(**table_description.dict()))

for table in tables:
if table not in stored_tables_list:
rows.append(
repository.save_table_info(
TableDescription(
db_connection_id=db_connection_id,
table_name=table,
status=TableDescriptionStatus.NOT_SCANNED.value,
metadata=metadata,
)
rows.append(
repository.save_table_info(
TableDescription(
db_connection_id=db_connection_id,
table_name=table,
status=TableDescriptionStatus.NOT_SCANNED.value,
metadata=metadata,
)
)
)
return rows

@override
Expand Down
2 changes: 1 addition & 1 deletion dataherald/sql_database/models/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class DatabaseConnection(BaseModel):

@classmethod
def validate_uri(cls, input_string):
pattern = r"([^:/]+)://([^/]+)/([^/]+)"
pattern = r"([^:/]+):/+([^/]+)/([^/]+)"
match = re.match(pattern, input_string)
if not match:
raise InvalidURIFormatError(f"Invalid URI format: {input_string}")
Expand Down

0 comments on commit ea3e009

Please sign in to comment.