Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions dialect/entsql/annotation.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ import "entgo.io/ent/schema"
// Annotation is a builtin schema annotation for attaching
// SQL metadata to schema objects for both codegen and runtime.
type Annotation struct {
// The Schema option allows setting the schema which the table belongs to.
// Note, this option is no-op for Ent default migration engine. However, schema
// extensions (like Atlas) can accept this option and implement it accordingly.
//
// entsql.Annotation{
// Schema: "public",
// }
//
Schema string `json:"schema,omitempty"`

// The Table option allows overriding the default table
// name that is generated by ent. For example:
//
Expand Down Expand Up @@ -146,6 +156,21 @@ func (Annotation) Name() string {
return "EntSQL"
}

// The Schema option allows setting the schema which the table belongs to.
// Note, this option is no-op for Ent default migration engine. However, schema
// extensions (like Atlas) can accept this option and implement it accordingly.
//
// func (T) Annotations() []schema.Annotation {
// return []schema.Annotation{
// entsql.Schema("public"),
// }
// }
func Schema(s string) *Annotation {
return &Annotation{
Schema: s,
}
}

// The Table option allows overriding the default table
// name that is generated by ent. For example:
//
Expand All @@ -160,6 +185,14 @@ func Table(t string) *Annotation {
}
}

// SchemaTable allows setting both schema and table name in one annotation.
func SchemaTable(s, t string) *Annotation {
return &Annotation{
Schema: s,
Table: t,
}
}

// Check allows injecting custom "DDL" for setting an unnamed "CHECK" clause in "CREATE TABLE".
//
// entsql.Annotation{
Expand Down Expand Up @@ -273,6 +306,9 @@ func (a Annotation) Merge(other schema.Annotation) schema.Annotation {
default:
return a
}
if s := ant.Schema; s != "" {
a.Schema = s
}
if t := ant.Table; t != "" {
a.Table = t
}
Expand Down