migrate

package
v0.1.13 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ChannelTypeScript

func ChannelTypeScript(detail api.ChannelDetail) string

ChannelTypeScript renders a TypeScript interface for one channel schema.

func CopyUploads

func CopyUploads(ctx context.Context, fromClient, toClient *api.Client, fromRef, toRef SiteRef, dryRun bool) (UploadCopyResult, *MediaRewritePlan, error)

func NormalizeChannel

func NormalizeChannel(detail api.ChannelDetail) map[string]any

NormalizeChannel strips unstable fields from a channel detail.

func NormalizeCustomizations

func NormalizeCustomizations(fields []api.CustomField) []map[string]any

NormalizeCustomizations strips unstable fields from a customization slice.

func ParseSinceValue

func ParseSinceValue(raw string, now time.Time) (string, error)

ParseSinceValue accepts RFC3339 or compact relative durations like 1d, 2w, 3h.

func ValidateEntries

func ValidateEntries(ctx context.Context, fromClient, toClient *api.Client,
	mapping map[string]map[string]string,
	channelMap map[string]api.ChannelDetail,
) []string

ValidateEntries re-fetches source and target entries after copy, compares them field-by-field, and returns warnings for any mismatches. It never returns an error — fetch failures are reported as warnings.

func WithCopyObserver

func WithCopyObserver(ctx context.Context, obs CopyObserver) context.Context

WithCopyObserver stores a CopyObserver in the context.

Types

type BlogCopyItem

type BlogCopyItem struct {
	Blog   string `json:"blog"`
	Slug   string `json:"slug,omitempty"`
	Kind   string `json:"kind"`
	Action string `json:"action"`
}

BlogCopyItem describes one copied blog or post.

type BlogCopyResult

type BlogCopyResult struct {
	From  SiteRef        `json:"from"`
	To    SiteRef        `json:"to"`
	Query string         `json:"query"`
	Items []BlogCopyItem `json:"items,omitempty"`
}

BlogCopyResult reports blog copy results.

func CopyBlogs

func CopyBlogs(ctx context.Context, fromClient, toClient *api.Client, fromRef, toRef SiteRef, query string, media *MediaRewritePlan, dryRun bool) (BlogCopyResult, error)

CopyBlogs copies blogs and their posts between sites.

type ChannelCopyItem

type ChannelCopyItem struct {
	Source string `json:"source"`
	Target string `json:"target"`
	Action string `json:"action"`
}

ChannelCopyItem describes one copied channel.

type ChannelCopyOptions added in v0.1.13

type ChannelCopyOptions struct {
	DryRun          bool
	Existing        ExistingContentAction
	ResolveExisting ExistingContentResolver
	// contains filtered or unexported fields
}

ChannelCopyOptions controls channel copy behavior.

type ChannelCopyResult

type ChannelCopyResult struct {
	From         SiteRef           `json:"from"`
	To           SiteRef           `json:"to"`
	Items        []ChannelCopyItem `json:"items,omitempty"`
	Placeholders []string          `json:"placeholders,omitempty"`
}

ChannelCopyResult reports one or many copied channels.

func CopyAllChannels

func CopyAllChannels(ctx context.Context, fromClient, toClient *api.Client, fromRef, toRef SiteRef, dryRun bool) (ChannelCopyResult, error)

CopyAllChannels copies all channels from source to target.

func CopyAllChannelsWithOptions added in v0.1.13

func CopyAllChannelsWithOptions(ctx context.Context, fromClient, toClient *api.Client, fromRef, toRef SiteRef, opts ChannelCopyOptions) (ChannelCopyResult, error)

CopyAllChannelsWithOptions copies all channels from source to target.

func CopyChannel

func CopyChannel(ctx context.Context, fromClient, toClient *api.Client, fromRef, toRef ChannelRef) (ChannelCopyResult, error)

CopyChannel copies one channel definition.

type ChannelDiffResult

