mirror of
https://github.com/hanzoai/base.git
synced 2026-10-30 15:03:47 +00:00
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.
40 lines
1.2 KiB
Go
40 lines
1.2 KiB
Go
package migrations
|
|
|
|
import (
|
|
"database/sql"
|
|
"errors"
|
|
|
|
"github.com/hanzoai/base/core"
|
|
)
|
|
|
|
// The five _view* system collections 1780000000_views_metadata made are
|
|
// retired. Nothing ever read them — not Base, not the admin UI, not a client —
|
|
// and as system collections they could not be what an org's views need to be:
|
|
// shared by the org, changed by the org's admin, and the org's own schema to
|
|
// extend. Team views are an ordinary `views` collection now, which the CRM
|
|
// module installs (modules/crm), and a person's own views live in their IAM
|
|
// preferences.
|
|
//
|
|
// A system collection refuses deletion, so each one is released from that
|
|
// first. Its rows go with its table.
|
|
func init() {
|
|
core.SystemMigrations.Register(func(txApp core.App) error {
|
|
// children before the parent, though none references another by relation
|
|
for _, name := range []string{"_view_groups", "_view_sorts", "_view_filters", "_view_fields", "_views"} {
|
|
c, err := txApp.FindCollectionByNameOrId(name)
|
|
if errors.Is(err, sql.ErrNoRows) {
|
|
continue
|
|
}
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
c.System = false
|
|
if err := txApp.Delete(c); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}, nil)
|
|
}
|