package main

import (
	"context"
	"flag"

	"dataservices/commons/config"
	"dataservices/commons/database"
	"dataservices/test/tablecreator/tables"

	"github.com/pingcap/log"
	"go.uber.org/zap"
)

const (
	defaultConfigPath = "/etc/dbaas/config.yaml"
)

func main() {
	var configPath string
	flag.StringVar(&configPath, "config-path", defaultConfigPath, "DBaaS configuration file path")
	flag.Parse()
	ctx := context.Background()

	// Load config
	err := config.InitConfig(configPath)
	if err != nil {
		// TODO: unexpected error like this, should we throw a alert/page, just log seems not enough ?
		log.Fatal("Initialize configuration failed", zap.Error(err))
	}

	// Connect database
	config := config.Global()
	database.Connect(ctx,
		config.MysqlConf.User,
		config.MysqlConf.Password,
		config.MysqlConf.Host,
		config.MysqlConf.Port,
		config.MysqlConf.Database,
		config.MysqlConf.CharSet,
		config.MysqlConf.TimeZone,
	)
	tables.CreateCentralTables(database.DBConn.DB)
}
