-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: separate migrations from codebase + templatize migrations
- Loading branch information
1 parent
ad8afed
commit e6bd49b
Showing
99 changed files
with
649 additions
and
520 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
"os" | ||
|
||
"github.com/SigNoz/signoz-otel-collector/migrator" | ||
"github.com/spf13/pflag" | ||
"go.uber.org/zap" | ||
"go.uber.org/zap/zapcore" | ||
) | ||
|
||
func init() { | ||
// init zap logger | ||
config := zap.NewProductionConfig() | ||
config.EncoderConfig.EncodeLevel = zapcore.LowercaseLevelEncoder | ||
config.EncoderConfig.TimeKey = "timestamp" | ||
config.EncoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder | ||
logger, err := config.Build() | ||
if err != nil { | ||
log.Fatalf("Failed to initialize zap logger %v", err) | ||
} | ||
// replace global logger | ||
zap.ReplaceGlobals(logger) | ||
} | ||
|
||
func main() { | ||
logger := zap.L().With(zap.String("component", "migrate cli")) | ||
f := pflag.NewFlagSet("Collector Migrator CLI Options", pflag.ExitOnError) | ||
|
||
f.Usage = func() { | ||
fmt.Println(f.FlagUsages()) | ||
os.Exit(0) | ||
} | ||
|
||
f.String("dsn", "", "Clickhouse DSN") | ||
f.String("cluster-name", "", "Cluster name to use while running migrations") | ||
f.Bool("multi-node-cluster", false, "True if the dsn points to a multi node clickhouse cluster, false otherwise. Defaults to false.") | ||
|
||
err := f.Parse(os.Args[1:]) | ||
if err != nil { | ||
logger.Fatal("Failed to parse args", zap.Error(err)) | ||
} | ||
|
||
dsn, err := f.GetString("dsn") | ||
if err != nil { | ||
logger.Fatal("Failed to get dsn from args", zap.Error(err)) | ||
} | ||
|
||
clusterName, err := f.GetString("cluster-name") | ||
if err != nil { | ||
logger.Fatal("Failed to get cluster name from args", zap.Error(err)) | ||
} | ||
|
||
multiNodeCluster, err := f.GetBool("multi-node-cluster") | ||
if err != nil { | ||
logger.Fatal("Failed to get multi node cluster flag from args", zap.Error(err)) | ||
} | ||
|
||
if dsn == "" || clusterName == "" { | ||
logger.Fatal("dsn and clusterName are required fields") | ||
} | ||
|
||
migrationManager, err := migrator.NewMigrationManager(dsn, clusterName, multiNodeCluster) | ||
if err != nil { | ||
logger.Fatal("Failed to create migration manager", zap.Error(err)) | ||
} | ||
err = migrationManager.Migrate(context.Background()) | ||
if err != nil { | ||
logger.Fatal("Failed to run migrations", zap.Error(err)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
exporter/clickhouselogsexporter/migrations/000002_add_minmax_idx.down.sql
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
exporter/clickhouselogsexporter/migrations/000002_add_minmax_idx.up.sql
This file was deleted.
Oops, something went wrong.
3 changes: 0 additions & 3 deletions
3
exporter/clickhouselogsexporter/migrations/000003_add_distributed_table.down.sql
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
exporter/clickhouselogsexporter/migrations/000004_ttl_only_drop_parts.down.sql
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
exporter/clickhouselogsexporter/migrations/000004_ttl_only_drop_parts.up.sql
This file was deleted.
Oops, something went wrong.
2 changes: 0 additions & 2 deletions
2
exporter/clickhouselogsexporter/migrations/000006_tag_attributes.down.sql
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
exporter/clickhouselogsexporter/migrations/000007_default_indexes.down.sql
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.