codegen: add generator for soft-deletion

This commit is contained in:
2026-09-19 21:36:31 -07:00
parent 9d4a1eab10
commit b064948d24
4 changed files with 89 additions and 1 deletions

View File

@@ -69,9 +69,11 @@ func SampleValue(c pkgschema.Column, offset int) ast.Expr {
// UpdateTestFields returns the columns for which the test generator should assign its own
// sample values, in the MakeXyz() factory and in the create/update test: the same columns
// that GenerateSaveItemFunc's "update" branch writes to, minus foreign keys (which can't be
// given plausible values here) and the auto-managed "created_at"/"updated_at" columns.
// given plausible values here), the auto-managed "created_at"/"updated_at" columns, and the
// soft-delete columns (which SoftDeleteXyz() manages).
func UpdateTestFields(tbl pkgschema.Table) (ret []pkgschema.Column) {
hasCreatedAt, hasUpdatedAt := tbl.HasAutoTimestamps()
hasSoftDelete := tbl.HasSoftDelete()
for _, c := range tbl.Columns {
if c.Name == "rowid" || c.IsPrimaryKey || c.IsForeignKey {
continue
@@ -82,6 +84,9 @@ func UpdateTestFields(tbl pkgschema.Table) (ret []pkgschema.Column) {
if c.Name == "updated_at" && hasUpdatedAt {
continue
}
if hasSoftDelete && (c.Name == "is_deleted" || c.Name == "deleted_at") {
continue
}
ret = append(ret, c)
}
return