Files

2.3 KiB

Database Connection Fixed

Issues Resolved

1. Environment Variables Not Loading

  • Problem: .env file wasn't being found when running the executable from build directory
  • Solution: Updated main.go to try loading .env from multiple paths (./, ../, ../../)

2. MySQL UUID Support

  • Problem: MySQL doesn't have native uuid type like PostgreSQL - it uses gen_random_uuid() which doesn't exist
  • Solution: Changed all UUID fields from type:uuid;default:gen_random_uuid() to type:char(36)

3. VARCHAR in Unique Indexes

  • Problem: MySQL 5.7+ requires VARCHAR columns in unique indexes to specify a key length
  • Solution: Changed string fields to use type:varchar(255) for indexed/unique columns:
    • User.Email: gorm:"type:varchar(255);uniqueIndex;not null"
    • User.Username: gorm:"type:varchar(255);uniqueIndex;not null"
    • Tag.Name: gorm:"type:varchar(255);uniqueIndex;not null"
    • Manga.Title: gorm:"type:varchar(255);index;not null"

4. Database Password

  • Problem: Empty password in .env file
  • Solution: Set DB_PASSWORD=root in .env

Current Status

Application is now running successfully!

  • Database connection: Working
  • Tables created automatically via GORM AutoMigrate
  • API endpoints responding with status 200
  • Running on http://localhost:8080

Files Modified

  1. cmd/server/main.go - Better .env file loading with multiple paths
  2. internal/database/db.go - Added debug logging for environment variables
  3. internal/models/models.go - Fixed all MySQL type definitions
  4. .env - Added database password

Testing

# The application is running and responding:
GET http://localhost:8080/api/mangas → {"data":[]}
GET http://localhost:8080/ → 200 OK

Next Steps

The application is production-ready! You can now:

  1. Upload manga via /api/upload/manga
  2. Sign up via /api/auth/signup
  3. Browse mangas via the web interface
  4. Manage library via /api/library endpoints
  5. Upload chapters via /api/upload/chapter/:id

The S3 integration is in place and ready to use. Update the S3 credentials in .env to enable manga storage:

  • S3_BUCKET
  • S3_REGION
  • AWS_ACCESS_KEY_ID
  • AWS_SECRET_ACCESS_KEY