preset

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package preset knows the schemas of common platforms: where they keep personal data, how their tables link up, and which settings would let a staging copy act on real customers.

Index

Constants

This section is empty.

Variables

View Source
var Names = []string{"wordpress", "woocommerce", "magento2", "laravel"}

Names lists the presets that can be asked for by name.

Functions

func Safe

func Safe(s string) string

Safe returns s if it looks like an identifier (a hook, job or gateway name) and a placeholder otherwise, so no stored value can slip into a report through a label.

Types

type MetaTable

type MetaTable struct {
	Key, Value string
	Platform   string
	Keys       map[string]*detect.Hint       // known keys
	Probe      []string                      // keys worth reading directly if the sample misses them
	HintFor    func(key string) *detect.Hint // pattern-based hints
	Label      func(key string) string       // maps raw keys to names, e.g. Magento attribute IDs
	// Families are keys known to share a prefix, such as Ultimate Member's
	// per-user caches. They are grouped and probed by prefix.
	Families []detect.FamilyRule
	// Settings marks a table that holds one row per key, such as
	// wp_options, even when it lost its unique index.
	Settings bool
	// Primary marks the tables of the main site and the shared ones; a
	// scan spends its budgets on them first.
	Primary bool
	// Labels marks a translation table found without a preset: its keys
	// name UI strings, so only their values are judged.
	Labels bool
	// Guard marks a key/value table found without a preset by a shape data
	// tables can have too. Its keys must read as identifiers or labels; a
	// table keyed by people's names is judged as a plain table instead.
	Guard bool
}

MetaTable describes a key/value table such as wp_postmeta. Each key is judged on its own, as if it were a column.

func (*MetaTable) Hint

func (m *MetaTable) Hint(key string) *detect.Hint

Hint returns what the preset knows about one key.

type Querier

type Querier interface {
	QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
	QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
}

Querier is the part of *sql.DB the presets need.

type Result

type Result struct {
	Platforms     []model.Platform
	Columns       map[string]map[string]*detect.Hint // table → lower-case column → hint
	Meta          map[string]*MetaTable
	Actions       map[string]TableAction
	Relationships []model.Relationship
	Prefixes      []string
	SideEffects   []model.SideEffect
	RowSubjects   []RowSubject
	Warnings      []string
}

Result is everything the presets found.

func Detect

func Detect(ctx context.Context, q Querier, schema *model.Schema, which string, timeout time.Duration) *Result

Detect recognises platforms and collects their hints and side effects. which is "auto", "none" or one of Names.

func (*Result) ColumnHint

func (r *Result) ColumnHint(table, column string) *detect.Hint

ColumnHint returns the preset hint for a column, if any.

type RowSubject added in v0.3.0

type RowSubject struct {
	Table, Column string
	// Where selects the rows. It is a constant written in the preset,
	// never text from the database.
	Where string
	// IndexColumn must lead an index, so the rows are found without a
	// full scan; without one the subject is skipped.
	IndexColumn string
	Hint        *detect.Hint
}

RowSubject is a column whose data depends on the row, such as the title of a WordPress privacy request, which holds the requester's email.

type TableAction

type TableAction struct {
	Action string // "truncate"
	Reason string
}

TableAction is advice for a whole table, e.g. to empty it in the copy.

Jump to

Keyboard shortcuts

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