Documentation
¶
Overview ¶
Package prune removes obsolete models in bounded batches, like Laravel's Prunable and MassPrunable models. Applications declare each prunable model with a typed selection; the registry runs them explicitly (for example from a scheduled command). Nothing prunes during boot.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Count ¶
type Count struct {
Name Name `json:"name"`
Removed int64 `json:"removed"`
// Remaining is true when MaxBatches stopped the run before a short batch.
Remaining bool `json:"remaining,omitempty"`
}
Count reports one declaration's committed removals.
type Options ¶
Options bounds one run. Each batch is its own transaction.
func DefaultOptions ¶
func DefaultOptions() Options
DefaultOptions removes up to 100 batches of 500 models per declaration.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry holds validated declarations in name order.
func (*Registry) Run ¶
func (r *Registry) Run(ctx context.Context, db database.Transactor, options Options, selected ...Name) (Result, error)
Run prunes the selected declarations (all when none are named) in name order, batch by batch, until a batch removes fewer than BatchSize models or MaxBatches is reached. A failure stops the run and reports confirmed work.
type Result ¶
Result lists committed removals. StoppedAt names the declaration whose batch failed; earlier batches, including its own, remain committed.
type Target ¶
type Target struct {
// contains filtered or unexported fields
}
Target is one prunable model declaration; use ORMModel or ORMSoftModel.
func ORMModel ¶
ORMModel registers an ordinary ORM model for bounded lifecycle or mass pruning. Example: prune.ORMModel("app.logs", Logs.Query(), prune.Lifecycle).
func ORMSoftModel ¶
func ORMSoftModel[M any](name Name, selection orm.Query[M], soft orm.SoftDeletable[M], mode Mode) Target
ORMSoftModel registers physical pruning with the exact soft-model declaration token. Example: prune.ORMSoftModel("app.users", Users.Query().OnlyTrashed(), Users.Soft, prune.Mass).