config

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseCapySquashYAML

func ParseCapySquashYAML(data []byte, config *CapySquashConfig) error

ParseCapySquashYAML parses YAML content into CapySquashConfig

Types

type Auth0Config

type Auth0Config struct {
	Enabled       bool     `json:"enabled"`
	Domain        string   `json:"domain"`
	CustomClaims  []string `json:"custom_claims"`
	RoleClaimPath string   `json:"role_claim_path"`
}

type AutoApplyConfig

type AutoApplyConfig struct {
	Enabled             bool     `yaml:"enabled" json:"enabled"`                             // Enable auto-apply
	Branches            []string `yaml:"branches" json:"branches"`                           // Branches to auto-apply on
	ExcludeBranches     []string `yaml:"exclude_branches" json:"exclude_branches"`           // Branches to never auto-apply
	RequireApprovalFrom []string `yaml:"require_approval_from" json:"require_approval_from"` // Require approval from users
}

AutoApplyConfig configures automatic application of optimizations

type BranchConfig

type BranchConfig struct {
	SafetyLevel    string `yaml:"safety_level" json:"safety_level"`         // Safety level for this branch
	FailOnWarnings bool   `yaml:"fail_on_warnings" json:"fail_on_warnings"` // Fail on warnings for this branch
}

BranchConfig configures branch-specific settings

type CapySquashConfig

type CapySquashConfig struct {
	// Core settings
	Enabled            bool   `yaml:"enabled" json:"enabled"`                         // Enable/disable pgsquash for this repository
	SafetyLevel        string `yaml:"safety_level" json:"safety_level"`               // paranoid | conservative | standard | aggressive
	MigrationThreshold int    `yaml:"migration_threshold" json:"migration_threshold"` // Minimum number of files to trigger consolidation suggestions

	// File patterns
	Include []string `yaml:"include" json:"include"` // File patterns to analyze
	Exclude []string `yaml:"exclude" json:"exclude"` // File patterns to exclude

	// PR comment settings
	PRComment PRCommentConfig `yaml:"pr_comment" json:"pr_comment"`

	// Pass/fail thresholds
	Checks ChecksConfig `yaml:"checks" json:"checks"`

	// Notification settings
	Notifications NotificationsConfig `yaml:"notifications" json:"notifications"`

	// Auto-apply settings (use with caution!)
	AutoApply AutoApplyConfig `yaml:"auto_apply" json:"auto_apply"`

	// Monorepo support
	Projects []ProjectConfig `yaml:"projects" json:"projects"`

	// Branch-specific settings
	Branches map[string]BranchConfig `yaml:"branches" json:"branches"`
}

CapySquashConfig represents the .capysquash.yml configuration file This file is used for per-repository GitHub integration settings It takes precedence over pgsquash.config.json for GitHub-specific settings

func DefaultCapySquashConfig

func DefaultCapySquashConfig() *CapySquashConfig

DefaultCapySquashConfig returns default configuration for .capysquash.yml

func LoadCapySquashConfig

func LoadCapySquashConfig(path string) (*CapySquashConfig, error)

LoadCapySquashConfig loads .capysquash.yml from the current directory or specified path

func LoadCapySquashConfigFromRepo

func LoadCapySquashConfigFromRepo(repoPath string) (*CapySquashConfig, error)

LoadCapySquashConfigFromRepo loads .capysquash.yml from a repository directory

func (*CapySquashConfig) GetBranchConfig

func (c *CapySquashConfig) GetBranchConfig(branchName string) *BranchConfig

GetBranchConfig returns branch-specific config if it exists

func (*CapySquashConfig) GetProjectConfig

func (c *CapySquashConfig) GetProjectConfig(files []string) *ProjectConfig

GetProjectConfig returns the project config for a given set of file paths (for monorepo support)

func (*CapySquashConfig) MergeWithEngineConfig

func (c *CapySquashConfig) MergeWithEngineConfig(engineConfig *Config) *Config

MergeWithEngineConfig merges CapySquashConfig into the engine Config CAPYSQUASH settings take precedence for overlapping fields

func (*CapySquashConfig) ShouldAnalyze

func (c *CapySquashConfig) ShouldAnalyze(files []string) bool

ShouldAnalyze determines if pgsquash should analyze the given files

func (*CapySquashConfig) ShouldAutoApply

func (c *CapySquashConfig) ShouldAutoApply(branchName string) bool

ShouldAutoApply determines if auto-apply should be used for the given branch

