Skip to content

Commit

Permalink
Merge pull request #49 from ai-cfia/48-as-a-devops-id-like-for-the-cu…
Browse files Browse the repository at this point in the history
…stom-postgres-image-to-also-seed-initial-data

Issue #48: Adds step for fertiscan initial data insertion
  • Loading branch information
SonOfLope authored Sep 24, 2024
2 parents 91bccd1 + 0e89102 commit 8eb53dc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions dockerfiles/postgres/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions dockerfiles/postgres/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 "$@"
4 changes: 2 additions & 2 deletions dockerfiles/postgres/fetch_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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()

0 comments on commit 8eb53dc

Please sign in to comment.