Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

1.1 KB
Raw Blame
package sqlmigrator

import (
	"time"

	"github.com/SigNoz/signoz/pkg/errors"

	"github.com/SigNoz/signoz/pkg/factory"
)

var (
	ErrCodeInvalidSQLMigratorConfig = errors.MustNewCode("invalid_sqlmigrator_config")
	ErrCodePendingSQLMigrations     = errors.MustNewCode("pending_sql_migrations")
)

type Config struct {
	// Lock is the lock configuration.
	Lock Lock `mapstructure:"lock"`
}

type Lock struct {
	// Timeout is the time to wait for the migration lock.
	Timeout time.Duration `mapstructure:"timeout"`
	// Interval is the interval to try to acquire the migration lock.
	Interval time.Duration `mapstructure:"interval"`
}

func NewConfigFactory() factory.ConfigFactory {
	return factory.NewConfigFactory(factory.MustNewName("sqlmigrator"), newConfig)
}

func newConfig() factory.Config {
	return Config{
		Lock: Lock{
			Timeout:  2 * time.Minute,
			Interval: 10 * time.Second,
		},
	}
}

func (c Config) Validate() error {
	if c.Lock.Timeout <= c.Lock.Interval {
		return errors.New(errors.TypeInvalidInput, ErrCodeInvalidSQLMigratorConfig, "lock::timeout must be greater than lock::interval")
	}

	return nil
}