Help us shape the future of Go! Take the 2026 Go Developer Survey

diff

package
v0.11.784 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseDateTime added in v0.11.245

func ParseDateTime(value interface{}) (*time.Time, error)

ParseDateTime converts various datetime representations to time.Time. This is a shared utility function used across all database implementations.

func SampleSizeFromContext added in v0.11.646

func SampleSizeFromContext(ctx context.Context) int64

SampleSizeFromContext returns the sample size set via WithSampleSize, or 0 if none was set, in which case the whole table should be scanned.

func WithSampleSize added in v0.11.646

func WithSampleSize(ctx context.Context, size int64) context.Context

WithSampleSize stores the maximum number of records a summarizer should read when producing a table summary. A value <= 0 means "scan everything".

Only summarizers that support sampling (currently MongoDB) honor this; the SQL-backed summarizers ignore it and always scan the full table.

Types

type AlterStatementGenerator added in v0.11.359

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

AlterStatementGenerator generates ALTER TABLE statements based on schema comparison results.

func NewAlterStatementGenerator added in v0.11.359

func NewAlterStatementGenerator(dialect DatabaseDialect, reverse bool) *AlterStatementGenerator

NewAlterStatementGenerator creates a new ALTER statement generator with the specified dialect.

func (*AlterStatementGenerator) GenerateAlterStatements added in v0.11.359

func (g *AlterStatementGenerator) GenerateAlterStatements(result *SchemaComparisonResult) []string

GenerateAlterStatements generates ALTER TABLE SQL statements to transform one table to match another. By default (reverse=false), it generates statements to transform Table2 to match Table1. If reverse=true, it generates statements to transform Table1 to match Table2.

type BooleanStatistics

type BooleanStatistics struct {
	TrueCount  int64
	FalseCount int64
	NullCount  int64
	Count      int64
}

func (*BooleanStatistics) Type

func (bs *BooleanStatistics) Type() string

type Column

type Column struct {
	Name           string
	Type           string         // Original database-specific type (e.g., "INTEGER", "VARCHAR(255)")
	NormalizedType CommonDataType // Normalized common type (e.g., "numeric", "string")
	Nullable       bool
	PrimaryKey     bool
	Unique         bool

	Stats ColumnStatistics
}

type ColumnDifference

type ColumnDifference struct {
	ColumnName            string
	TypeDifference        *TypeDifference
	NullabilityDifference *NullabilityDifference
	UniquenessDifference  *UniquenessDifference
}

ColumnDifference represents differences for a column that exists in both tables.

type ColumnStatistics

type ColumnStatistics interface {
	Type() string
}

ColumnStatistics is an interface for different types of column statistics.

type CommonDataType

type CommonDataType string

CommonDataType represents the normalized data type categories.

const (
	CommonTypeNumeric  CommonDataType = "numeric"
	CommonTypeString   CommonDataType = "string"
	CommonTypeBoolean  CommonDataType = "boolean"
	CommonTypeDateTime CommonDataType = "datetime"
	CommonTypeBinary   CommonDataType = "binary"
	CommonTypeJSON     CommonDataType = "json"
	CommonTypeUnknown  CommonDataType = "unknown"
)

type CostEstimator added in v0.11.458

type CostEstimator interface {
	EstimateTableDiffCost(ctx context.Context, tableName string, schemaOnly bool) (*TableDiffCostEstimate, error)
}

type DatabaseDialect added in v0.11.359

type DatabaseDialect string

DatabaseDialect represents the SQL dialect for generating ALTER TABLE statements.

const (
	DialectPostgreSQL DatabaseDialect = "postgresql"
	DialectSnowflake  DatabaseDialect = "snowflake"
	DialectBigQuery   DatabaseDialect = "bigquery"
	DialectDuckDB     DatabaseDialect = "duckdb"
	DialectTSQL       DatabaseDialect = "tsql"
	DialectGeneric    DatabaseDialect = "generic"
)

func DetectDialectFromConnection added in v0.11.359

func DetectDialectFromConnection(conn1Type, conn2Type string) DatabaseDialect

DetectDialectFromConnection detects the database dialect from connection type names.

type DatabaseTypeMapper

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

DatabaseTypeMapper provides a base implementation for type mapping.

func NewBigQueryTypeMapper

func NewBigQueryTypeMapper() *DatabaseTypeMapper

NewBigQueryTypeMapper provides BigQuery-specific type mapping.

func NewDatabaseTypeMapper

