Files
base/migrations/retire_view_metadata_test.go
zeekay 7b5f02793e The CRM is a module an org installs into its own Base
A module is a named import document, and installing one is a grow:
core.GrowCollections creates what is missing and adds the fields, select
values and indexes an existing collection lacks, in one transaction,
changing nothing that exists. A relation names its collection by name.
Installing twice changes nothing.

modules/crm carries the thirteen collections: people, companies,
opportunities, candidates, applications, lists, list_members, segments,
activities (one row per source id), notes, tasks, attachments and the
org's shared views. POST /v1/modules/{name} installs, GET /v1/modules
lists, both for a superuser or the org's admin, who can never reach a
collection only a superuser manages this way.

The _view* system collections are retired. Nothing read them, and team
views are the ordinary views collection now.
2026-10-18 21:02:29 -07:00

50 lines
1.3 KiB
Go

package migrations_test
import (
"testing"
"github.com/hanzoai/base/core"
_ "github.com/hanzoai/base/migrations"
)
var viewMetadata = []string{"_views", "_view_fields", "_view_filters", "_view_sorts", "_view_groups"}
// The _view* system collections are gone from a new Base and from one that
// had them, rows and all.
func TestViewMetadataIsRetired(t *testing.T) {
app := core.NewBaseApp(core.BaseAppConfig{DataDir: t.TempDir()})
if err := app.Bootstrap(); err != nil {
t.Fatal(err)
}
defer app.ResetBootstrapState()
gone := func() {
t.Helper()
for _, name := range viewMetadata {
if _, err := app.FindCollectionByNameOrId(name); err == nil {
t.Fatalf("%s is still a collection", name)
}
if app.HasTable(name) {
t.Fatalf("%s is still a table", name)
}
}
}
gone()
// a Base from before the retirement: the collections exist and hold a row
rerun(t, app, "1780000000_views_metadata.go")
views, err := app.FindCollectionByNameOrId("_views")
if err != nil {
t.Fatalf("the old migration did not recreate _views: %v", err)
}
r := core.NewRecord(views)
r.Load(map[string]any{"owner": "u1", "collection": "people", "name": "Mine"})
if err := app.Save(r); err != nil {
t.Fatal(err)
}
rerun(t, app, "1790000200_retire_view_metadata.go")
gone()
}