Repository: stephenafamo/bob (go)

Issue:
No generated error constants for unique index
If I create a unique index like:

```
CREATE UNIQUE INDEX my_index ON my_table (field_one, field_two);
```

should I not get a [generated error](https://bob.stephenafamo.com/docs/code-generation/usage#generated-error-constants) on `my_table` like:

```
type myTableErrors struct {
    ErrUniqueFieldOneAndFieldTwo *UniqueConstraintError
}
``` 

If I set up this unique constraint explicitly in my bob.yaml, I get the error defined upon `myTableErrors`


Discussion:
Right now, the template generates the code based on unique constraints, not unique indexes.

This is a bug and should be modified.
I would be interested in working on this
Sure. Go for it @tlietz 👍🏾 

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 ## [Unreleased]
 
+### Changed
+
+- Generates error constants with unique indexes instead of unique constraints. (thanks @tlietz)
+
 ## [v0.30.0] - 2025-01-16
 
 ### Added
diff --git a/gen/templates/models/table/01_types.go.tpl b/gen/templates/models/table/01_types.go.tpl
--- a/gen/templates/models/table/01_types.go.tpl
+++ b/gen/templates/models/table/01_types.go.tpl
@@ -131,20 +131,28 @@ func build{{$tAlias.UpSingular}}Where[Q {{$.Dialect}}.Filterable](cols {{$tAlias
 	}
 }
 
-{{ if $table.Constraints.Uniques }}
+{{ $hasUniqueIndex := false }}
+{{range $index := $table.Indexes}}
+{{ if $index.Unique }} 
+	{{ $hasUniqueIndex = true }}
+	{{ break }}
+{{ end }} 
+{{end -}}
+
+{{ if $hasUniqueIndex }}
 var {{$tAlias.UpSingular}}Errors = &{{$tAlias.DownSingular}}Errors{
-	{{range $constraint := $table.Constraints.Uniques}}
-	{{ $s := $constraint.Name }}
-	{{ if eq "sqlite" $.Dialect }}
-	{{ $s = printf "%s.%s" $table.Name (join (printf ", %s." $table.Name) $constraint.Columns) }}
+	{{range $index := $table.Indexes}}
+	{{ if $index.Unique }}
+	ErrUnique{{$index.Name | camelcase}}: &UniqueConstraintError{s: "{{$index.Name}}"},
 	{{ end }}
-	ErrUnique{{join "_and_" $constraint.Columns | camelcase}}: &UniqueConstraintError{s: "{{$s}}"},
 	{{end}}
 }
 
 type {{$tAlias.DownSingular}}Errors struct {
-	{{range $constraint := $table.Constraints.Uniques}}
-	ErrUnique{{join "_and_" $constraint.Columns | camelcase}} *UniqueConstraintError
+	{{range $index := $table.Indexes}}
+	{{ if $index.Unique }} 
+	ErrUnique{{$index.Name | camelcase}} *UniqueConstraintError
 	{{ end }}
+	{{end}}
 }
 {{ end }}


Test patch:
diff --git a/gen/templates/models/table/01_types_test.go.tpl b/gen/templates/models/table/01_types_test.go.tpl
--- a/gen/templates/models/table/01_types_test.go.tpl
+++ b/gen/templates/models/table/01_types_test.go.tpl
@@ -53,21 +53,23 @@ func Test{{$tAlias.UpSingular}}UniqueConstraintErrors(t *testing.T) {
 		expectedErr *models.UniqueConstraintError
 		applyFn     func(tpl *factory.{{$tAlias.UpSingular}}Template, obj *models.{{$tAlias.UpSingular}})
 	}{
-	{{range $constraint := $table.Constraints.Uniques}}
-		{{- $errName := printf "ErrUnique%s" (join "_and_" $constraint.Columns | camelcase) -}}
+	{{range $index := $table.Indexes}}
+		{{ if $index.Unique }}
+		{{- $errName := printf "ErrUnique%s" ($index.Name | camelcase) -}}
 		{
 			name: "{{$errName}}",
 			expectedErr: models.{{$tAlias.UpSingular}}Errors.{{$errName}},
 			applyFn: func(tpl *factory.{{$tAlias.UpSingular}}Template, obj *models.{{$tAlias.UpSingular}}) {
 				tpl.Apply(
 					factory.{{$tAlias.UpSingular}}Mods.RandomizeAllColumns(nil),
-					{{range $columnName := $constraint.Columns}}
-					{{- $colAlias := $tAlias.Column $columnName -}}
+					{{range $indexColumn := $index.Columns}}
+					{{- $colAlias := $tAlias.Column $indexColumn.Name -}}
 					factory.{{$tAlias.UpSingular}}Mods.{{$colAlias}}(obj.{{$colAlias}}),
 					{{end}}
 				)
 			},
 		},
+		{{ end }}
 	{{end}}
 	}