func NewDatabaseTypeMapper() *DatabaseTypeMapper

func NewDuckDBTypeMapper

func NewDuckDBTypeMapper() *DatabaseTypeMapper

NewDuckDBTypeMapper provides DuckDB-specific type mapping.

func NewMongoTypeMapper added in v0.11.646

func NewMongoTypeMapper() *DatabaseTypeMapper

NewMongoTypeMapper provides MongoDB type mapping. The keys are the BSON type aliases reported by the aggregation `$type` operator (e.g. "double", "string", "objectId"), since MongoDB has no static catalog and types are inferred from the documents themselves.

func NewPostgresTypeMapper added in v0.11.226

func NewPostgresTypeMapper() *DatabaseTypeMapper

NewPostgresTypeMapper provides PostgreSQL-specific type mapping.

func NewSQLServerTypeMapper added in v0.11.673

func NewSQLServerTypeMapper() *DatabaseTypeMapper

NewSQLServerTypeMapper provides SQL Server-compatible type mapping, including Microsoft Fabric Warehouse types exposed through the TDS endpoint.

func NewSnowflakeTypeMapper added in v0.11.226

func NewSnowflakeTypeMapper() *DatabaseTypeMapper

NewSnowflakeTypeMapper provides Snowflake-specific type mapping.

func (*DatabaseTypeMapper) AddBinaryTypes

func (m *DatabaseTypeMapper) AddBinaryTypes(types ...string)

func (*DatabaseTypeMapper) AddBooleanTypes

func (m *DatabaseTypeMapper) AddBooleanTypes(types ...string)

func (*DatabaseTypeMapper) AddDateTimeTypes

func (m *DatabaseTypeMapper) AddDateTimeTypes(types ...string)

func (*DatabaseTypeMapper) AddJSONTypes

func (m *DatabaseTypeMapper) AddJSONTypes(types ...string)

func (*DatabaseTypeMapper) AddNumericTypes

func (m *DatabaseTypeMapper) AddNumericTypes(types ...string)

func (*DatabaseTypeMapper) AddStringTypes

func (m *DatabaseTypeMapper) AddStringTypes(types ...string)

func (*DatabaseTypeMapper) IsBoolean

func (m *DatabaseTypeMapper) IsBoolean(databaseType string) bool

func (*DatabaseTypeMapper) IsDateTime

func (m *DatabaseTypeMapper) IsDateTime(databaseType string) bool

func (*DatabaseTypeMapper) IsNumeric

func (m *DatabaseTypeMapper) IsNumeric(databaseType string) bool

func (*DatabaseTypeMapper) IsString

func (m *DatabaseTypeMapper) IsString(databaseType string) bool

func (*DatabaseTypeMapper) MapType

func (m *DatabaseTypeMapper) MapType(databaseType string) CommonDataType

type DateTimeStatistics

type DateTimeStatistics struct {
	EarliestDate *time.Time // Earliest datetime value or nil
	LatestDate   *time.Time // Latest datetime value or nil
	Count        int64
	NullCount    int64
	UniqueCount  int64
}

func (*DateTimeStatistics) Type

func (dts *DateTimeStatistics) Type() string

type DiffCostEstimate added in v0.11.458

type DiffCostEstimate struct {
	SourceTable         *TableDiffCostEstimate `json:"sourceTable"`
	TargetTable         *TableDiffCostEstimate `json:"targetTable"`
	TotalBytesProcessed int64                  `json:"totalBytesProcessed"`
	TotalBytesBilled    int64                  `json:"totalBytesBilled"`
}

type JSONStatistics

type JSONStatistics struct {
	Count     int64
	NullCount int64
}

func (*JSONStatistics) Type

func (js *JSONStatistics) Type() string

type MissingColumn

type MissingColumn struct {
	ColumnName  string
	Type        string
	Nullable    bool
	PrimaryKey  bool
	Unique      bool
	TableName   string // The table where this column exists
	MissingFrom string // The table where this column is missing
}

MissingColumn represents a column that exists in only one table.

type NullabilityDifference

type NullabilityDifference struct {
	Table1Nullable bool
	Table2Nullable bool
}

NullabilityDifference represents a difference in nullability between two tables.

type NumericalStatistics

type NumericalStatistics struct {
	Min       *float64 // pointer to handle NULL values
	Max       *float64
	Avg       *float64
	Sum       *float64
	Count     int64
	NullCount int64
	StdDev    *float64
}

NumericalStatistics holds statistics for numerical columns.

