export

package
v0.2.0 Latest Latest
Warning

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

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

Documentation

Overview

Package export implements the `export` subcommand's core: reading the current state of every configured workspace out of the repository and writing it, one table per entity, to a pluggable Sink (BigQuery today). The Exporter is sink-agnostic — it builds a generic Table (typed columns + rows of natural Go values) and hands it to the Sink, which owns all backend-specific concerns (schema evolution, full-refresh, encoding). This keeps a future Cloud Storage sink a drop-in without touching the read/normalize logic here.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Column

type Column struct {
	// Name is the column name (fixed columns are snake_case; custom fields are
	// "field_<id>").
	Name string
	// Type is the logical column type.
	Type ColumnType
	// Repeated marks an array column (ARRAY<Type>).
	Repeated bool
	// Nullable marks a nullable column. A non-nullable, non-repeated column is
	// REQUIRED in the sink's schema.
	Nullable bool
}

Column describes one output column.

type ColumnType

type ColumnType string

ColumnType is the backend-neutral logical type of a Table column. A Sink maps it to its own type system (e.g. BigQuery STRING/INT64/...).

const (
	TypeString    ColumnType = "STRING"
	TypeInt       ColumnType = "INT64"
	TypeFloat     ColumnType = "FLOAT64"
	TypeBool      ColumnType = "BOOL"
	TypeTimestamp ColumnType = "TIMESTAMP"
)

type Exporter

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

Exporter reads workspace data from the repository and writes it to a Sink. It holds no mutable state across a run.

func New

func New(repo interfaces.Repository, sink Sink, opts ...Option) *Exporter

New builds an Exporter. repo and sink are required; opts are optional. The per-workspace privacy policy travels on each Target, not here.

func (*Exporter) Run

func (e *Exporter) Run(ctx context.Context, targets []Target) error

Run exports every target. A failure on one target is logged and collected but does not stop the others; all collected failures are returned joined so the caller (and its error reporter) sees every one.

Single-instance assumption: Run is designed to be invoked by ONE process at a time. The per-table refresh (TRUNCATE then append via the sink) is not atomic and takes no distributed lock, so two overlapping exports of the same destination can interleave and duplicate rows. This is a deliberate, documented constraint (the export is a singly-run batch job, e.g. a scheduled task with no overlap), not an oversight — see docs/export.md.

type Option

type Option func(*Exporter)

Option customizes an Exporter.

func WithTablePrefix

func WithTablePrefix(prefix string) Option

WithTablePrefix prepends prefix to every table name. It is empty in production (tables are named exactly cases/actions/...); tests use it to write uniquely-named tables into a shared dataset without recreating the dataset.

type Sink

type Sink interface {
	// WriteTable replaces the table's schema and data within namespace.
	WriteTable(ctx context.Context, namespace string, table *Table) error
	io.Closer
}

Sink is a destination that fully replaces (洗替) a table's schema and rows. Implementations MUST make each WriteTable a full refresh of the named table within the given namespace.

type Table

type Table struct {
	Name    string
	Columns []Column
	Rows    []map[string]any
}

Table is a full-refresh unit: a named table with a typed schema and its rows. Row values are natural Go types keyed by column name; a missing key is NULL. Backend-specific encoding (e.g. TIMESTAMP -> microseconds) is the Sink's job.

type Target

type Target struct {
	Entry     *model.WorkspaceEntry
	Namespace string
	// ExcludePrivate, when true, omits this workspace's private Cases (and their
	// Actions / Memos). It is resolved per workspace by the caller.
	ExcludePrivate bool
}

Target binds one workspace to its destination namespace (a BigQuery dataset) and its per-workspace privacy policy.

Jump to

Keyboard shortcuts

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