Requirements
PostgreSQL
Version: 12 or higherFeatures Used:
- TIMESTAMPTZ for timestamps
- Foreign key constraints
- Cascade deletes
Flyway
Version: Managed by Spring BootConfiguration:
- Baseline on migrate: enabled
- Baseline version: 0
Database Connection
Connection String Format
The application accepts PostgreSQL connection strings in two formats:The application automatically handles both formats. Spring Boot’s DataSource configuration normalizes Prisma-style URLs to JDBC format.
Example Connections
- Local
- Neon
- Render
Database Schema
The database uses PascalCase table names (e.g.,"User", "Task") with quoted identifiers, inherited from the original Prisma schema.
Tables Overview
User
Stores user accounts with email/password and Google OAuth support
Task
Individual tasks with status, priority, and relationships
Project
Project containers for organizing tasks
TaskType
Custom task types within projects
RefreshToken
JWT refresh tokens for authentication
Schema Details
- User
- Task
- Project
- TaskType
- RefreshToken
passwordis hashed using BCryptgeminiKeyis AES encryptedgoogleIdis populated for OAuth users
Flyway Migrations
The application uses Flyway to manage database schema changes. Migrations run automatically on application startup.Configuration
Migration Files
All migrations are located insrc/main/resources/db/migration/:
V1: Add Gemini Key to User
File: Adds support for storing encrypted Gemini API keys per user.
V1__add_gemini_key_to_user.sqlV2: Create Refresh Token Table
File: Implements JWT refresh token storage for long-lived sessions.
V2__create_refresh_token_table.sqlV3: Add Language to User
File: Adds internationalization support with Portuguese as default.
V3__add_language_to_user.sqlV4: Add Priority to Task
File: Enables task prioritization (LOW, MEDIUM, HIGH).
V4__add_priority_to_task.sqlMigration Naming Convention
Flyway migrations must follow this pattern:V1__initial_schema.sqlV2__add_user_settings.sqlV3__create_notifications_table.sql
Hibernate Configuration
The application uses Hibernate with specific settings:ddl-auto: validate means Hibernate only checks that entities match the database schema. It will not create or alter tables. All schema changes must be done via Flyway migrations.Physical Naming Strategy
ThePhysicalNamingStrategyStandardImpl preserves exact entity names, including PascalCase and quotes:
public."User"
Database Setup Instructions
- Local Development
- Neon (Serverless)
- Render PostgreSQL
Install PostgreSQL
Download and install PostgreSQL 12+ from postgresql.org
Troubleshooting
Migration Failed
Migration Failed
Problem: Flyway migration fails with SQL errorSolutions:
- Check database user has CREATE, ALTER, INSERT privileges
- Verify migration SQL syntax is correct
- Check
flyway_schema_historytable for failed entries - Manually fix database state and mark migration as resolved
Table Not Found
Table Not Found
Problem: Application throws “relation does not exist” errorSolutions:
- Ensure migrations have run successfully
- Check that table names use correct quoting:
\"User\" - Verify schema is set to
public - Check Flyway baseline version matches applied migrations
Connection Refused
Connection Refused
Problem: Cannot connect to PostgreSQL databaseSolutions:
- Verify database is running:
pg_isready -h localhost -p 5432 - Check connection string format
- Ensure firewall allows connections on port 5432
- For cloud databases, verify IP allowlist settings
Schema Validation Failed
Schema Validation Failed
Problem: Hibernate validation fails on startupSolutions:
- Ensure all migrations have been applied
- Check entity annotations match database schema
- Verify column types match between entity and database
- Set
ddl-auto: nonetemporarily to skip validation
Best Practices
Version Control
Always commit migration files to version control before deploying.
Test Migrations
Test migrations on a staging database before applying to production.
Backup Before Migration
Always backup production database before running new migrations.
Rollback Plan
Have a rollback strategy for failed migrations (e.g., restore from backup).
Related Documentation
Environment Variables
Configure database connection strings
Deployment
Deploy with database configuration
API Reference
Explore data model via API endpoints