Skip to content

Consider adding script to import seed data #28

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

Open
ryanlovett opened this issue Dec 5, 2024 · 1 comment
Open

Consider adding script to import seed data #28

ryanlovett opened this issue Dec 5, 2024 · 1 comment
Assignees
Labels
sys-admin Deployment, devops, etc

Comments

@ryanlovett
Copy link
Contributor

I wrote a simple script to import the seed data in a cluster environment, where psql was not included the docker container running the web app. It inherits the various DB_* environment variables. It might be worth including something similar in jhe/scripts/. Since it is part of the app's deployment and not the app itself, I didn't feel confident in creating a PR for it. So just for your consideration...

import os

import psycopg2

# Database connection parameters
db_params = {
    'dbname': os.environ.get('DB_NAME'),
    'user': os.environ.get('DB_USER'),
    'password': os.environ.get('DB_PASSWORD'),
    'host': os.environ.get('DB_HOST'),
    'port': os.environ.get('DB_PORT', 5432)
}

# Connect to the database
conn = psycopg2.connect(**db_params)
conn.autocommit = True
cursor = conn.cursor()

# Read and execute the SQL file
with open('/app/seed.sql', 'r') as sql_file:
    sql_commands = sql_file.read()

    # Execute the SQL commands
    cursor.execute(sql_commands)

# Close the connection
cursor.close()
conn.close()

print("Seed data imported successfully.")
@s1monj
Copy link
Collaborator

s1monj commented Dec 5, 2024

good idea and looks great thanks @ryanlovett - will find a spot for it

@s1monj s1monj self-assigned this Dec 5, 2024
@s1monj s1monj added the sys-admin Deployment, devops, etc label Dec 5, 2024
@ryanlovett ryanlovett mentioned this issue Mar 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sys-admin Deployment, devops, etc
Projects
None yet
Development

No branches or pull requests

2 participants