type ChecksConfig

type ChecksConfig struct {
	MaxWarnings         int             `yaml:"max_warnings" json:"max_warnings"`                   // Fail PR if warnings exceed this
	FailOnCritical      bool            `yaml:"fail_on_critical" json:"fail_on_critical"`           // Fail PR if critical warnings found
	FailOnWarnings      bool            `yaml:"fail_on_warnings" json:"fail_on_warnings"`           // Fail on any warnings
	FailOnDataLoss      bool            `yaml:"fail_on_data_loss" json:"fail_on_data_loss"`         // Fail on data loss operations
	MinReductionPercent int             `yaml:"min_reduction_percent" json:"min_reduction_percent"` // Require minimum file reduction percentage
	RequireOptimization bool            `yaml:"require_optimization" json:"require_optimization"`   // Fail if no migrations are optimized
	RequiredIndexes     []RequiredIndex `yaml:"required_indexes" json:"required_indexes"`           // Require specific indexes
}

ChecksConfig configures pass/fail thresholds for GitHub checks

type ClerkConfig

type ClerkConfig struct {
	Enabled               bool   `json:"enabled"`
	JWTVersion            string `json:"jwt_version"`
	OrganizationSupport   bool   `json:"organization_support"`
	PublicMetadataSupport bool   `json:"public_metadata_support"`
}

type Config

type Config struct {
	SafetyLevel            string                   `json:"safety_level"`
	ProdDBDSN              string                   `json:"prod_db_dsn"`
	Output                 OutputConfig             `json:"output"`
	Rules                  RulesConfig              `json:"rules"`
	ExcludePatterns        []string                 `json:"exclude_patterns"`
	IncludeSchemas         []string                 `json:"include_schemas"`
	Performance            PerformanceConfig        `json:"performance"`
	ModernFeatures         ModernFeaturesConfig     `json:"modern_features"`
	ConflictResolution     ConflictResolutionConfig `json:"conflict_resolution"`
	PostgreSQLFeatures     PostgreSQLFeaturesConfig `json:"postgresql_features"`
	ThirdPartyIntegrations ThirdPartyConfig         `json:"third_party_integrations"`
	Plugins                PluginSettings           `json:"plugins"`           // Plugin system configuration
	Validation             ValidationConfig         `json:"validation"`        // Docker validation configuration
	StaticValidation       StaticValidatorConfig    `json:"static_validation"` // Static analysis rules configuration
}

func DefaultConfig

func DefaultConfig() *Config

func LoadConfig

func LoadConfig(configPath string) (*Config, error)

func (*Config) SaveToFile

func (c *Config) SaveToFile(path string) error

func (*Config) Validate

func (c *Config) Validate() error

Validate checks if the config values are valid

type ConfigValidationError

type ConfigValidationError struct {
	Path   string
	Errors []string
}

ConfigValidationError represents config validation errors with helpful messages

func (*ConfigValidationError) Error

func (e *ConfigValidationError) Error() string

type ConflictResolutionConfig

type ConflictResolutionConfig struct {
	EnablePrioritySystem  bool   `json:"enable_priority_system"`
	StrictModeEnabled     bool   `json:"strict_mode_enabled"`
	AllowOverlappingRules bool   `json:"allow_overlapping_rules"`
	ConflictLogLevel      string `json:"conflict_log_level"`
}

type FunctionRulesConfig

type FunctionRulesConfig struct {
	RemoveDuplicateDefinitions bool `json:"remove_duplicate_definitions"`
	PreserveSignatureChanges   bool `json:"preserve_signature_changes"`
}

type GenericJSONError

type GenericJSONError struct {
	Path    string
	Message string
}

GenericJSONError represents other JSON parsing errors

func (*GenericJSONError) Error

func (e *GenericJSONError) Error() string

type IndexRulesConfig

type IndexRulesConfig struct {
	ConsolidateRecreations    bool `json:"consolidate_recreations"`
	PreserveUniqueConstraints bool `json:"preserve_unique_constraints"`
}

type JSONSyntaxError

type JSONSyntaxError struct {
	Path    string
	Line    int
	Column  int
	Context string
	Message string
}

JSONSyntaxError represents a JSON syntax error with helpful context

func (*JSONSyntaxError) Error

func (e *JSONSyntaxError) Error() string

type JSONTypeError

type JSONTypeError struct {
	Path     string
	Line     int
	Column   int
	Context  string
	Field    string
	Expected string
	Got      string
}

