Skip to content

Consider adding script to import seed data #28

Open
@ryanlovett

Description

@ryanlovett

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.")

Metadata

Metadata

Assignees

Labels

sys-adminDeployment, devops, etc

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions