Skip to content

Dev#7

Merged
itsLeonB merged 6 commits into
mainfrom
dev
Jan 9, 2026
Merged

Dev#7
itsLeonB merged 6 commits into
mainfrom
dev

Conversation

@itsLeonB

@itsLeonB itsLeonB commented Jan 4, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • New Features

    • Expanded repository and transaction tests with broader coverage
  • Bug Fixes

    • Standardized error handling across the codebase for consistent reporting
  • Removals

    • Soft-delete support and related deletion filters removed — deletions are now permanent
  • Chores

    • Switched default UUID generation to UUIDv7
    • Updated/refreshed dependency versions and simplified CI/build steps

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai

coderabbitai Bot commented Jan 4, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

BaseEntity dropped soft-delete fields/methods and switched ID default to uuidv7(); soft-delete scopes and filters were removed (package internal and public scopes). Error handling was migrated from eris to ungerr. Tests were consolidated/updated and CI/Makefile/pre-push scripts adjusted; dependencies were updated in go.mod.

Changes

Cohort / File(s) Summary
Base entity
base_entity.go
Removed DeletedAt sql.NullTime and IsDeleted(); changed ID default tag from gen_random_uuid() to uuidv7().
Soft-delete scopes (public)
gorm_scopes.go, gorm_repository.go
Removed DeletedFilter and its use in repository methods; eliminated public filter vars (ExcludeDeleted, IncludeDeleted, OnlyDeleted); removed usages of .WhereDeleted() in repo queries.
Soft-delete scopes (internal)
internal/gorm_scopes.go
Deleted file: removed DeletedFilterType interface and ExcludeDeleted/IncludeDeleted/OnlyDeleted implementations and their WhereDeleted() scopes.
Error library migration
gorm_repository.go, internal/transactor.go, gorm_scopes.go
Replaced eris usages with ungerr equivalents (eris.Wrap/Errf/Newungerr.Wrap/Unknown/Unknownf/New), updating error construction/wrapping paths.
Dependency updates
go.mod
Removed rotisserie/eris, added ungerr and other dependency version changes and indirect dependency refreshes.
Tests added/updated
gorm_repository_test.go, gorm_transactor_test.go, gorm_scopes_test.go, internal/internal_test.go
Added comprehensive gorm_repository_test.go (new test models TestUser, TestProfile, TestEntityWithBase); renamed packages from gocrud_testcrud_test/internal_test; migrated tests to use TestUser; removed TestDeletedFilter.
Tests removed (test/ dir)
test/constants_test.go, test/repository_test.go
Deleted legacy test files from test/ directory; their coverage migrated or removed.
CI / Build / Hooks
.github/workflows/ci.yml, Makefile, scripts/git-pre-push.sh
Added make build target; removed test dir verification and test-package build steps from CI; replaced lint step with build in pre-push; reworked Makefile test/coverage targets and PHONY list.

Sequence Diagram(s)

This change set does not meet the criteria for sequence diagram generation.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • Add Deleted Filter on Specs #4 — touches DeletedFilter and scope implementations that this PR removes; directly related to soft-delete scope changes.
  • feat: add base entity #2 — earlier changes to BaseEntity (adding DeletedAt/IsDeleted) that this PR reverses/updates (ID default and soft-delete removal).
  • Dev #5 — overlaps repository multi-record methods and tests (InsertMany/DeleteMany/SaveMany) modified in this PR.

Poem

🐰 I hopped among structs in midnight code,

Dropped the old delete and chose a new node,
UUIDv7 now leads the way,
Ungerr wraps errors where they lay,
Tests rebloom — I celebrate the road!

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 6.06% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'Dev' is vague and generic, providing no meaningful information about the substantial changes made across multiple files including dependency updates, error handling refactoring, and removal of soft-delete functionality. Replace with a descriptive title that summarizes the main change, such as 'Replace eris with ungerr and remove soft-delete support' or 'Refactor error handling and update dependencies'.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 92b1303 and 146dcf4.

📒 Files selected for processing (2)
  • gorm_repository_test.go
  • gorm_transactor_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • gorm_repository_test.go
🧰 Additional context used
🧬 Code graph analysis (1)
gorm_transactor_test.go (3)
gorm_repository_test.go (1)
  • TestUser (16-23)
gorm_repository.go (2)
  • NewRepository (45-51)
  • Specification (37-41)
gorm_transactor.go (1)
  • NewTransactor (25-27)
🔇 Additional comments (4)
gorm_transactor_test.go (4)

1-1: LGTM: Package rename is consistent.

The package name change from gocrud_test to crud_test aligns with the import alias on line 8.


15-25: LGTM: Test setup correctly migrated to TestUser.

The AutoMigrate call on line 21 correctly uses &TestUser{}, which is consistent with the model type used throughout the updated tests.


86-210: LGTM: WithinTransaction tests correctly migrated to TestUser.

All three transaction tests (success, rollback, nested) have been properly updated:

  • Repository creation uses correct type parameter NewRepository[TestUser]
  • Specifications use Specification[TestUser] with TestUser models
  • Rollback verification appropriately uses FindAll to confirm no records exist after rollback

212-227: LGTM: Error test appropriately validates Begin failure.

The test correctly triggers an error condition by closing the database connection before calling Begin. This is a reasonable approach for testing error handling in the transactor.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (2)
gorm_scopes.go (1)

37-37: Consider a more specific error type for validation errors.

The ungerr.Unknownf type typically indicates unexpected or unclassifiable errors, but an invalid field name is a validation/input error rather than an "unknown" condition. Consider using a more semantically appropriate error type if ungerr provides validation or bad-request error types.

gorm_repository.go (1)

168-168: Consider more specific error types for validation failures.

Using ungerr.Unknown for input validation errors (empty slices, zero values) may not be semantically accurate. These are known validation failures rather than "unknown" errors. If ungerr provides validation or bad-request error types, they would be more appropriate.

Also applies to: 185-185, 202-202, 219-219

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 539f459 and d8d51f3.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (5)
  • base_entity.go
  • go.mod
  • gorm_repository.go
  • gorm_scopes.go
  • internal/transactor.go
🧰 Additional context used
🧬 Code graph analysis (1)
internal/transactor.go (1)
lib/constants.go (1)
  • MsgTransactionError (8-8)
🔇 Additional comments (4)
gorm_scopes.go (1)

9-9: LGTM: Error library migration.

The migration from eris to ungerr is consistent with the project-wide error handling refactor.

internal/transactor.go (1)

8-8: LGTM: Consistent error library migration.

All error handling has been successfully migrated from eris to ungerr. The error messages and wrapping logic remain unchanged, maintaining the same error handling semantics.

Also applies to: 19-19, 33-33, 66-66, 77-77, 93-93

gorm_repository.go (1)

7-7: LGTM: Error library migration executed consistently.

The migration from eris to ungerr is implemented correctly across all repository methods, maintaining the same error handling semantics.

Also applies to: 71-71, 96-96, 124-124, 143-143, 160-160, 177-177, 194-194, 211-211

go.mod (1)

9-9: LGTM: Dependency updates appear reasonable.

The updates to testify (patch version) and indirect dependencies (text, protobuf, genproto, decimal) are standard maintenance updates that likely come from the new direct dependencies.

Also applies to: 23-26

Comment thread base_entity.go
Comment thread base_entity.go
Comment thread go.mod Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
internal/internal_test.go (1)

186-215: Thread-safety issue with assert inside goroutines.

Using assert.Equal inside goroutines without synchronization is unsafe because testing.T methods are not thread-safe. This can cause test failures or panics due to data races.

🐛 Proposed fix using `t.Run` with synchronization or collecting results
 func TestIsValidFieldName_Concurrent(t *testing.T) {
 	testCases := []struct {
 		field    string
 		expected bool
 	}{
 		{"concurrent_test_field", true},
 		{"table.column", true},
 		{".invalid", false},
 		{"invalid.", false},
 		{"invalid..dots", false},
 	}
 	
-	// Run multiple goroutines concurrently
-	done := make(chan bool, 500) // 100 goroutines * 5 test cases
-	
-	for i := 0; i < 100; i++ {
-		go func() {
-			for _, tc := range testCases {
-				result := internal.IsValidFieldName(tc.field)
-				assert.Equal(t, tc.expected, result, "IsValidFieldName should return %v for %q", tc.expected, tc.field)
-			}
-			done <- true
-		}()
-	}
-	
-	// Wait for all goroutines to complete
-	for i := 0; i < 100; i++ {
-		<-done
-	}
+	// Run multiple goroutines concurrently
+	errChan := make(chan error, 500)
+	var wg sync.WaitGroup
+	
+	for i := 0; i < 100; i++ {
+		wg.Add(1)
+		go func() {
+			defer wg.Done()
+			for _, tc := range testCases {
+				result := internal.IsValidFieldName(tc.field)
+				if result != tc.expected {
+					errChan <- fmt.Errorf("IsValidFieldName(%q) = %v, want %v", tc.field, result, tc.expected)
+				}
+			}
+		}()
+	}
+	
+	wg.Wait()
+	close(errChan)
+	
+	for err := range errChan {
+		t.Error(err)
+	}
 }

Add imports for sync and fmt at the top of the file.

gorm_scopes_test.go (1)

24-31: Remove SoftDeleteModel definition and migration.

The model is prepared in the setupScopesTestDB function but is never instantiated or used in any of the seven test functions in this file. Since no soft delete tests exist to consume it, removing both the type definition and the reference in db.AutoMigrate will reduce unnecessary test infrastructure.

🤖 Fix all issues with AI agents
In @gorm_repository_test.go:
- Around line 443-459: Test name TestCRUDRepository_Update_Error is misleading
because it asserts a successful update; either rename it to reflect success
(e.g., TestCRUDRepository_Update_Success) or change it to exercise a real error
case: call repo.Update with a non-existent TestUser ID or with data that
violates constraints and assert the expected error/behavior from Update; update
the test function name and assertions accordingly and keep references to
TestCRUDRepository_Update_Error, repo.Update, and TestUser so reviewers can
locate the change.

In @gorm_transactor_test.go:
- Around line 229-237: The test named TestTransactor_Commit_Error is misleading
because it asserts that committing without an active transaction returns no
error; rename the test function to TestTransactor_Commit_NoTransaction (or
similar) and update the function declaration and any references to match the new
name, or alternatively add a true error-case test that sets up a failing commit
scenario; update only the test function name and any callers/assertions for
TestTransactor_Commit_Error and ensure the test body remains consistent with its
intent.
🧹 Nitpick comments (5)
scripts/git-pre-push.sh (1)

5-5: Consider using printf instead of echo for better portability.

The \n escape sequences in echo statements may not be interpreted consistently across all POSIX shells. Some shells (like dash, commonly used as /bin/sh) will print literal \n instead of newlines.

♻️ Proposed refactor for portability
-echo "\n=== Running linting ==="
+printf "\n=== Running linting ===\n"
 if ! make lint; then
     echo "❌ Linting failed! Please fix the issues before pushing."
     exit 1
 fi
 
-echo "\n=== Running build ==="
+printf "\n=== Running build ===\n"
 if ! make build; then
     echo "❌ Build failed! Please fix the issues before pushing."
     exit 1
 fi
 
-echo "\n=== Running tests ==="
+printf "\n=== Running tests ===\n"
 if ! make test; then
     echo "❌ Tests failed! Please fix the test issues before pushing."
     exit 1
 fi
 
-echo "\n✅ All checks passed! Pushing can continue...\n"
+printf "\n✅ All checks passed! Pushing can continue...\n\n"

Also applies to: 11-11, 17-17

gorm_scopes_test.go (1)

14-22: Consider consolidating duplicate test model definitions.

TestModel here has nearly identical fields to TestUser in gorm_repository_test.go. Consider defining a shared test model in a common test helper file to reduce duplication and ensure consistency.

Makefile (1)

31-47: Consider adding cleanup for generated coverage files.

The per-package coverage generates multiple coverage-*.out and coverage-*.html files. Consider adding a clean target to remove these artifacts:

✨ Suggested clean target
clean:
	@echo "Cleaning generated files..."
	@rm -f coverage-*.out coverage-*.html
	@echo "Cleanup complete!"

And add clean to the .PHONY declaration on line 1.

gorm_repository_test.go (2)

25-31: TestProfile is defined but never used in any test.

Consider removing this unused type or adding tests that exercise preload relations with it.


54-66: Consider using t.Helper() pattern for better test failure context.

setupTestDB uses panic for error handling, which doesn't integrate well with Go's testing framework. Consider accepting *testing.T and using t.Fatal for better error messages and stack traces.

✨ Proposed improvement
-func setupTestDB() *gorm.DB {
+func setupTestDB(t *testing.T) *gorm.DB {
+	t.Helper()
 	db, err := gorm.Open(sqlite.Open(":memory:"), &gorm.Config{})
 	if err != nil {
-		panic("failed to connect database")
+		t.Fatalf("failed to connect database: %v", err)
 	}

 	// Migrate the schema
 	if err = db.AutoMigrate(&TestUser{}, &TestProfile{}); err != nil {
-		panic(err)
+		t.Fatalf("failed to migrate: %v", err)
 	}

 	return db
 }

Then update all call sites to pass t:

db := setupTestDB(t)
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3069781 and 92b1303.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (10)
  • .github/workflows/ci.yml
  • Makefile
  • go.mod
  • gorm_repository_test.go
  • gorm_scopes_test.go
  • gorm_transactor_test.go
  • internal/internal_test.go
  • scripts/git-pre-push.sh
  • test/constants_test.go
  • test/repository_test.go
💤 Files with no reviewable changes (3)
  • test/constants_test.go
  • .github/workflows/ci.yml
  • test/repository_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • go.mod
🧰 Additional context used
🧬 Code graph analysis (1)
gorm_transactor_test.go (3)
gorm_repository_test.go (1)
  • TestUser (16-23)
gorm_repository.go (2)
  • NewRepository (45-51)
  • Specification (37-41)
gorm_transactor.go (1)
  • NewTransactor (25-27)
🪛 checkmake (0.2.2)
Makefile

[warning] 3-3: Target body for "help" exceeds allowed length of 5 (12).

(maxbodylength)


[warning] 1-1: Missing required phony target "all"

(minphony)


[warning] 1-1: Missing required phony target "clean"

(minphony)

🔇 Additional comments (14)
scripts/git-pre-push.sh (1)

11-16: LGTM! Good addition of a build gate.

The build step appropriately validates compilation before running tests, catching build failures early in the development workflow.

internal/internal_test.go (2)

1-1: LGTM!

Package rename to internal_test correctly follows the black-box testing convention for the internal package.


10-80: Excellent test coverage for field name validation.

The table-driven tests comprehensively cover valid cases (simple fields, underscores, numbers, dot notation), invalid cases (empty, spaces, special characters, SQL injection attempts), and strict dot validation rules. This provides strong protection against SQL injection in field names.

gorm_scopes_test.go (3)

1-1: LGTM!

Package rename to crud_test aligns with the test consolidation refactor across the repository.


45-81: Good pagination test coverage.

Tests appropriately cover edge cases including page 0 defaulting to page 1, negative pages, and large limits. Well-structured table-driven tests.


83-129: LGTM!

OrderBy tests include SQL injection prevention validation, which is important for security. The test at line 106 correctly expects an error for malicious field names.

gorm_transactor_test.go (3)

1-1: LGTM!

Package rename to crud_test and use of TestUser from the same package is consistent with the test consolidation approach.


148-152: Improved rollback verification logic.

The updated test correctly verifies rollback by checking that no records exist after the transaction fails, rather than checking for a specific record. This is more robust.


212-227: LGTM!

Good error path coverage by closing the database connection before calling Begin to trigger a connection error.

Makefile (2)

20-22: LGTM!

The new build target is straightforward and appropriate for CI workflows to verify compilation.


53-58: No action needed—the pre-push hook script exists.

The scripts/git-pre-push.sh file is present and valid. The install target will work as intended.

Likely an incorrect or invalid review comment.

gorm_repository_test.go (3)

1-13: LGTM!

Clean imports and package declaration. The test file is well-organized with all necessary dependencies.


172-191: Flexible error handling for not-found case.

The test correctly handles both scenarios where the repository might return an error or a zero-value result for non-existent records. This makes the test robust against implementation changes.


68-88: Comprehensive CRUD test coverage.

The repository tests provide excellent coverage of all CRUD operations including single and bulk operations, with proper validation of returned data and timestamps.

Also applies to: 254-277, 357-380, 393-414

Comment thread gorm_repository_test.go Outdated
Comment thread gorm_transactor_test.go Outdated
itsLeonB and others added 2 commits January 9, 2026 16:03
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
gorm_transactor_test.go (1)

57-60: Duplicate test: This subtest is redundant with TestTransactor_Commit_WithoutTransaction.

The subtest "commit without transaction" (lines 57-60) tests identical functionality to TestTransactor_Commit_WithoutTransaction (lines 229-237). Consider removing one to eliminate duplication.

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 92b1303 and 146dcf4.

📒 Files selected for processing (2)
  • gorm_repository_test.go
  • gorm_transactor_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • gorm_repository_test.go
🧰 Additional context used
🧬 Code graph analysis (1)
gorm_transactor_test.go (3)
gorm_repository_test.go (1)
  • TestUser (16-23)
gorm_repository.go (2)
  • NewRepository (45-51)
  • Specification (37-41)
gorm_transactor.go (1)
  • NewTransactor (25-27)
🔇 Additional comments (4)
gorm_transactor_test.go (4)

1-1: LGTM: Package rename is consistent.

The package name change from gocrud_test to crud_test aligns with the import alias on line 8.


15-25: LGTM: Test setup correctly migrated to TestUser.

The AutoMigrate call on line 21 correctly uses &TestUser{}, which is consistent with the model type used throughout the updated tests.


86-210: LGTM: WithinTransaction tests correctly migrated to TestUser.

All three transaction tests (success, rollback, nested) have been properly updated:

  • Repository creation uses correct type parameter NewRepository[TestUser]
  • Specifications use Specification[TestUser] with TestUser models
  • Rollback verification appropriately uses FindAll to confirm no records exist after rollback

212-227: LGTM: Error test appropriately validates Begin failure.

The test correctly triggers an error condition by closing the database connection before calling Begin. This is a reasonable approach for testing error handling in the transactor.

@itsLeonB itsLeonB merged commit c0101fd into main Jan 9, 2026
10 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request Mar 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant