diff --git a/.github/workflows/gen-db.yml b/.github/workflows/gen-db.yml index 0284fb0ae..1b7f48330 100644 --- a/.github/workflows/gen-db.yml +++ b/.github/workflows/gen-db.yml @@ -5,11 +5,11 @@ 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 workflow_dispatch: # manual execution release: types: [published] - branches: [main] jobs: build: @@ -34,26 +34,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' destination_repo: 'SIMPLE-AstroDB/SIMPLE-binary' destination_branch: 'main' user_email: 'github-actions@github.com' diff --git a/simple/utils/generate_database.py b/simple/utils/generate_database.py new file mode 100644 index 000000000..17fd0a308 --- /dev/null +++ b/simple/utils/generate_database.py @@ -0,0 +1,29 @@ +# Script to generate database from JSON contents +# This gets run automatically with Github Actions + +import argparse +import sys +from astrodb_utils import load_astrodb + +sys.path.append("./") +from simple.schema import REFERENCE_TABLES +from simple.schema import * + +# Location of source data +DB_NAME = "SIMPLE.sqlite" +DB_PATH = "data/" + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description="Generate the SIMPLE database") + args = parser.parse_args() + + # Run the loader for the specified DB architecture + db = load_astrodb( + DB_NAME, data_path=DB_PATH, recreatedb=True, reference_tables=REFERENCE_TABLES + ) + print("New database generated.") + + # Close all connections + db.session.close() + db.engine.dispose()