mirror of
https://github.com/luxfi/bank.git
synced 2026-11-02 12:37:36 +00:00
Base v0.39.0 had a startup panic in MigrationsRunner.initMigrationsTable
(nil pointer at base.go:808 → migrations_runner.go:256 because app.DB()
returned nil before serve.go could finish init). Fixed in Base v1.x.
In Base v1.3.1, RelationField.CollectionId validation now requires the
ACTUAL collection ID, not the name (field_relation.go:277-280):
relCollection, _ := app.FindCachedCollectionByNameOrId(v)
if relCollection == nil || relCollection.Id != v {
return validation.NewError("...The relation collection doesn't exist.")
}
Previous code passed "users" / "accounts" by name; Base looked them up
fine but rejected the field because the stored ID was a random
`hbc_xxxxxxxx` not the name. Two fixes:
- All RelationField{CollectionId: "users"} → "_users_auth_" (Base's
canonical id for the system users auth collection).
- All NewBaseCollection(Name) → NewBaseCollection(Name, Name) so each
bank collection gets a stable id matching its name. Sibling collections
can then keep referencing CollectionId: AccountCollectionName etc.
Verified locally:
$ bankd serve --http :8070 --dir /tmp/bank-data-test
Server started at http://0.0.0.0:8070
$ sqlite3 /tmp/bank-data-test/data.db "SELECT name FROM _collections WHERE NOT system"
users / accounts / beneficiaries / transactions / fees / sessions /
balances / audit_log / documents / wallets
40 lines
1.2 KiB
Go
40 lines
1.2 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},
|
|
)
|
|
|
|
listRule := `account.owner = @request.auth.id`
|
|
c.ListRule = &listRule
|
|
c.ViewRule = &listRule
|
|
|
|
return app.Save(c)
|
|
}
|