schemadraft

package
v1.9.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 25, 2026 License: AGPL-3.0 Imports: 11 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrConnectionAlreadyInDraft = fmt.Errorf("connection already exists in draft")
View Source
var RootDir string

RootDir overrides ~/.apito/schema-drafts in tests.

Functions

func Apply

func Apply(draft *models.ProjectSchema, op *Operation) error

func BoolPayload

func BoolPayload(args map[string]interface{}, key string) (bool, bool)

func ChangesetID

func ChangesetID(projectID string) string

ChangesetID is stable for a project so the console can refetch the same draft.

func ClassifyFieldChange

func ClassifyFieldChange(before, after *models.FieldInfo) (impact string, changes []string)

ClassifyFieldChange compares two fields with the same identifier.

func CloneFieldInfo

func CloneFieldInfo(f *models.FieldInfo) (*models.FieldInfo, error)

func ComputeDiff

func ComputeDiff(active, draft *models.ProjectSchema) *models.SchemaDiff

func ConnKeySet

func ConnKeySet(conns []*models.ConnectionType) map[string]*models.ConnectionType

func ConnectionIdentity

func ConnectionIdentity(c *models.ConnectionType) string

func DiffRequiresPhysicalDDL

func DiffRequiresPhysicalDDL(d *models.SchemaDiff) bool

func DraftCreateConnection

func DraftCreateConnection(draft *models.ProjectSchema, op *Operation) error

func EncodeDiff

func EncodeDiff(d *models.SchemaDiff) string

EncodeDiff serializes a schema diff for the GraphQL string field.

func FieldChangeSummary

func FieldChangeSummary(fc *models.SchemaFieldChange) string

func FieldMap

func FieldMap(fields []*models.FieldInfo) map[string]*models.FieldInfo

func FindConnection

func FindConnection(conns []*models.ConnectionType, peer, knownAs string) *models.ConnectionType

func FindFieldByIdentifier

func FindFieldByIdentifier(fields []*models.FieldInfo, id string) *models.FieldInfo

func FindFieldByIdentifierDeep

func FindFieldByIdentifierDeep(fields []*models.FieldInfo, id string) *models.FieldInfo

func FindModel

func FindModel(schema *models.ProjectSchema, name string) *models.ModelType

func ForwardEdges

func ForwardEdges(schema *models.ProjectSchema) map[string]ForwardEdge

func LabelToIdentifier

func LabelToIdentifier(label, fieldType string) string

func OperationSummary

func OperationSummary(opType string, args map[string]interface{}) string

func Plan

func Plan(projectID, changesetID string, ops []Op) []map[string]interface{}

Plan builds the pending execution rows the Schema Changes table groups by operation. Public rows stay pending until synchronous publish. They are not a Cloud repair ledger.

func Remove

func Remove(projectID string) error

Remove deletes the draft file. A missing file is success.

func Replay

func Replay(live *models.ProjectSchema, ops []Op) (*models.ProjectSchema, error)

Replay applies staged file operations with the same replay Cloud uses. create_model and add_model are one step. The local preview drops an unconnected users model.

func ReplayOperations

func ReplayOperations(base *models.ProjectSchema, ops []*Operation) (*models.ProjectSchema, error)

func StringArg

func StringArg(args map[string]interface{}, key string) string

func StringList

func StringList(args map[string]interface{}, key string) []string

func SummarizeDiffImpact

func SummarizeDiffImpact(d *models.SchemaDiff)

func ValidateCreateConnectionAgainstDraft

func ValidateCreateConnectionAgainstDraft(draft *models.ProjectSchema, op *Operation) error

validateCreateConnectionAgainstDraft enforces draft-side prerequisites for staging create_connection (versioning path skips open-core live-schema defaultFn).

Types

type API

type API interface {
	Status(ctx context.Context, project *models.Project) (map[string]interface{}, error)
	Preview(ctx context.Context, project *models.Project, source string, version int) (string, error)
	Diff(ctx context.Context, project *models.Project, changesetID string) (string, error)
	Events(ctx context.Context, project *models.Project, changesetID string) ([]map[string]interface{}, error)
	Records(ctx context.Context, project *models.Project, changesetID string, version, limit, offset int) ([]map[string]interface{}, error)
	Approve(ctx context.Context, project *models.Project, changesetID, message, actor string) (map[string]interface{}, error)
	Discard(ctx context.Context, project *models.Project, changesetID string) (bool, error)
}

API is the pending-draft surface both engines implement. History, revert, review, repair, and remote sync stay outside this interface.

type Capabilities

type Capabilities struct {
	History       bool `json:"history"`
	Collaboration bool `json:"collaboration"`
	Revert        bool `json:"revert"`
	Repair        bool `json:"repair"`
	RemoteSync    bool `json:"remote_sync"`
	AsyncPublish  bool `json:"async_publish"`
}

Capabilities tells the console which Cloud-only controls to show. The public engine leaves every flag false.

func CloudCapabilities

func CloudCapabilities() Capabilities

CloudCapabilities marks the controls the Cloud console composes around the shared pending panel.

func PublicCapabilities

func PublicCapabilities() Capabilities

PublicCapabilities is the local file-backed draft. Publish is synchronous.

func (Capabilities) Map

func (c Capabilities) Map() map[string]interface{}

type File

type File struct {
	ProjectID   string `json:"project_id"`
	ChangesetID string `json:"changeset_id,omitempty"`
	Ops         []Op   `json:"ops"`
}

File is the on-disk draft. changeset_id is optional so older files still load.

func Append

func Append(projectID string, op Op) (*File, error)

Append adds one operation and keeps the changeset id stable.

func Load

func Load(projectID string) (*File, error)

Load reads a draft. A missing file is an empty draft.

type ForwardEdge

type ForwardEdge struct {
	FromModel string
	ToModel   string
	KnownAs   string
	FromRel   string
	ToRel     string
}

type Local

type Local struct {
	Publish Publisher
}

Local is the file-backed pending draft.

func NewLocal

func NewLocal(publish Publisher) *Local

func (*Local) Approve

func (l *Local) Approve(ctx context.Context, project *models.Project, changesetID, _, _ string) (map[string]interface{}, error)

func (*Local) Diff

func (l *Local) Diff(_ context.Context, project *models.Project, _ string) (string, error)

func (*Local) Discard

func (l *Local) Discard(_ context.Context, project *models.Project, changesetID string) (bool, error)

func (*Local) Events

func (l *Local) Events(_ context.Context, project *models.Project, _ string) ([]map[string]interface{}, error)

func (*Local) Preview

func (l *Local) Preview(_ context.Context, project *models.Project, source string, _ int) (string, error)

func (*Local) Records

func (l *Local) Records(_ context.Context, project *models.Project, changesetID string, _, limit, offset int) ([]map[string]interface{}, error)

func (*Local) Status

func (l *Local) Status(_ context.Context, project *models.Project) (map[string]interface{}, error)

type Op

type Op struct {
	ID        string                 `json:"id"`
	Type      string                 `json:"type"`
	Args      map[string]interface{} `json:"args"`
	CreatedAt string                 `json:"created_at"`
}

Op is one staged schema mutation. Old draft files use this shape.

type Operation

type Operation struct {
	ID          string
	Type        string
	ModelName   string
	FieldName   string
	Payload     map[string]interface{}
	Summary     string
	Destructive bool
	CreatedAt   string
}

Operation is one staged schema mutation. The public draft file and the Cloud changeset replay this same shape.

type Publisher

type Publisher func(ctx context.Context, project *models.Project, ops []Op) error

Publisher applies staged operations to the live project. The public engine replays them synchronously. A returned error keeps the draft file.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL