Files
zeekayandClaude Opus 5.5 f8eaf72607 A tightened rule reaches the database that already exists
Each Ensure creates its collection once and returns early ever after, so
the owner-scoped rules of v1.5.0 only ever applied to a fresh database.
One created by an earlier release kept list/view open to anyone on
accounts, balances, transactions, wallets and cards through every
upgrade.

The rules are now one table, used at creation and re-asserted on every
boot. The users collection's anonymous create is closed the same way:
identity is Lux ID, so no anonymous caller makes a users record.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_016dDw5Lp9sZFctwvZLn4nVz
2026-09-22 23:05:09 -07:00

51 lines
1.0 KiB
Go

package collections
import "github.com/hanzoai/base/core"
const DocumentCollectionName = "documents"
func EnsureDocumentCollection(app core.App) error {
_, err := app.FindCollectionByNameOrId(DocumentCollectionName)
if err == nil {
return nil
}
c := core.NewBaseCollection(DocumentCollectionName, DocumentCollectionName)
c.Fields.Add(
&core.RelationField{
Name: "account",
CollectionId: AccountCollectionName,
Required: true,
MaxSelect: 1,
},
&core.TextField{
Name: "type",
Required: true,
},
&core.FileField{
Name: "file",
Required: true,
MaxSelect: 1,
MaxSize: 10 << 20, // 10MB
MimeTypes: []string{
"application/pdf",
"image/jpeg",
"image/png",
},
},
&core.TextField{
Name: "status",
Required: true,
},
&core.TextField{Name: "reviewedBy"},
&core.TextField{Name: "reviewNote"},
&core.AutodateField{Name: "created", OnCreate: true},
&core.AutodateField{Name: "updated", OnCreate: true, OnUpdate: true},
)
readable(c)
return app.Save(c)
}