Skip to content

Commit

Permalink
fix imports in templates (#3)
Browse files Browse the repository at this point in the history
Signed-off-by: Sarah Funkhouser <147884153+golanglemonade@users.noreply.github.com>
  • Loading branch information
golanglemonade authored Aug 27, 2024
1 parent 01f730f commit 1b3ca91
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 20 deletions.
14 changes: 7 additions & 7 deletions history/templates/auditing.tmpl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{/* gotype: entgo.io/ent/entc/gen.Graph */}}

{{ define "auditing" }}
// Code generated by enthistory, DO NOT EDIT.
// Code generated by entx.history, DO NOT EDIT.
{{- $pkg := base $.Config.Package }}
{{- template "header" $ }}
import (
Expand Down Expand Up @@ -103,7 +103,7 @@ func ({{ $h.Receiver }} *{{ $h.Name }}) Diff(history *{{ $h.Name }}) (*HistoryDi
{{ end }}
{{ end }}

func (c Change) String(op enthistory.OpType) string {
func (c Change) String(op history.OpType) string {
var newstr, oldstr string
if c.New != nil {
val, err := json.Marshal(c.New)
Expand All @@ -122,9 +122,9 @@ func (c Change) String(op enthistory.OpType) string {
}
}
switch op {
case enthistory.OpTypeInsert:
case history.OpTypeInsert:
return fmt.Sprintf("%s: %s", c.FieldName, newstr)
case enthistory.OpTypeDelete:
case history.OpTypeDelete:
return fmt.Sprintf("%s: %s", c.FieldName, oldstr)
default:
return fmt.Sprintf("%s: %s -> %s", c.FieldName, oldstr, newstr)
Expand Down Expand Up @@ -179,7 +179,7 @@ type record struct {
Table string
RefId any
HistoryTime time.Time
Operation enthistory.OpType
Operation history.OpType
Changes []Change
{{- if $includeUpdatedBy }}
UpdatedBy {{ if $updatedByNillable}}*{{- end}}{{ $updatedByValueType }}
Expand Down Expand Up @@ -268,9 +268,9 @@ func audit{{ $n.Name }}(ctx context.Context, config config) ([][]string, error)
{{- end }}
}
switch curr.Operation {
case enthistory.OpTypeInsert:
case history.OpTypeInsert:
record.Changes = (&{{ $n.Name }}{}).changes(curr)
case enthistory.OpTypeDelete:
case history.OpTypeDelete:
record.Changes = curr.changes(&{{ $n.Name }}{})
default:
if i == 0 {
Expand Down
6 changes: 3 additions & 3 deletions history/templates/historyClient.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
{{/* gotype: entgo.io/ent/entc/gen.Graph */}}

{{ define "historyClient" }}
// Code generated by enthistory, DO NOT EDIT.
// Code generated by entx.history, DO NOT EDIT.
{{ $pkg := base $.Config.Package }}
{{ template "header" $ }}

// withHistory adds the history hooks to the appropriate schemas - generated by enthistory
// withHistory adds the history hooks to the appropriate schemas - generated by entx.history
func (c *Client) WithHistory() {
{{- range $n := $.Nodes }}
{{- $name := $n.Name }}
Expand All @@ -16,7 +16,7 @@ func (c *Client) WithHistory() {
{{- range $h := $.Nodes }}
{{- $sameNodeType := hasPrefix $h.Name (printf "%sHistory" $name) }}
{{- if $sameNodeType }}
for _, hook := range enthistory.HistoryHooks[*{{ $name }}Mutation]() {
for _, hook := range history.HistoryHooks[*{{ $name }}Mutation]() {
c.{{ $name }}.Use(hook)
}
{{- end }}
Expand Down
10 changes: 5 additions & 5 deletions history/templates/historyFromMutation.tmpl
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
{{/* gotype: entgo.io/ent/entc/gen.Graph */}}

{{ define "historyFromMutation" }}
// Code generated by enthistory, DO NOT EDIT.
// Code generated by entx.history, DO NOT EDIT.
{{ $pkg := base $.Config.Package }}
{{ template "header" $ }}
var (
idNotFoundError = errors.New("could not get id from mutation")
)
func EntOpToHistoryOp(op ent.Op) enthistory.OpType {
func EntOpToHistoryOp(op ent.Op) history.OpType {
switch op {
case ent.OpDelete, ent.OpDeleteOne:
return enthistory.OpTypeDelete
return history.OpTypeDelete
case ent.OpUpdate, ent.OpUpdateOne:
return enthistory.OpTypeUpdate
return history.OpTypeUpdate
default:
return enthistory.OpTypeInsert
return history.OpTypeInsert
}
}

Expand Down
2 changes: 1 addition & 1 deletion history/templates/historyQuery.tmpl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{/* gotype: entgo.io/ent/entc/gen.Graph */}}

{{ define "historyQuery" }}
// Code generated by enthistory, DO NOT EDIT.
// Code generated by entx.history, DO NOT EDIT.
{{- $pkg := base $.Config.Package }}
{{- template "header" $ }}
import (
Expand Down
8 changes: 4 additions & 4 deletions history/templates/schema.tmpl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Code generated by enthistory, DO NOT EDIT.
// Code generated by entx.history, DO NOT EDIT.
package {{ .SchemaPkg }}

import (
Expand All @@ -10,7 +10,7 @@ import (
"entgo.io/ent/schema/field"

"github.com/theopenlane/entx/history"
"github.com/datumforge/entx"
"github.com/theopenlane/entx"
)

{{- $schema := .Schema }}
Expand All @@ -31,7 +31,7 @@ func ({{ $name }}) Annotations() []schema.Annotation {
Schema: "{{ .SchemaName }}",
{{- end }}
},
enthistory.Annotations{
history.Annotations{
IsHistory: true,
Exclude: true,
},
Expand Down Expand Up @@ -59,7 +59,7 @@ func ({{ $name }}) Fields() []ent.Field {
Immutable().
Optional(),
field.Enum("operation").
GoType(enthistory.OpType("")).
GoType(history.OpType("")).
Immutable(),
{{- if $.WithUpdatedBy }}
field.{{ $.UpdatedByValueType | ToUpperCamel }}("updated_by").
Expand Down

0 comments on commit 1b3ca91

Please sign in to comment.