Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hack for updating the migration_info.version value in the database #392

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions ccx_notification_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ package main
// https://redhatinsights.github.io/ccx-notification-writer/packages/ccx_notification_writer.html

import (
"database/sql"
"flag"
"fmt"
"net/http"
Expand Down Expand Up @@ -484,6 +485,8 @@ func doSelectedOperation(configuration *ConfigStruct, cliFlags CliFlags) (int, e
return PrintMigrationInfo(configuration)
case cliFlags.PerformMigrations != "":
return PerformMigrations(configuration, cliFlags.PerformMigrations)
case cliFlags.UpdateMigrationInfo != "":
return UpdateMigrationInfo(configuration, cliFlags.UpdateMigrationInfo)
default:
exitCode, err := startService(configuration)
return exitCode, err
Expand Down Expand Up @@ -533,6 +536,7 @@ func main() {
flag.BoolVar(&cliFlags.MigrationInfo, "migration-info", false, "prints migration info")
flag.StringVar(&cliFlags.MaxAge, "max-age", "", "max age for displaying/cleaning old records")
flag.StringVar(&cliFlags.PerformMigrations, "migrate", "", "set database version")
flag.StringVar(&cliFlags.UpdateMigrationInfo, "migration-info-update", "", "set migration info data")
flag.Parse()

// service configuration has exactly the same structure as *.toml file
Expand Down Expand Up @@ -634,3 +638,38 @@ func PerformMigrations(configuration *ConfigStruct, migParam string) (exitStatus
exitStatus = ExitStatusOK
return
}

// UpdateMigrationInfo migrates the database to the version
// specified in params
func UpdateMigrationInfo(configuration *ConfigStruct, migParam string) (exitStatus int, err error) {
utils.Set(All())
// get db handle
storageConfiguration := GetStorageConfiguration(configuration)
storage, err := NewStorage(&storageConfiguration)
if err != nil {
log.Error().Err(err).Msg(StorageHandleErr)
exitStatus = ExitStatusMigrationError
return
}

tx, err := storage.connection.Begin()
if err != nil {
return -1, err
}

updateMigrationInfo := fmt.Sprintf(`
UPDATE migration_info SET version=%s
`, migParam)

err = func(tx *sql.Tx) error {
_, err := tx.Exec(updateMigrationInfo)
if err != nil {
return err
}

return nil
}(tx)

finishTransaction(tx, err)
return 0, err
}
1 change: 1 addition & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type CliFlags struct {
MigrationInfo bool
MaxAge string
PerformMigrations string
UpdateMigrationInfo string
}

// RequestID data type is used to store the request ID supplied in input Kafka
Expand Down