codegen: add generator for soft-deletion
This commit is contained in:
@@ -61,3 +61,18 @@ func (t Table) HasAutoTimestamps() (hasCreatedAt bool, hasUpdatedAt bool) {
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// HasSoftDelete reports whether this table supports soft-deletion, i.e., whether it has both
|
||||
// an "is_deleted" and a "deleted_at" column.
|
||||
func (t Table) HasSoftDelete() bool {
|
||||
var hasIsDeleted, hasDeletedAt bool
|
||||
for _, c := range t.Columns {
|
||||
if c.Name == "is_deleted" && c.Type == "integer" {
|
||||
hasIsDeleted = true
|
||||
}
|
||||
if c.Name == "deleted_at" && c.Type == "integer" {
|
||||
hasDeletedAt = true
|
||||
}
|
||||
}
|
||||
return hasIsDeleted && hasDeletedAt
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user