Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #48: Adds step for fertiscan initial data insertion #49

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
Loading