config

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2025 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Module = fx.Module("config", fx.Provide(

	func() (*Config, error) {

		if _, err := os.Stat("housekeeper.yaml"); os.IsNotExist(err) {

			return nil, nil
		}

		return LoadConfigFile("housekeeper.yaml")
	},
	func(c *Config) *format.Formatter {
		return c.GetFormatter()
	},
))

Functions

This section is empty.

Types

type ClickHouse

type ClickHouse struct {
	// Version specifies the target ClickHouse version for schema compatibility
	// This helps ensure generated DDL is compatible with the specified version
	Version string `yaml:"version,omitempty"`

	// ConfigDir specifies the directory where ClickHouse configuration files are stored
	// This directory is used for managing ClickHouse server configuration fragments
	ConfigDir string `yaml:"config_dir,omitempty"`

	// Cluster specifies the default cluster name for distributed ClickHouse deployments
	// This is used for ON CLUSTER operations and distributed DDL statements
	Cluster string `yaml:"cluster,omitempty"`

	// IgnoreDatabases specifies a list of database names to exclude from schema operations
	// These databases will be ignored during dump and diff operations
	IgnoreDatabases []string `yaml:"ignore_databases,omitempty"`
}

ClickHouse represents ClickHouse-specific configuration settings.

This struct contains configuration values that are specific to the ClickHouse database system, including version compatibility and configuration file management.

type Config

type Config struct {
	// ClickHouse contains ClickHouse-specific configuration settings
	ClickHouse ClickHouse `yaml:"clickhouse"`

	// FormatOptions contains formatter configuration settings
	FormatOptions *FormatterOptionsConfig `yaml:"format_options,omitempty"`

	// Entrypoint specifies the main SQL file that serves as the entry point for the schema
	Entrypoint string `yaml:"entrypoint"`

	// Dir specifies the directory where migration files are stored
	Dir string `yaml:"dir"`
}

Config represents the project configuration for ClickHouse schema management.

func LoadConfig

func LoadConfig(r io.Reader) (*Config, error)

LoadConfig parses a schema configuration from the provided io.Reader.

The function expects YAML-formatted configuration data that defines the project schema entry point and migration directory. It uses a streaming YAML decoder to handle configuration files efficiently. If no ClickHouse version is specified, it defaults to DefaultClickHouseVersion.

Parameters:

  • r: An io.Reader containing YAML configuration data

Returns:

  • *Config: Successfully parsed configuration
  • error: Any parsing or validation errors encountered

Example:

import (
	"strings"
	"github.com/pseudomuto/housekeeper/pkg/config"
)

yamlData := `
entrypoint: db/main.sql
dir: db/migrations
`

cfg, err := config.LoadConfig(strings.NewReader(yamlData))
if err != nil {
	panic(err)
}

fmt.Printf("Schema entrypoint: %s\n", cfg.Entrypoint)

func LoadConfigFile

func LoadConfigFile(path string) (*Config, error)

LoadConfigFile loads a project configuration from the specified file path. This is a convenience function that opens the file and calls LoadConfig.

Example:

cfg, err := config.LoadConfigFile("housekeeper.yaml")
if err != nil {
	log.Fatal("Failed to load config:", err)
}

fmt.Printf("Entrypoint: %s, Migration dir: %s\n", cfg.Entrypoint, cfg.Dir)

func (*Config) GetFormatter added in v0.1.7

func (c *Config) GetFormatter() *format.Formatter

GetFormatter creates a new formatter instance using the merged formatter options.

This is a convenience method that combines GetFormatterOptions with formatter creation. It returns a properly configured formatter that respects both default settings and user overrides from the configuration file.

func (*Config) GetFormatterOptions added in v0.1.7

func (c *Config) GetFormatterOptions() format.FormatterOptions

GetFormatterOptions returns the merged formatter options, combining defaults with user configuration.

This method starts with the default formatter options and applies any non-nil values from the user configuration. This ensures that unspecified values retain their defaults while allowing users to selectively override specific settings, including zero values.

type FormatterOptionsConfig added in v0.1.7

type FormatterOptionsConfig struct {
	// IndentSize specifies the number of spaces to use for indentation
	IndentSize *int `yaml:"indent_size,omitempty"`

	// MaxLineLength suggests when to break long lines (0 = no limit)
	MaxLineLength *int `yaml:"max_line_length,omitempty"`

	// UppercaseKeywords controls whether SQL keywords are formatted in uppercase
	UppercaseKeywords *bool `yaml:"uppercase_keywords,omitempty"`

	// AlignColumns controls whether column definitions are aligned in CREATE TABLE statements
	AlignColumns *bool `yaml:"align_columns,omitempty"`

	// MultilineFunctions enables multi-line formatting for complex function expressions
	MultilineFunctions *bool `yaml:"multiline_functions,omitempty"`

	// FunctionArgThreshold is the number of function arguments that triggers multi-line formatting
	FunctionArgThreshold *int `yaml:"function_arg_threshold,omitempty"`

	// MultilineFunctionNames contains function names that should always be formatted multi-line
	MultilineFunctionNames []string `yaml:"multiline_function_names,omitempty"`

	// FunctionIndentSize specifies extra indentation for function arguments (defaults to IndentSize)
	FunctionIndentSize *int `yaml:"function_indent_size,omitempty"`

	// SmartFunctionPairing enables intelligent argument pairing for conditional functions
	SmartFunctionPairing *bool `yaml:"smart_function_pairing,omitempty"`

	// PairedFunctionNames specifies which function names should use paired argument formatting
	PairedFunctionNames []string `yaml:"paired_function_names,omitempty"`

	// PairSize specifies how many arguments constitute a pair for paired formatting
	PairSize *int `yaml:"pair_size,omitempty"`
}

FormatterOptionsConfig represents format configuration settings that can be specified in YAML.

This struct uses pointer fields to distinguish between explicitly set zero values and unspecified values in the YAML configuration. This allows proper merging with default values where only non-nil user values override the defaults.

Jump to

Keyboard shortcuts

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