Prerequisites
- PostgreSQL 14 or higher installed
- Node.js 18+ for running Drizzle commands
- Access to create databases and users
PostgreSQL Installation
Ubuntu/Debian
macOS
Windows
Download and install from postgresql.orgDatabase Creation
1. Access PostgreSQL
2. Create Database and User
3. Configure Connection String
Add the connection string to your.env file:
Drizzle Configuration
PROVESA Web uses Drizzle Kit for database migrations. The configuration is defined indrizzle.config.js:
Configuration Options
Path to the database schema file. All schema definitions are exported from
./src/lib/server/db/schema.jsDatabase dialect. Set to
postgresql for PostgreSQL databases.Database connection URL from the
DATABASE_URL environment variable.Enable verbose logging for database operations. Set to
true for detailed output.Enable strict mode for schema validation. Set to
true to catch potential issues.Database Schema
The database schema is organized in multiple files undersrc/lib/server/db/schemas/:
- auth.schema.js - Better Auth tables (users, sessions, accounts)
- theme_config.schema.js - Theme customization settings
- footer.schema.js - Footer content and links
- legal_pages.schema.js - Legal pages (privacy, terms)
- hero_slides.schema.js - Homepage carousel slides
- products.schema.js - Product catalog
- nosotros_config.schema.js - About page configuration
- nosotros_page.schema.js - About page content
- sugerencias.schema.js - Customer suggestions
- sugerencias_config.schema.js - Suggestions configuration
- postulaciones.schema.js - Job applications
- empleo_sucursales.schema.js - Branch offices for jobs
- site_config.schema.js - Global site settings
- concursos.schema.js - Contests and promotions
Database Connection
The database connection is established insrc/lib/server/db/index.js:
- Uses the
postgres-jsdriver - Loads all schemas from
./schema.js - Validates that
DATABASE_URLis set
Running Migrations
1. Generate Migration
After modifying schema files, generate a migration:drizzle/ directory.
2. Apply Migrations
Apply pending migrations to the database:3. Push Schema (Development)
For rapid development, push schema changes directly without migrations:Seeding the Database
PROVESA Web includes seed files to populate initial data:Admin User Seed
The admin seed (src/lib/server/db/seeds/seed-admin.js) creates the initial administrator account using these environment variables:
ADMIN_NAME- Administrator display nameADMIN_EMAIL- Administrator email (login)ADMIN_PASSWORD- Administrator password
Theme Seed
The theme seed (src/lib/server/db/seeds/seed-theme.js) sets up default theme configuration.
Run Seeds
Drizzle Studio
Drizzle Studio provides a visual database browser:https://local.drizzle.studio where you can:
- Browse tables and data
- Run queries
- Edit records
- View relationships
Common Operations
Reset Database
Backup Database
Restore Database
Production Considerations
Connection Pooling
For production, configure connection pooling inDATABASE_URL:
SSL Connection
For remote databases, enable SSL:Managed PostgreSQL
Consider using managed PostgreSQL services:- Supabase - Free tier available, includes auth and storage
- Neon - Serverless PostgreSQL with generous free tier
- Railway - Simple deployment with PostgreSQL included
- AWS RDS - Enterprise-grade managed database
Troubleshooting
Connection Refused
Error:ECONNREFUSED 127.0.0.1:5432
Solution:
Authentication Failed
Error:password authentication failed for user
Solution:
- Verify username and password in
DATABASE_URL - Check PostgreSQL password with:
psql -U provesa_user -d provesa_db - Reset password if needed:
DATABASE_URL Not Set
Error:DATABASE_URL is not set
Solution:
- Ensure
.envfile exists in project root - Verify
DATABASE_URLis defined in.env - Restart your development server
Next Steps
- Environment Variables - Complete environment variable reference
- Email Setup - Configure email for password recovery
