Files
zeekay 77c69fb333 fix: bump Base v0.39.0 → v1.3.1 + pin explicit collection IDs
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
2026-05-27 17:49:24 -07:00

55 lines
1.2 KiB
Go

package collections
import "github.com/hanzoai/base/core"
const AuditCollectionName = "audit_log"
// EnsureAuditCollection creates the audit_log collection if it does not exist.
// Immutable append-only log for compliance-relevant events (freeze, unfreeze,
// limit changes, KYC transitions, etc.).
func EnsureAuditCollection(app core.App) error {
_, err := app.FindCollectionByNameOrId(AuditCollectionName)
if err == nil {
return nil
}
c := core.NewBaseCollection(AuditCollectionName, AuditCollectionName)
// API rules: all nil — superuser only. Audit log is not user-accessible.
c.Fields.Add(
// The account this event relates to.
&core.RelationField{
Name: "account",
CollectionId: AccountCollectionName,
Required: true,
MaxSelect: 1,
},
// Who performed the action (user id or "system").
&core.TextField{
Name: "actor",
Required: true,
},
// What happened.
&core.TextField{
Name: "action",
Required: true,
},
// Structured detail blob.
&core.JSONField{
Name: "detail",
MaxSize: 1 << 20,
},
&core.AutodateField{
Name: "created",
OnCreate: true,
},
)
return app.Save(c)
}