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

38 lines
1.1 KiB
Go

package collections
import "github.com/hanzoai/base/core"
const ConversionCollectionName = "conversions"
func EnsureConversionCollection(app core.App) error {
_, err := app.FindCollectionByNameOrId(ConversionCollectionName)
if err == nil {
return nil
}
c := core.NewBaseCollection(ConversionCollectionName, ConversionCollectionName)
c.Fields.Add(
&core.RelationField{
Name: "account",
CollectionId: AccountCollectionName,
Required: true,
MaxSelect: 1,
},
&core.TextField{Name: "sellCurrency", Required: true, Min: 3, Max: 3},
&core.TextField{Name: "buyCurrency", Required: true, Min: 3, Max: 3},
&core.NumberField{Name: "sellAmount", Required: true},
&core.NumberField{Name: "buyAmount"},
&core.NumberField{Name: "rate"},
&core.TextField{Name: "quoteId"},
&core.TextField{Name: "ccConversionId"},
&core.TextField{Name: "status"}, // pending, completed, failed, cancelled
&core.AutodateField{Name: "created", OnCreate: true},
&core.AutodateField{Name: "updated", OnCreate: true, OnUpdate: true},
)
readable(c)
return app.Save(c)
}