Skip to content

Commit

Permalink
Fix database update errors and remove db engine/version (#314)
Browse files Browse the repository at this point in the history
* Fix database update errors and remove db engine/version

* Removed leftover debug variable print

* Deleted extra space
  • Loading branch information
christhemorse authored Apr 27, 2023
1 parent bd772db commit 72dab3d
Showing 1 changed file with 19 additions and 25 deletions.
44 changes: 19 additions & 25 deletions cmd/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@ func Database() *cobra.Command {
databaseCreate.Flags().StringP("redis-eviction-policy", "", "", "eviction policy for the new redis managed database")

// Database update flags
databaseUpdate.Flags().StringP("database-engine", "e", "", "database engine for the manaaged database")
databaseUpdate.Flags().StringP("database-engine-version", "v", "", "database engine version for the manaaged database")
databaseUpdate.Flags().StringP("region", "r", "", "region id for the managed database")
databaseUpdate.Flags().StringP("plan", "p", "", "plan id for the managed database")
databaseUpdate.Flags().StringP("label", "l", "", "label for the managed database")
Expand Down Expand Up @@ -363,8 +361,6 @@ var databaseUpdate = &cobra.Command{
return nil
},
Run: func(cmd *cobra.Command, args []string) {
databaseEngine, _ := cmd.Flags().GetString("database-engine")
databaseEngineVersion, _ := cmd.Flags().GetString("database-engine-version")
region, _ := cmd.Flags().GetString("region")
plan, _ := cmd.Flags().GetString("plan")
label, _ := cmd.Flags().GetString("label")
Expand All @@ -375,37 +371,35 @@ var databaseUpdate = &cobra.Command{
trustedIPs, _ := cmd.Flags().GetStringSlice("trusted-ips")
mysqlSQLModes, _ := cmd.Flags().GetStringSlice("mysql-sql-modes")
mysqlRequirePrimaryKey, _ := cmd.Flags().GetBool("mysql-require-primary-key")
mysqlRequirePrimaryKeySet := cmd.Flags().Lookup("mysql-require-primary-key").Changed
mySQLSlowQueryLog, _ := cmd.Flags().GetBool("mysql-slow-query-log")
mySQLSlowQueryLogSet := cmd.Flags().Lookup("mysql-slow-query-log").Changed
mySQLLongQueryTime, _ := cmd.Flags().GetInt("mysql-long-query-time")
redisEvictionPolicy, _ := cmd.Flags().GetString("redis-eviction-policy")

opt := &govultr.DatabaseUpdateReq{
DatabaseEngine: databaseEngine,
DatabaseEngineVersion: databaseEngineVersion,
Plan: plan,
Region: region,
Label: label,
Tag: tag,
MaintenanceDOW: maintenanceDOW,
MaintenanceTime: maintenanceTime,
ClusterTimeZone: clusterTimeZone,
TrustedIPs: trustedIPs,
MySQLSQLModes: mysqlSQLModes,
MySQLRequirePrimaryKey: nil,
MySQLSlowQueryLog: nil,
MySQLLongQueryTime: mySQLLongQueryTime,
RedisEvictionPolicy: redisEvictionPolicy,
}

if mysqlRequirePrimaryKey {
Plan: plan,
Region: region,
Label: label,
Tag: tag,
MaintenanceDOW: maintenanceDOW,
MaintenanceTime: maintenanceTime,
ClusterTimeZone: clusterTimeZone,
TrustedIPs: trustedIPs,
MySQLSQLModes: mysqlSQLModes,
MySQLLongQueryTime: mySQLLongQueryTime,
RedisEvictionPolicy: redisEvictionPolicy,
}

if mysqlRequirePrimaryKeySet && mysqlRequirePrimaryKey {
opt.MySQLRequirePrimaryKey = govultr.BoolToBoolPtr(true)
} else if !mysqlRequirePrimaryKey {
} else if mysqlRequirePrimaryKeySet && !mysqlRequirePrimaryKey {
opt.MySQLRequirePrimaryKey = govultr.BoolToBoolPtr(false)
}

if mySQLSlowQueryLog {
if mySQLSlowQueryLogSet && mySQLSlowQueryLog {
opt.MySQLSlowQueryLog = govultr.BoolToBoolPtr(true)
} else if !mySQLSlowQueryLog {
} else if mySQLSlowQueryLogSet && !mySQLSlowQueryLog {
opt.MySQLSlowQueryLog = govultr.BoolToBoolPtr(false)
}

Expand Down

0 comments on commit 72dab3d

Please sign in to comment.