Skip to content

Commit

Permalink
Issue open-horizon#4111 - Bug: secret_exists column not added to secr…
Browse files Browse the repository at this point in the history
…ets_policy if table already exists

Signed-off-by: Max McAdam <max@fredcom.com>
  • Loading branch information
MaxMcAdam committed Jul 24, 2024
1 parent 5ed9120 commit fdd62db
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 3 additions & 1 deletion agreementbot/persistence/postgresql/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,10 @@ func (db *AgbotPostgresqlDB) Initialize(cfg *config.HorizonConfig) error {

// Run each SQL statement in the array of SQL statements for the current version.
for si := 0; si < len(migrationSQL[v].sql); si++ {
if _, err := db.db.Exec(migrationSQL[v].sql[si]); err != nil {
if _, err := db.db.Exec(migrationSQL[v].sql[si]); err != nil && migrationSQL[v].exitOnFailure {
return errors.New(fmt.Sprintf("unable to run SQL migration statement version %v, index %v, statement %v, error: %v", v, si, migrationSQL[v].sql[si], err))
} else if err != nil {
fmt.Printf("unable to run SQL migration statement version %v, index %v, statement %v, error: %v", v, si, migrationSQL[v].sql[si], err)
} else if _, err := db.db.Exec(VERSION_UPDATE, HIGHEST_DATABASE_VERSION, migrationSQL[v].description); err != nil {
return errors.New(fmt.Sprintf("unable to create version table, error: %v", err))
} else {
Expand Down
8 changes: 6 additions & 2 deletions agreementbot/persistence/postgresql/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,16 @@ END $$`

const VERSION_UPDATE = `UPDATE version SET ver = $1, description = $2, updated = current_timestamp WHERE id = 1;`

const HIGHEST_DATABASE_VERSION = v1
const HIGHEST_DATABASE_VERSION = v2
const v2 = 1
const v1 = 0

type SchemaUpdate struct {
sql []string // The SQL statements to run for an update to the schema.
description string // A description of the schema change.
exitOnFailure bool // true to quit if the update fails
}

var migrationSQL = map[int]SchemaUpdate{}
var v2SchemaUpdate = SchemaUpdate{sql: []string{"ALTER TABLE secrets_policy ADD COLUMN \"secret_exists\" BOOLEAN NOT NULL DEFAULT true;", "ALTER TABLE secrets_pattern ADD COLUMN \"secret_exists\" BOOLEAN NOT NULL DEFAULT true;"}, description: "Add a column to the secrets table to indicate if the secret exists or not. This is necessary to support node-specific secrets.", exitOnFailure: false}

var migrationSQL = map[int]SchemaUpdate{v2: v2SchemaUpdate}

0 comments on commit fdd62db

Please sign in to comment.