type ChannelDiffResult struct {
	From        ChannelRef `json:"from"`
	To          ChannelRef `json:"to"`
	ChannelDiff DiffSet    `json:"channel_diff"`
	FieldsDiff  DiffSet    `json:"fields_diff"`
}

ChannelDiffResult reports channel-level and field-level differences.

func DiffChannel

func DiffChannel(ctx context.Context, fromClient, toClient *api.Client, fromRef, toRef ChannelRef) (ChannelDiffResult, error)

DiffChannel compares two channel definitions after normalization.

type ChannelInfoResult

type ChannelInfoResult struct {
	Channel      api.ChannelDetail `json:"channel"`
	Dependencies []string          `json:"dependencies,omitempty"`
	Dependants   []string          `json:"dependants,omitempty"`
	Circular     bool              `json:"circular"`
	TypeScript   string            `json:"typescript,omitempty"`
}

ChannelInfoResult exposes one channel plus dependency metadata.

func ChannelInfo

func ChannelInfo(ctx context.Context, client *api.Client, ref ChannelRef) (ChannelInfoResult, error)

ChannelInfo loads a channel plus dependency metadata and TS output.

type ChannelRef

type ChannelRef struct {
	SiteRef
	Channel string `json:"channel"`
}

ChannelRef points at one channel on one site.

func ParseChannelRef

func ParseChannelRef(raw, hostOverride, defaultSite, defaultBaseURL string) (ChannelRef, error)

ParseChannelRef parses `site/channel` or `channel`.

type CollectionCopyItem

type CollectionCopyItem struct {
	Slug   string `json:"slug"`
	Name   string `json:"name"`
	Action string `json:"action"`
}

CollectionCopyItem describes one copied collection.

type CollectionCopyOptions

type CollectionCopyOptions struct {
	AllowErrors    bool
	DryRun         bool
	Media          *MediaRewritePlan
	ProductMapping map[string]string
}

CollectionCopyOptions controls collection copy behavior.

type CollectionCopyResult

type CollectionCopyResult struct {
	From  SiteRef              `json:"from"`
	To    SiteRef              `json:"to"`
	Items []CollectionCopyItem `json:"items,omitempty"`
}

CollectionCopyResult reports collection copy results.

func CopyCollections

func CopyCollections(ctx context.Context, fromClient, toClient *api.Client, fromRef, toRef SiteRef, opts CollectionCopyOptions) (CollectionCopyResult, error)

CopyCollections copies product collections between sites.

type CopyObserver

type CopyObserver = observer.CopyObserver

CopyObserver is an alias for the shared observer interface.

func ObserverFromContext

func ObserverFromContext(ctx context.Context) CopyObserver

ObserverFromContext returns the CopyObserver from context, or a no-op observer.

type CustomizationCopyOptions added in v0.1.13

type CustomizationCopyOptions struct {
	DryRun   bool
	Existing ExistingContentAction
	Stage    string
}

CustomizationCopyOptions controls customization copy behavior.

type CustomizationCopyResult

type CustomizationCopyResult struct {
	Kind       CustomizationKind `json:"kind"`
	From       SiteRef           `json:"from"`
	To         SiteRef           `json:"to"`
	Action     string            `json:"action"`
	FieldCount int               `json:"field_count"`
}

CustomizationCopyResult reports one schema copy operation.

func CopyCustomizations

func CopyCustomizations(ctx context.Context, service CustomizationService, fromClient, toClient *api.Client, fromRef, toRef SiteRef, dryRun bool, stageLabels ...string) (CustomizationCopyResult, error)

CopyCustomizations copies one schema between sites.

func CopyCustomizationsWithOptions added in v0.1.13

func CopyCustomizationsWithOptions(ctx context.Context, service CustomizationService, fromClient, toClient *api.Client, fromRef, toRef SiteRef, opts CustomizationCopyOptions) (CustomizationCopyResult, error)

CopyCustomizationsWithOptions copies one schema between sites.

type CustomizationDiffResult

type CustomizationDiffResult struct {
	Kind CustomizationKind `json:"kind"`
	From SiteRef           `json:"from"`
	To   SiteRef           `json:"to"`
	Diff DiffSet           `json:"diff"`
}

CustomizationDiffResult reports normalized schema differences.

func DiffCustomizations

func DiffCustomizations(ctx context.Context, service CustomizationService, fromClient, toClient *api.Client, fromRef, toRef SiteRef) (CustomizationDiffResult, error)

DiffCustomizations diffs one schema between sites.

type CustomizationKind

type CustomizationKind string

CustomizationKind selects customer or product schemas.

const (
	CustomizationCustomers CustomizationKind = "customers"
	CustomizationProducts  CustomizationKind = "products"
)

type CustomizationService

type CustomizationService struct {
	Kind CustomizationKind
}

CustomizationService loads and writes customer/product customizations.

func (CustomizationService) Load

func (s CustomizationService) Load(ctx context.Context, client *api.Client) ([]api.CustomField, error)

Load fetches the schema.

func (CustomizationService) Write

func (s CustomizationService) Write(ctx context.Context, client *api.Client, fields []api.CustomField, replace bool) error

Write creates or replaces the schema.

type DiffChange

type DiffChange struct {
	Kind string `json:"kind"`
	Path string `json:"path"`
	From any    `json:"from,omitempty"`
	To   any    `json:"to,omitempty"`
}

DiffChange describes one normalized difference.

type DiffSet

type DiffSet struct {
	Added   []DiffChange `json:"added,omitempty"`
	Removed []DiffChange `json:"removed,omitempty"`
	Updated []DiffChange `json:"updated,omitempty"`
}

DiffSet groups added, removed, and updated changes.

func DiffNormalized

func DiffNormalized(from, to any) DiffSet

DiffNormalized compares two normalized values.

func (DiffSet) HasChanges

func (d DiffSet) HasChanges() bool

HasChanges reports whether any differences exist.

type ExistingContentAction added in v0.1.13

type ExistingContentAction string

ExistingContentAction describes how a copy operation should handle target content that already exists.

const (
	ExistingContentUpdate ExistingContentAction = "update"
	ExistingContentSkip   ExistingContentAction = "skip"
	ExistingContentReview ExistingContentAction = "review"
	ExistingContentAbort  ExistingContentAction = "abort"
)

type ExistingContentDecision added in v0.1.13

type ExistingContentDecision struct {
	Action     ExistingContentAction
	ApplyToAll bool
}

ExistingContentDecision is returned by a type-level conflict resolver.

type ExistingContentPrompt added in v0.1.13

type ExistingContentPrompt struct {
	Type          string
	Item          string
	Source        string
	Target        string
	SourceCount   int
	ExistingCount int
}

ExistingContentPrompt describes a type-level conflict decision.

type ExistingContentResolver added in v0.1.13

type ExistingContentResolver func(context.Context, ExistingContentPrompt) (ExistingContentDecision, error)

ExistingContentResolver asks the caller how to handle existing target content.

type MediaRewritePlan

type MediaRewritePlan struct {
	// contains filtered or unexported fields
}

MediaRewritePlan tracks source upload URLs and rewrites matching strings to target URLs.

func NewMediaRewritePlan

func NewMediaRewritePlan() *MediaRewritePlan

NewMediaRewritePlan creates an empty media rewrite plan.

func (*MediaRewritePlan) Add

func (p *MediaRewritePlan) Add(sourceURL, targetURL string)

Add registers one source upload URL to target URL rewrite.

func (*MediaRewritePlan) RewriteString

func (p *MediaRewritePlan) RewriteString(path, value string) string

RewriteString rewrites known source upload URLs inside one string.

func (*MediaRewritePlan) RewriteValue

func (p *MediaRewritePlan) RewriteValue(path string, value any) any

RewriteValue rewrites matching URLs inside nested map/slice/string payloads in place.

func (*MediaRewritePlan) Warnings

func (p *MediaRewritePlan) Warnings() []string

Warnings returns deduplicated rewrite warnings collected so far.

