Skip to content

Commit

Permalink
fix generate_database action (#479)
Browse files Browse the repository at this point in the history
* fix generate_database action

* remove unused parts of script
  • Loading branch information
kelle authored Apr 2, 2024
1 parent 593669f commit 45e67c5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 14 deletions.
18 changes: 4 additions & 14 deletions .github/workflows/gen-db.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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: '[email protected]'
Expand Down
29 changes: 29 additions & 0 deletions simple/utils/generate_database.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 45e67c5

Please sign in to comment.