JSONTypeError represents a JSON type mismatch error

func (*JSONTypeError) Error

func (e *JSONTypeError) Error() string

type ModernFeaturesConfig

type ModernFeaturesConfig struct {
	EnableVectorSupport    bool `json:"enable_vector_support"`
	EnableGeneratedColumns bool `json:"enable_generated_columns"`
	EnableEventSourcing    bool `json:"enable_event_sourcing"`
	EnableMergeStatements  bool `json:"enable_merge_statements"`
	EnableMultirangeTypes  bool `json:"enable_multirange_types"`
	EnableAdvancedRLS      bool `json:"enable_advanced_rls"`
}

type NextAuthConfig

type NextAuthConfig struct {
	Enabled         bool     `json:"enabled"`
	SessionStrategy string   `json:"session_strategy"`
	DatabaseTables  []string `json:"database_tables"`
}

type NotificationsConfig

type NotificationsConfig struct {
	NotifyUsers  []string `yaml:"notify_users" json:"notify_users"`   // GitHub users to notify (@username)
	SlackChannel string   `yaml:"slack_channel" json:"slack_channel"` // Slack channel to post to (#channel)
}

NotificationsConfig configures notifications for analysis results

type OutputConfig

type OutputConfig struct {
	Format                   string `json:"format"`
	PreserveComments         bool   `json:"preserve_comments"`
	AddConsolidationComments bool   `json:"add_consolidation_comments"`
	FileNaming               string `json:"file_naming"`
	Directory                string `json:"directory"`
}

type PRCommentConfig

type PRCommentConfig struct {
	Enabled                bool `yaml:"enabled" json:"enabled"`                                 // Post comments on PRs
	UpdateExisting         bool `yaml:"update_existing" json:"update_existing"`                 // Update existing comment vs create new
	IncludeStats           bool `yaml:"include_stats" json:"include_stats"`                     // Include file reduction stats
	IncludeWarnings        bool `yaml:"include_warnings" json:"include_warnings"`               // Include warnings section
	IncludeRecommendations bool `yaml:"include_recommendations" json:"include_recommendations"` // Include actionable recommendations
}

PRCommentConfig configures how PR comments are formatted and posted

type PerformanceConfig

type PerformanceConfig struct {
	StreamingThresholdMB int  `json:"streaming_threshold_mb"`
	ParallelProcessing   bool `json:"parallel_processing"`
	ShowProgress         bool `json:"show_progress"`
}

type PlanetScaleConfig

type PlanetScaleConfig struct {
	Enabled                bool `json:"enabled"`
	DisableForeignKeys     bool `json:"disable_foreign_keys"`
	OptimizeForReplication bool `json:"optimize_for_replication"`
}

type PluginSettings

type PluginSettings struct {
	AutoDetect      bool     `json:"auto_detect"`      // Automatically detect and enable plugins (default: true)
	EnabledPlugins  []string `json:"enabled_plugins"`  // Explicitly enabled plugins (empty = auto-detect all)
	DisabledPlugins []string `json:"disabled_plugins"` // Explicitly disabled plugins
	Verbose         bool     `json:"verbose"`          // Log plugin activity (default: false)
}

PluginSettings configures the plugin system behavior

type PostgreSQLFeaturesConfig

type PostgreSQLFeaturesConfig struct {
	TargetVersion          string   `json:"target_version"`
	EnabledExtensions      []string `json:"enabled_extensions"`
	OptimizeForPerformance bool     `json:"optimize_for_performance"`
	UseModernSyntax        bool     `json:"use_modern_syntax"`
	ValidateCompatibility  bool     `json:"validate_compatibility"`
	UseASTAnalyzer         bool     `json:"use_ast_analyzer"` // Use AST-based analyzer instead of regex (default: true)
}

type ProjectConfig

type ProjectConfig struct {
	Name        string   `yaml:"name" json:"name"`                 // Project name
	Include     []string `yaml:"include" json:"include"`           // File patterns for this project
	SafetyLevel string   `yaml:"safety_level" json:"safety_level"` // Safety level for this project
}

ProjectConfig configures a project in a monorepo

type RequiredIndex

type RequiredIndex struct {
	Table  string `yaml:"table" json:"table"`
	Column string `yaml:"column" json:"column"`
}

RequiredIndex specifies an index that must exist

type RulesConfig