type MenuCopyItem struct {
	Slug   string `json:"slug"`
	Action string `json:"action"`
}

MenuCopyItem describes one copied menu.

type MenuCopyOptions struct {
	DryRun          bool
	ErrorOnExisting bool
	Existing        ExistingContentAction
	Media           *MediaRewritePlan
	ResolveExisting ExistingContentResolver
}

MenuCopyOptions controls menu copy behavior.

type MenuCopyResult struct {
	From  SiteRef        `json:"from"`
	To    SiteRef        `json:"to"`
	Query string         `json:"query"`
	Items []MenuCopyItem `json:"items,omitempty"`
}

MenuCopyResult reports menu copy results.

func CopyMenus

func CopyMenus(ctx context.Context, fromClient, toClient *api.Client, fromRef, toRef SiteRef, query string, overwriteExisting bool, media *MediaRewritePlan, dryRun bool) (MenuCopyResult, error)

CopyMenus copies nested menu documents. When overwriteExisting is false, existing menus return an error.

func CopyMenusWithOptions added in v0.1.13

func CopyMenusWithOptions(ctx context.Context, fromClient, toClient *api.Client, fromRef, toRef SiteRef, query string, opts MenuCopyOptions) (MenuCopyResult, error)

CopyMenusWithOptions copies nested menu documents.

type NotificationCopyItem

type NotificationCopyItem struct {
	Slug   string `json:"slug"`
	Name   string `json:"name"`
	Action string `json:"action"`
}

NotificationCopyItem describes one copied notification.

type NotificationCopyResult

type NotificationCopyResult struct {
	From  SiteRef                `json:"from"`
	To    SiteRef                `json:"to"`
	Query string                 `json:"query"`
	Items []NotificationCopyItem `json:"items,omitempty"`
}

NotificationCopyResult reports notification copy results.

func CopyNotifications

func CopyNotifications(ctx context.Context, fromClient, toClient *api.Client, fromRef, toRef SiteRef, query string, media *MediaRewritePlan, dryRun bool) (NotificationCopyResult, error)

CopyNotifications copies notification templates between sites.

type PageCopyItem

type PageCopyItem struct {
	Fullpath string `json:"fullpath"`
	Action   string `json:"action"`
}

PageCopyItem describes one copied page.

type PageCopyResult

type PageCopyResult struct {
	From     SiteRef        `json:"from"`
	To       SiteRef        `json:"to"`
	Query    string         `json:"query"`
	Items    []PageCopyItem `json:"items,omitempty"`
	Warnings []string       `json:"warnings,omitempty"`
}

PageCopyResult reports page copy results.

func CopyPages

func CopyPages(ctx context.Context, fromClient, toClient *api.Client, fromRef, toRef SiteRef, query string, media *MediaRewritePlan, dryRun bool) (PageCopyResult, error)

CopyPages copies pages matching query (`*`, prefix*, exact).

type ProductCopyItem

type ProductCopyItem struct {
	Slug   string `json:"slug"`
	Name   string `json:"name"`
	Action string `json:"action"`
}

ProductCopyItem describes one copied product.

type ProductCopyOptions

type ProductCopyOptions struct {
	AllowErrors bool
	DryRun      bool
	Media       *MediaRewritePlan
	Upsert      string
}

ProductCopyOptions controls product copy behavior.

type ProductCopyResult

type ProductCopyResult struct {
	From  SiteRef           `json:"from"`
	To    SiteRef           `json:"to"`
	Items []ProductCopyItem `json:"items,omitempty"`
}

ProductCopyResult reports product copy results.

func CopyProducts

func CopyProducts(ctx context.Context, fromClient, toClient *api.Client, fromRef, toRef SiteRef, opts ProductCopyOptions) (ProductCopyResult, map[string]string, error)

CopyProducts copies products between sites and returns an ID mapping for collection remapping.

type RecordCopyItem

