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

fix generate_database action #479

Merged
merged 13 commits into from
Apr 2, 2024
19 changes: 5 additions & 14 deletions .github/workflows/gen-db.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
name: Generate Database

on:
# More details on trigger events: https://docs.github.com/en/actions/reference/events-that-trigger-workflows
# More details on trigger events:
# https://docs.github.com/en/actions/reference/events-that-trigger-workflows
pull_request: # added for testing
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not do this on a pull_request, as this action essentially builds the binary file for purposes of the website. That should only be done when we are ready to push a change, not when someone opens a pull request.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am pretty sure I added this here just so it would run on this PR. in order to test the script.

workflow_dispatch: # manual execution
release:
types: [published]
branches: [main]

jobs:
build:
Expand All @@ -34,26 +35,16 @@ jobs:

- name: Generate sqlite (file) database
run: |
python scripts/tutorials/generate_database.py sqlite
python simple/utils/generate_database.py
working-directory: .

# The postgres database creation can take a while on the hobby-dev tier in Heroku
# Disabling until we have a better idea on how to use this
# - name: Generate postgres (Heroku) database
# env:
# SIMPLE_DATABASE_URL: ${{secrets.SIMPLE_DATABASE_URL}}
# run: |
# pip install psycopg2
# python scripts/tutorials/generate_database.py postgres
# working-directory: .

- name: Push database file
uses: dmnemec/copy_file_to_another_repo_action@main
# Details for this action at https://github.com/marketplace/actions/push-a-file-to-another-repository
env:
API_TOKEN_GITHUB: ${{ secrets.SIMPLE_TOKEN }}
with:
source_file: 'SIMPLE.db'
source_file: 'SIMPLE.sqlite'
Comment on lines -56 to +46
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once this is merged, we will need to go to the binary repo and delete the old db file to avoid confusion.

destination_repo: 'SIMPLE-AstroDB/SIMPLE-binary'
destination_branch: 'main'
user_email: '[email protected]'
Expand Down
45 changes: 45 additions & 0 deletions simple/utils/generate_database.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Script to generate database from JSON contents
# This gets run automatically with Github Actions

import argparse
import sys
import os
from astrodb_utils import load_astrodb

sys.path.append("./")
from simple.schema import *
from simple.schema import REFERENCE_TABLES

# Location of source data
DB_PATH = "data"
DB_NAME = "SIMPLE.sqlite"


if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Generate the SIMPLE database")
# parser.add_argument(
# "architecture",
# choices=["sqlite", "postgres"],
# help="Database architecture to use.",
# )
# parser.add_argument(
# "connection_string",
# nargs="?",
# help="Connection string to use for non-sqlite databases.",
# )

args = parser.parse_args()

# Get the connection string for any non-sqlite database
# if args.connection_string is not None:
# connection_string = args.connection_string
# else:
connection_string = os.getenv("SIMPLE_DATABASE_URL", default="")
kelle marked this conversation as resolved.
Show resolved Hide resolved

# Run the loader for the specified DB architecture
db = load_astrodb(DB_NAME, reference_tables=REFERENCE_TABLES)
print("New database generated.")

# Close all connections
db.session.close()
db.engine.dispose()
Loading