This directory contains scripts for setting up and seeding the database for the OrgChat application.
db_setup.py- Creates the PostgreSQL database if it doesn't existseed_db.py- Seeds the database with sample organization charts and employeessetup_and_seed.py- Runs both scripts in sequence for a complete setupinit_db.sql- SQL script for database creation and schema definitionrun_sql_init.py- Python script to run the SQL initialization
Make sure you have installed all required dependencies:
pip install -r ../requirements.txt
For the SQL initialization script, you also need:
- PostgreSQL command-line tools (
psql) installed and available in your PATH
The scripts use the following environment variables:
DATABASE_URL: The PostgreSQL connection string (default:postgresql://postgres:postgres@localhost:5432/orgchart)NUM_ORG_CHARTS: Number of organization charts to create (default: 100)
You can set these in a .env file in the project root or pass them as environment variables.
For a complete setup (create database and seed):
python setup_and_seed.pyTo initialize the database using raw SQL (alternative method):
python ../setup_database.py --sql-initThis will create the database and tables using the SQL script, which is useful for direct database setup.
To only create the database:
python db_setup.pyTo only seed the database:
python seed_db.py [number_of_org_charts]You can optionally specify the number of organization charts to create as a command-line argument.
# Create 50 organization charts
python seed_db.py 50
# Create database and 200 organization charts
NUM_ORG_CHARTS=200 python setup_and_seed.py
# Initialize with SQL and seed 50 organization charts
NUM_ORG_CHARTS=50 python ../setup_database.py --sql-init