type RecordCopyItem struct {
	Action     string                    `json:"action"`
	Identifier string                    `json:"identifier"`
	Resource   string                    `json:"resource"`
	SourceID   string                    `json:"source_id,omitempty"`
	TargetID   string                    `json:"target_id,omitempty"`
	Localized  []RecordLocalizedCopyItem `json:"localized,omitempty"`
}

RecordCopyItem captures one copied record.

type RecordCopyOptions

type RecordCopyOptions struct {
	AllowErrors    bool
	CopyCustomers  bool
	DryRun         bool
	Media          *MediaRewritePlan
	Only           []string
	PasswordLength int
	PerPage        int
	Query          string
	Recursive      bool
	Stage          string
	Upsert         string
	Where          string
}

RecordCopyOptions controls entry/customer copy behavior.

type RecordCopyResult

type RecordCopyResult struct {
	From     SiteRef          `json:"from"`
	To       SiteRef          `json:"to"`
	Resource string           `json:"resource"`
	Items    []RecordCopyItem `json:"items,omitempty"`
	Warnings []string         `json:"warnings,omitempty"`
}

RecordCopyResult reports raw record copy output.

func CopyChannelEntries

func CopyChannelEntries(ctx context.Context, fromClient, toClient *api.Client, fromRef, toRef ChannelRef, opts RecordCopyOptions) (RecordCopyResult, error)

CopyChannelEntries copies entries between channels, optionally recursing into dependencies.

func CopyCustomers

func CopyCustomers(ctx context.Context, fromClient, toClient *api.Client, fromRef, toRef SiteRef, opts RecordCopyOptions) (RecordCopyResult, error)

CopyCustomers copies customers between sites.

func CopySiteEntries

func CopySiteEntries(ctx context.Context, fromClient, toClient *api.Client, fromRef, toRef SiteRef,
	channels []string, opts RecordCopyOptions,
) ([]RecordCopyResult, error)

CopySiteEntries copies entries across multiple channels using a shared ID mapping, dependency-aware ordering, and deferred resolution for circular references.

type RecordLocalizedCopyItem added in v0.1.7

type RecordLocalizedCopyItem struct {
	Locale string   `json:"locale"`
	Action string   `json:"action"`
	Fields []string `json:"fields,omitempty"`
}

RecordLocalizedCopyItem captures a localized entry-field copy action.

type RedirectCopyItem

type RedirectCopyItem struct {
	Source string `json:"source"`
	Action string `json:"action"`
}

RedirectCopyItem describes one copied redirect.

type RedirectCopyResult

type RedirectCopyResult struct {
	From  SiteRef            `json:"from"`
	To    SiteRef            `json:"to"`
	Items []RedirectCopyItem `json:"items,omitempty"`
}

RedirectCopyResult reports redirect copy results.

func CopyRedirects

func CopyRedirects(ctx context.Context, fromClient, toClient *api.Client, fromRef, toRef SiteRef, dryRun bool) (RedirectCopyResult, error)

CopyRedirects copies URL redirects between sites.

type RoleCopyItem

type RoleCopyItem struct {
	Name   string `json:"name"`
	Action string `json:"action"`
}

RoleCopyItem describes one copied role.

type RoleCopyResult

type RoleCopyResult struct {
	From  SiteRef        `json:"from"`
	To    SiteRef        `json:"to"`
	Items []RoleCopyItem `json:"items,omitempty"`
}

RoleCopyResult reports role copy results.

func CopyRoles

func CopyRoles(ctx context.Context, fromClient, toClient *api.Client, fromRef, toRef SiteRef, dryRun bool) (RoleCopyResult, error)

CopyRoles copies customer roles between sites.

type SiteCopyOptions

type SiteCopyOptions struct {
	AllowErrors      bool
	ConflictResolver ExistingContentResolver
	CopyCustomers    bool
	DryRun           bool
	Include          []string
	Only             []string
	Recursive        bool
	Upsert           string
	Force            bool
}

SiteCopyOptions controls site copy orchestration.

type SiteCopyResult

