This document explains the automated database initialization process implemented for the production Docker environment.
The application has been configured to automatically initialize the database tables when the container starts. This ensures that the application will work correctly without manual intervention.
-
Container Startup: When the Docker container starts, it runs
production-server.js. -
Database Initialization Check: The server checks if it needs to initialize the database by running
initialize-database.js. -
Table Creation: If the database tables don't exist, the initialization script runs
drizzle-kit pushto create all necessary tables based on the schema defined inshared/schema.ts. -
Application Start: Once the database is properly initialized, the application starts serving requests.
The docker-compose.yml file has been configured to:
- Wait for the PostgreSQL database to be healthy before starting the application
- Set up proper health checks for both the database and the application
- Configure all necessary environment variables
If the automatic initialization fails, you can:
-
Start the PostgreSQL container only:
docker-compose up -d postgres -
Connect to the database directly and create the tables:
docker-compose exec postgres psql -U ${PGUSER} -d ${PGDATABASE} -
Or run the initialization script manually:
docker-compose exec app node initialize-database.js
If you encounter issues with database initialization:
-
Check the logs for error messages:
docker-compose logs app -
Ensure the database container is running and healthy:
docker-compose ps -
Verify database connection settings in the environment variables:
docker-compose config
For production deployments, ensure:
- All required environment variables are set in a secure manner
- Database backup and restore procedures are in place
- The database has sufficient resources for the expected load