Bugfix update for transfer of company data from mongo to sql (#121)

Fixed the following errors:

- Typo in readme.md
- Mongo delivers the last_update of an company as a string not as date.

Added:
- Entrypoint description in readme.md
This commit is contained in:
Philipp Horstenkamp 2023-09-13 19:14:36 +02:00 committed by GitHub
parent 507647d164
commit fea31e543b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 5 deletions

1
.gitignore vendored
View File

@ -217,3 +217,4 @@ replay_pid*
/unit-test-results.xml /unit-test-results.xml
/lbr-audit.md /lbr-audit.md
/.ruff_cache/ /.ruff_cache/
/Jupyter/test.ipynb

View File

@ -12,6 +12,13 @@
See the [CONTRIBUTING.md](CONTRIBUTING.md) about how code should be formatted and what kind of rules we set ourselves. See the [CONTRIBUTING.md](CONTRIBUTING.md) about how code should be formatted and what kind of rules we set ourselves.
## Available entrypoints
The project has currently the following entrypoint available:
- data-transfer > Transfers all the data from the mongodb into the sql db to make it available as production data.
- reset-sql > Resets all sql tables in the connected db.
## DB Connection settings ## DB Connection settings
To connect to the SQL db see [sql/connector.py](./src/aki_prj23_transparenzregister/utils/sql/connector.py) To connect to the SQL db see [sql/connector.py](./src/aki_prj23_transparenzregister/utils/sql/connector.py)
@ -20,7 +27,7 @@ To connect to the Mongo db see [connect]
Create a `secrets.json` in the root of this repo with the following structure (values to be replaces by desired config): Create a `secrets.json` in the root of this repo with the following structure (values to be replaces by desired config):
```json ```json
{ {
"postgres": { "postgres": {
"username": "postgres", "username": "postgres",
"password": "postgres", "password": "postgres",

View File

@ -209,6 +209,9 @@ def add_company(company: dict[str, Any], db: Session) -> None:
raise DataInvalidError( raise DataInvalidError(
"The company name needs to be valid (not empty and not only whitespace)." "The company name needs to be valid (not empty and not only whitespace)."
) )
last_update: date | None = (
date.fromisoformat(company["last_update"]) if company["last_update"] else None
)
company_entry = entities.Company( company_entry = entities.Company(
court_id=court_id, court_id=court_id,
hr=company["id"]["hr_number"].strip().replace(" ", " ").replace(" ", " "), hr=company["id"]["hr_number"].strip().replace(" ", " ").replace(" ", " "),
@ -216,7 +219,7 @@ def add_company(company: dict[str, Any], db: Session) -> None:
city=simplify_string(location.get("city")), city=simplify_string(location.get("city")),
zip_code=simplify_string(location.get("zip_code")), zip_code=simplify_string(location.get("zip_code")),
street=simplify_string(location.get("street")), street=simplify_string(location.get("street")),
last_update=company["last_update"], last_update=last_update,
) )
db.add(company_entry) db.add(company_entry)
db.commit() db.commit()
@ -335,7 +338,12 @@ def transfer_data(db: Session | None) -> None:
if db is None: if db is None:
db = get_session(JsonFileConfigProvider("./secrets.json")) db = get_session(JsonFileConfigProvider("./secrets.json"))
logger.remove() logger.remove()
logger.add(sys.stdout, level="INFO") logger.add(
sys.stdout,
level="INFO",
catch=True,
format="{time:YYYY-MM-DD HH:mm:ss} {level} {message}",
)
logger.add("data-transfer.log", level="INFO", retention=5) logger.add("data-transfer.log", level="INFO", retention=5)
reset_all_tables(db) reset_all_tables(db)
@ -352,4 +360,4 @@ def transfer_data(db: Session | None) -> None:
if __name__ == "__main__": if __name__ == "__main__":
transfer_data(get_session(JsonFileConfigProvider("./secrets.json"))) transfer_data(get_session("sqlite:///local-test-data.db"))

View File

@ -262,7 +262,7 @@ def company_generator(seed: int) -> dict[str, Any]:
"zip_code": get_random_zip() if random.choice([True, False]) else None, "zip_code": get_random_zip() if random.choice([True, False]) else None,
"street": get_random_string(20) if random.choice([True, False]) else None, "street": get_random_string(20) if random.choice([True, False]) else None,
}, },
"last_update": date(random.randint(2000, 2023), 1, 1), "last_update": date(random.randint(2000, 2023), 1, 1).isoformat(),
} }