Skip to content

v1.17.2 - Database Defaults and MongoDB Fixes โ€‹

Release Date: February 1, 2026

Version 1.17.2 addresses critical issues with database initialization and MongoDB code generation. This release changes the default database to SQLite for a better out-of-the-box experience and fixes code generation bugs that caused compilation errors with MongoDB projects.

๐ŸŽฏ Highlights โ€‹

  • SQLite is now the default database - Zero-configuration setup for new projects
  • MongoDB code generation fixed - No more GORM imports in MongoDB projects
  • Better developer experience - Get started faster without external dependencies

๐Ÿ› Bug Fixes โ€‹

Default Database Changed to SQLite โ€‹

Issue: The default database was PostgreSQL, requiring users to install and configure a PostgreSQL server even for simple projects or learning.

Fix: Changed the default database to SQLite, which:

  • Requires no external database server
  • Works out of the box with zero configuration
  • Perfect for development, testing, and prototyping
  • Creates a simple .db file in your project
  • Still allows switching to any other database via --database flag

Before:

bash
goca init myproject --module github.com/user/myproject
# Would default to PostgreSQL, requiring DB setup

After:

bash
goca init myproject --module github.com/user/myproject
# Now defaults to SQLite - works immediately!

Using other databases:

bash
# PostgreSQL
goca init myproject --module github.com/user/myproject --database postgres

# MongoDB
goca init myproject --module github.com/user/myproject --database mongodb

# MySQL
goca init myproject --module github.com/user/myproject --database mysql

# And more: sqlserver, dynamodb, elasticsearch

MongoDB Code Generation Fixed โ€‹

Issue: When creating a project with MongoDB, the generated code incorrectly:

  • Imported both GORM and MongoDB driver
  • Used *gorm.DB instead of *mongo.Client
  • Called gorm.Open() instead of mongo.Connect()
  • Added GORM dependencies to go.mod
  • Result: Projects didn't compile - multiple undefined errors

Example of errors:

"go.mongodb.org/mongo-driver/mongo/options" imported and not used
undefined: gorm
undefined: mongo.Open

Fix: Complete rewrite of MongoDB initialization:

  • Created dedicated createMongoDBMainGo() function
  • Uses *mongo.Client for MongoDB connections
  • Proper MongoDB driver imports only
  • Correct mongo.Connect() and client.Ping() usage
  • go.mod only includes go.mongodb.org/mongo-driver
  • Health checks adapted for MongoDB
  • Graceful shutdown with client disconnection

Generated MongoDB code now:

go
import (
    "go.mongodb.org/mongo-driver/mongo"
    "go.mongodb.org/mongo-driver/mongo/options"
    "go.mongodb.org/mongo-driver/mongo/readpref"
    // NO gorm imports!
)

var (
    mongoClient *mongo.Client  // Correct type!
)

func connectToMongoDB(cfg *config.Config) (*mongo.Client, error) {
    clientOptions := options.Client().ApplyURI(dsn)
    ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
    client, err := mongo.Connect(ctx, clientOptions)
    // ... proper MongoDB connection
}

๐Ÿงช Testing โ€‹

Added comprehensive test coverage for database initialization:

TestInitDefaultDatabase โ€‹

  • Verifies SQLite is the default when no --database flag is provided
  • Checks .goca.yaml contains type: "sqlite"
  • Validates go.mod has gorm.io/driver/sqlite

TestInitMongoDBNoGorm โ€‹

  • Ensures MongoDB projects use mongo-driver
  • Verifies GORM is NOT imported
  • Confirms *mongo.Client type is used
  • Validates go.mod has correct dependencies

๐Ÿ“Š Test Results โ€‹

All database initialization tests passing:

  • โœ… Default database (SQLite)
  • โœ… PostgreSQL (no regression)
  • โœ… MySQL (no regression)
  • โœ… MongoDB (fixed)
  • โœ… SQL Server (no regression)

๐Ÿ”„ Migration Guide โ€‹

For Existing Projects โ€‹

No changes required! This only affects new project initialization.

If you want to update an existing project:

To SQLite (from PostgreSQL):

  1. Update .goca.yaml: Change database.type to "sqlite"
  2. Update go.mod: Replace postgres driver with sqlite
    bash
    go get gorm.io/driver/sqlite
    go mod tidy
  3. Update connection string in .env or config

MongoDB projects created before v1.17.2: If you have a non-compiling MongoDB project, regenerate it:

bash
goca init myproject-fixed --module github.com/user/myproject --database mongodb
# Copy your business logic to the new project

For New Projects โ€‹

Just use the defaults!

bash
goca init myproject --module github.com/user/myproject
cd myproject
go mod tidy
go run cmd/server/main.go
# Works immediately with SQLite!

๐Ÿ“ฆ Installation โ€‹

Update to v1.17.2:

bash
go install github.com/sazardev/goca@v1.17.2

Verify installation:

bash
goca version
# Output: v1.17.2
  • Issue #42: MongoDB projects fail to compile
  • Issue #43: Default database should be SQLite for easier onboarding

๐Ÿ“ Complete Changes โ€‹

Changed:

  • Default database from postgres to sqlite
  • MongoDB code generation to use mongo-driver correctly

Added:

  • createMongoDBMainGo() function for MongoDB-specific code
  • Placeholder functions for DynamoDB and Elasticsearch
  • Comprehensive database initialization tests

Fixed:

  • MongoDB projects now compile successfully
  • No more mixed GORM/MongoDB imports
  • Proper mongo.Client usage in MongoDB projects

๐Ÿ™ Contributors โ€‹

Thank you to everyone who reported these issues and helped improve Goca!

๐Ÿ”— Resources โ€‹


Previous: v1.17.1

View on GitHub โ€ข Download โ€ข Report Issue

Released under the MIT License.