Files
asle/DATABASE_SETUP.md
defiQUG 4c33f65d10 Complete initial setup: dependencies, Prisma fixes, and database setup guides
- Install backend and frontend dependencies
- Fix Prisma schema BigInt default values
- Generate Prisma client
- Create database setup script and documentation
- Add DATABASE_SETUP.md guide
2025-12-03 22:13:39 -08:00

2.6 KiB

Database Setup Guide

This guide helps you set up the PostgreSQL database for ASLE backend.

Prerequisites

  • PostgreSQL 15+ installed and running
  • Access to create databases

Quick Setup

# Start PostgreSQL container
docker-compose up -d postgres

# The database will be created automatically with:
# - User: asle
# - Password: asle_password
# - Database: asle

Update backend/.env:

DATABASE_URL="postgresql://asle:asle_password@localhost:5432/asle?schema=public"

Option 2: Local PostgreSQL

  1. Create database:

    # As postgres superuser
    sudo -u postgres psql -c "CREATE DATABASE asle;"
    
    # Or create a user first
    sudo -u postgres psql -c "CREATE USER asle WITH PASSWORD 'your_password';"
    sudo -u postgres psql -c "CREATE DATABASE asle OWNER asle;"
    
  2. Update backend/.env:

    DATABASE_URL="postgresql://asle:your_password@localhost:5432/asle?schema=public"
    

Option 3: Using Existing PostgreSQL

If you have PostgreSQL running with different credentials:

  1. Create database:

    psql -U your_user -c "CREATE DATABASE asle;"
    
  2. Update backend/.env:

    DATABASE_URL="postgresql://your_user:your_password@localhost:5432/asle?schema=public"
    

Running Migrations

After setting up the database:

cd backend

# Generate Prisma client
npm run prisma:generate

# Run migrations
npm run prisma:migrate

# Initialize database with default configs
npm run setup:db

# Create admin user
npm run setup:admin

Troubleshooting

Authentication Failed

If you see Authentication failed:

  1. Check PostgreSQL is running:

    pg_isready -h localhost -p 5432
    
  2. Verify credentials in backend/.env

  3. Test connection:

    psql $DATABASE_URL -c "SELECT version();"
    

Database Already Exists

If database already exists, migrations will still work:

npm run prisma:migrate

Permission Denied

If you get permission errors:

# Grant permissions
sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE asle TO your_user;"

Connection String Format

postgresql://[user]:[password]@[host]:[port]/[database]?schema=public

Examples:

  • postgresql://postgres@localhost:5432/asle?schema=public (no password)
  • postgresql://asle:password@localhost:5432/asle?schema=public (with password)
  • postgresql://user:pass@db.example.com:5432/asle?schema=public (remote)

Next Steps

After database is set up:

  1. Run migrations
  2. Initialize database
  3. Create admin user
  4. Start backend: npm run dev