type SiteCopyResult struct {
	From           SiteRef                 `json:"from"`
	To             SiteRef                 `json:"to"`
	DryRun         bool                    `json:"dry_run,omitempty"`
	Uploads        UploadCopyResult        `json:"uploads"`
	Channels       ChannelCopyResult       `json:"channels"`
	ChannelEntries []RecordCopyResult      `json:"channel_entries,omitempty"`
	CustomerConfig CustomizationCopyResult `json:"customer_config"`
	ProductConfig  CustomizationCopyResult `json:"product_config"`
	Roles          RoleCopyResult          `json:"roles"`
	Products       ProductCopyResult       `json:"products"`
	Collections    CollectionCopyResult    `json:"collections"`
	Theme          themes.CopyResult       `json:"theme"`
	Pages          PageCopyResult          `json:"pages"`
	Menus          MenuCopyResult          `json:"menus"`
	Blogs          BlogCopyResult          `json:"blogs"`
	Notifications  NotificationCopyResult  `json:"notifications"`
	Redirects      RedirectCopyResult      `json:"redirects"`
	Translations   TranslationCopyResult   `json:"translations"`
	Warnings       []string                `json:"warnings,omitempty"`
}

SiteCopyResult groups stage outputs.

func CopySite

func CopySite(ctx context.Context, fromClient, toClient *api.Client, fromRef, toRef SiteRef, opts SiteCopyOptions) (SiteCopyResult, error)

CopySite orchestrates a broad site migration.

type SiteRef

type SiteRef struct {
	BaseURL string `json:"base_url"`
	Site    string `json:"site"`
}

SiteRef points at one site on one API host.

func ParseSiteRef

func ParseSiteRef(raw, hostOverride, defaultSite, defaultBaseURL string) (SiteRef, error)

ParseSiteRef parses `[site]` plus optional host override.

type ThemeRef

type ThemeRef struct {
	SiteRef
	Theme string `json:"theme"`
}

ThemeRef points at one theme on one site.

func ParseThemeRef

func ParseThemeRef(raw, hostOverride, defaultSite, defaultBaseURL string) (ThemeRef, error)

ParseThemeRef parses `site[/theme]`.

type TranslationCopyItem

type TranslationCopyItem struct {
	Key    string `json:"key"`
	Action string `json:"action"`
}

TranslationCopyItem describes one copied translation.

type TranslationCopyOptions

type TranslationCopyOptions struct {
	Query  string
	Since  string
	DryRun bool
	Media  *MediaRewritePlan
}

TranslationCopyOptions filters translations during copy.

type TranslationCopyResult

type TranslationCopyResult struct {
	From   SiteRef               `json:"from"`
	To     SiteRef               `json:"to"`
	Query  string                `json:"query"`
	Since  string                `json:"since,omitempty"`
	DryRun bool                  `json:"dry_run,omitempty"`
	Items  []TranslationCopyItem `json:"items,omitempty"`
}

TranslationCopyResult reports translation copy work.

func CopyTranslations

func CopyTranslations(ctx context.Context, fromClient, toClient *api.Client, fromRef, toRef SiteRef, opts TranslationCopyOptions) (TranslationCopyResult, error)

CopyTranslations copies translations between sites.

type UploadCopyItem

type UploadCopyItem struct {
	Action    string `json:"action"`
	Name      string `json:"name"`
	Size      int64  `json:"size,omitempty"`
	SourceID  string `json:"source_id,omitempty"`
	SourceURL string `json:"source_url,omitempty"`
	TargetID  string `json:"target_id,omitempty"`
	TargetURL string `json:"target_url,omitempty"`
}

UploadCopyItem describes one copied or reused upload.

type UploadCopyResult

type UploadCopyResult struct {
	From     SiteRef          `json:"from"`
	To       SiteRef          `json:"to"`
	Items    []UploadCopyItem `json:"items,omitempty"`
	Warnings []string         `json:"warnings,omitempty"`
}

UploadCopyResult reports upload copy work.

Jump to

Keyboard shortcuts

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