Skip to content

Commit

Permalink
chore: remove requirement of using flipt_analytics for the user to us…
Browse files Browse the repository at this point in the history
…e any database they want
  • Loading branch information
yquansah committed Feb 6, 2024
1 parent 73ce438 commit fac4df5
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 32 deletions.
8 changes: 4 additions & 4 deletions cmd/flipt/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
)

const (
regular = "regular"
analytics = "analytics"
defaultConfig = "default"
analytics = "analytics"
)

var database string
Expand Down Expand Up @@ -59,7 +59,7 @@ func newMigrateCommand() *cobra.Command {

// Run the OLTP and OLAP database migrations sequentially because of
// potential danger in DB migrations in general.
if err := runMigrations(cfg, logger, regular); err != nil {
if err := runMigrations(cfg, logger, defaultConfig); err != nil {
return err
}

Expand All @@ -74,6 +74,6 @@ func newMigrateCommand() *cobra.Command {
}

cmd.Flags().StringVar(&providedConfigFile, "config", "", "path to config file")
cmd.Flags().StringVar(&database, "database", "regular", "string to denote which database type to migrate")
cmd.Flags().StringVar(&database, "database", "default", "string to denote which database type to migrate")
return cmd
}
6 changes: 0 additions & 6 deletions internal/config/analytics.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import (
"github.com/spf13/viper"
)

var ErrWrongDatabase error = errors.New("database should be flipt_analytics")

// AnalyticsConfig defines the configuration for various mechanisms for
// reporting and querying analytical data for Flipt.
type AnalyticsConfig struct {
Expand Down Expand Up @@ -38,17 +36,13 @@ func (c *ClickhouseConfig) Options() (*clickhouse.Options, error) {
if err != nil {
return nil, err
}
if options.Auth.Database != "flipt_analytics" {
return nil, ErrWrongDatabase
}

return options, nil
}

//nolint:unparam
func (a *AnalyticsConfig) setDefaults(v *viper.Viper) error {
v.SetDefault("analytics", map[string]any{
"enabled": "false",
"clickhouse": map[string]any{
"enabled": "false",
"url": "",
Expand Down
21 changes: 0 additions & 21 deletions internal/config/analytics_test.go

This file was deleted.

7 changes: 6 additions & 1 deletion internal/storage/sql/migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,13 @@ func NewAnalyticsMigrator(cfg config.Config, logger *zap.Logger) (*Migrator, err
var dr database.Driver

if driver == Clickhouse {
options, err := cfg.Analytics.Storage.Clickhouse.Options()
if err != nil {
return nil, err
}

dr, err = clickhouseMigrate.WithInstance(sql, &clickhouseMigrate.Config{
DatabaseName: "flipt_analytics",
DatabaseName: options.Auth.Database,
MigrationsTableEngine: "MergeTree",
})
if err != nil {
Expand Down

0 comments on commit fac4df5

Please sign in to comment.