func (*NumericalStatistics) Type

func (ns *NumericalStatistics) Type() string

type QueryCostEstimate added in v0.11.458

type QueryCostEstimate struct {
	QueryType      string `json:"queryType"`
	Query          string `json:"query"`
	BytesProcessed int64  `json:"bytesProcessed"`
	BytesBilled    int64  `json:"bytesBilled"`
}

type SchemaComparisonResult

type SchemaComparisonResult struct {
	Table1 *TableSummaryResult
	Table2 *TableSummaryResult

	SamePropertiesCount      int                // Columns with identical properties in both tables
	DifferentPropertiesCount int                // Columns present in both tables but with different properties
	InTable1OnlyCount        int                // Columns present in table1 but not in table2
	InTable2OnlyCount        int                // Columns present in table2 but not in table1
	ColumnDifferences        []ColumnDifference // Structured differences for columns present in both tables
	MissingColumns           []MissingColumn    // Columns missing from one of the tables
	HasSchemaDifferences     bool               // True if DifferentPropertiesCount, InTable1OnlyCount, or InTable2OnlyCount > 0
	RowCountDiff             int64              // Difference in row count between the two tables
	HasRowCountDifference    bool               // True if RowCountDiff != 0
}

SchemaComparisonResult holds the detailed results of a table schema comparison.

func CompareTableSchemas

func CompareTableSchemas(summary1, summary2 *TableSummaryResult, t1Name, t2Name string) SchemaComparisonResult

func (*SchemaComparisonResult) GetSummaryTable

func (c *SchemaComparisonResult) GetSummaryTable() string

type SchemalessSummarizer added in v0.11.646

type SchemalessSummarizer interface {
	// IsSchemaless reports whether the source lacks a fixed, catalog-defined schema.
	IsSchemaless() bool
}

SchemalessSummarizer is implemented by TableSummarizers whose schema is inferred from the underlying data (e.g. MongoDB) rather than declared in a catalog. For such sources, data-diff omits ALTER TABLE statement generation, which has no meaning without a fixed, DDL-managed schema.

type StringStatistics

type StringStatistics struct {
	DistinctCount int64
	MaxLength     int
	MinLength     int
	AvgLength     float64
	Count         int64
	NullCount     int64
	EmptyCount    int64
	MostCommon    map[string]int64 // value -> frequency
	TopNDistinct  []string         // top N most common values
}

StringStatistics holds statistics for string/text columns.

func (*StringStatistics) Type

func (ss *StringStatistics) Type() string

type Table

type Table struct {
	Name    string
	Columns []*Column
}

type TableDiffCostEstimate added in v0.11.458

type TableDiffCostEstimate struct {
	TableName           string               `json:"tableName"`
	Queries             []*QueryCostEstimate `json:"queries"`
	TotalBytesProcessed int64                `json:"totalBytesProcessed"`
	TotalBytesBilled    int64                `json:"totalBytesBilled"`
	Supported           bool                 `json:"supported"`
	UnsupportedReason   string               `json:"unsupportedReason,omitempty"`
}

type TableSummarizer

type TableSummarizer interface {
	GetTableSummary(ctx context.Context, tableName string, schemaOnly bool) (*TableSummaryResult, error)
}

TableSummarizer defines an interface for connections that can provide a summary of a table.

type TableSummaryResult

type TableSummaryResult struct {
	RowCount int64
	Table    *Table
}

type Type

type Type struct {
	Name      string
	Size      int
	Precision int
	Scale     int
}

type TypeDifference

type TypeDifference struct {
	Table1Type           string
	Table2Type           string
	Table1NormalizedType CommonDataType
	Table2NormalizedType CommonDataType
	IsComparable         bool // True if normalized types are the same (e.g., both numeric)
}

TypeDifference represents a difference in column types between two tables.

type TypeMapping

type TypeMapping interface {
	MapType(databaseType string) CommonDataType
	IsNumeric(databaseType string) bool
	IsString(databaseType string) bool
	IsBoolean(databaseType string) bool
	IsDateTime(databaseType string) bool
}

TypeMapping defines the interface for mapping database-specific types to common types.

type UniquenessDifference

type UniquenessDifference struct {
	Table1Unique bool
	Table2Unique bool
}

UniquenessDifference represents a difference in uniqueness constraints between two tables.

type UnknownStatistics

type UnknownStatistics struct{}

func (*UnknownStatistics) Type

func (us *UnknownStatistics) Type() string

Jump to

Keyboard shortcuts

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