type RulesConfig struct {
	TableOperations    TableRulesConfig    `json:"table_operations"`
	IndexOperations    IndexRulesConfig    `json:"index_operations"`
	FunctionOperations FunctionRulesConfig `json:"function_operations"`

	// Overrides force-enables (true) or force-disables (false) specific named
	// consolidation rules relative to the safety-level baseline. Keys are rule
	// names as registered in the consolidation rule registry (e.g.
	// "create_alter_consolidation"). Unknown rule names are rejected when the
	// engine is constructed. A nil/empty map applies the baseline unchanged.
	Overrides map[string]bool `json:"overrides,omitempty"`
}

type StaticValidatorConfig

type StaticValidatorConfig struct {
	// EnabledRules is a list of rule codes to enable.
	// If empty or nil, all registered rules are enabled.
	EnabledRules []string `json:"enabled_rules" yaml:"enabled_rules" toml:"enabled_rules"`

	// RuleOptions allows passing custom configuration to specific rules.
	// Key is the rule code.
	RuleOptions map[string]map[string]any `json:"rule_options" yaml:"rule_options" toml:"rule_options"`

	// TreatWarningsAsErrors causes all violations to be reported as errors
	TreatWarningsAsErrors bool `json:"treat_warnings_as_errors" yaml:"treat_warnings_as_errors" toml:"treat_warnings_as_errors"`
}

StaticValidatorConfig configures the static validator

func DefaultStaticValidatorConfig

func DefaultStaticValidatorConfig() *StaticValidatorConfig

DefaultStaticValidatorConfig returns a default configuration

type SupabaseConfig

type SupabaseConfig struct {
	Enabled            bool   `json:"enabled"`
	JWTSecret          string `json:"jwt_secret"`
	EnableRLS          bool   `json:"enable_rls"`
	StorageIntegration bool   `json:"storage_integration"`
}

type TableRulesConfig

type TableRulesConfig struct {
	ConsolidateCreateAlter bool `json:"consolidate_create_alter"`
	RemoveDropCreateCycles bool `json:"remove_drop_create_cycles"`
	PreserveDataOperations bool `json:"preserve_data_operations"`
}

type ThirdPartyConfig

type ThirdPartyConfig struct {
	Auth0Integration       Auth0Config       `json:"auth0_integration"`
	NextAuthIntegration    NextAuthConfig    `json:"nextauth_integration"`
	SupabaseIntegration    SupabaseConfig    `json:"supabase_integration"`
	ClerkIntegration       ClerkConfig       `json:"clerk_integration"`
	VectorIntegration      VectorConfig      `json:"vector_integration"`
	PlanetScaleIntegration PlanetScaleConfig `json:"planetscale_integration"`
}

type ValidationConfig

type ValidationConfig struct {
	Mode                     string `json:"mode"`                       // Validation approach: TWO_CONTAINERS, TWO_DATABASES, or SCHEMA_DIFF
	DockerImage              string `json:"docker_image"`               // PostgreSQL Docker image (default: postgres:17)
	TimeoutSeconds           int    `json:"timeout_seconds"`            // Validation timeout in seconds (default: 120)
	ContainerReadyTimeout    int    `json:"container_ready_timeout"`    // Container startup timeout in seconds (default: 150, recommended for complex migrations with many extensions)
	EnableExtensionDetection bool   `json:"enable_extension_detection"` // Auto-detect and install extensions (default: true)
	AutoInstallExtensions    bool   `json:"auto_install_extensions"`    // Automatically install detected extensions (default: true)
	EnableSQLFixes           bool   `json:"enable_sql_fixes"`           // Apply automatic SQL fixes during validation (default: false)
	EnablePreprocessing      bool   `json:"enable_preprocessing"`       // Preprocess SQL to fix common issues (e.g., deduplicate publication statements) (default: true)
	Verbose                  bool   `json:"verbose"`                    // Show detailed validation output (default: true)
}

ValidationConfig configures Docker-based validation behavior

type ValidationErrors

type ValidationErrors struct {
	Errors []string
}

ValidationErrors contains multiple validation errors

func (*ValidationErrors) Error

func (e *ValidationErrors) Error() string

type VectorConfig

type VectorConfig struct {
	Enabled          bool     `json:"enabled"`
	DefaultIndexType string   `json:"default_index_type"`
	OptimizeQueries  bool     `json:"optimize_queries"`
	SupportedOps     []string `json:"supported_ops"`
}

Jump to

Keyboard shortcuts

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