From 0e89102da11968c32bdb730a6ddea165bd58c66a Mon Sep 17 00:00:00 2001 From: SonOfLope Date: Tue, 24 Sep 2024 14:00:29 -0400 Subject: [PATCH] Issue #48: Adds step for fertiscan initial data insertion --- dockerfiles/postgres/README.md | 2 ++ dockerfiles/postgres/entrypoint.sh | 6 ++++++ dockerfiles/postgres/fetch_schema.py | 4 ++-- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/dockerfiles/postgres/README.md b/dockerfiles/postgres/README.md index 3ff6125..92a9c4d 100644 --- a/dockerfiles/postgres/README.md +++ b/dockerfiles/postgres/README.md @@ -20,6 +20,8 @@ are required: schema. - `BB_DATABASE_ID` – The ID of the specific database schema to be fetched from Bytebase. +- `PROJECT_NAME` – The name of the project to which the database belongs. This + is used to insert initial data into the database of FeritScan. ## Usage example diff --git a/dockerfiles/postgres/entrypoint.sh b/dockerfiles/postgres/entrypoint.sh index bad9eca..f658f59 100644 --- a/dockerfiles/postgres/entrypoint.sh +++ b/dockerfiles/postgres/entrypoint.sh @@ -6,6 +6,12 @@ pg_ctl -D "/var/lib/postgresql/data" -o "-c listen_addresses=''" -w start psql -U "$POSTGRES_USER" -d "$POSTGRES_DB" -f /app/schema.sql +if [ "$PROJECT_NAME" = "fertiscan" ]; then + curl -o /app/init_data.sql https://raw.githubusercontent.com/ai-cfia/ailab-datastore/main/datastore/db/bytebase/FertiScan/init_data.sql + + psql -U "$POSTGRES_USER" -d "$POSTGRES_DB" -f /app/init_data.sql +fi + pg_ctl -D "/var/lib/postgresql/data" -m fast -w stop exec docker-entrypoint.sh "$@" diff --git a/dockerfiles/postgres/fetch_schema.py b/dockerfiles/postgres/fetch_schema.py index ef26af6..5d3c085 100644 --- a/dockerfiles/postgres/fetch_schema.py +++ b/dockerfiles/postgres/fetch_schema.py @@ -26,7 +26,7 @@ def generate_token(): print(f"Failed to generate token: {response.status_code}, {response.text}") return None -def fetch_fertiscan_dev_schema(): +def fetch_schema(): token = generate_token() if token: schema_url = f"{BB_URL}/v1/instances/{INSTANCE_ID}/databases/{DATABASE_ID}/schema" @@ -46,4 +46,4 @@ def fetch_fertiscan_dev_schema(): print("No token generated, cannot fetch schema.") if __name__ == "__main__": - fetch_fertiscan_dev_schema() + fetch_schema()