Skip to content
This repository has been archived by the owner on Jan 24, 2023. It is now read-only.

Update tokens table to fix issue affecting upgrades #2544

Merged
merged 6 commits into from
Jun 27, 2018
Merged
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
2 changes: 1 addition & 1 deletion deploy/proxy.env
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ ALLOWED_ORIGINS=http://nginx
SESSION_STORE_SECRET=wheeee!
CONSOLE_PROXY_CERT_KEY=use local dev-cert/pproxy.key in portal-proxy repo
CONSOLE_PROXY_CERT=use local dev-cert/pproxy.crt in portal-proxy repo
ENCRYPTION_KEY=B374A26A71490437AA024E4FADD5B497FDFF1A8EA6FF12F6FB65AF2720B59CCF
ENCRYPTION_KEY=B374A26A71490437AA024E4FADD5B497FDFF1A8EA6FF12F6FB65AF2720B59CCF
36 changes: 36 additions & 0 deletions src/backend/app-core/datastore/20180627111300_UpdateMetadata.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package datastore

import (
"database/sql"
"fmt"

"bitbucket.org/liamstask/goose/lib/goose"
)

func (s *StratosMigrations) Up_20180627111300(txn *sql.Tx, conf *goose.DBConf) {

updateMetadata := "ALTER TABLE tokens modify meta_data TEXT DEFAULT ''"
_, err := txn.Exec(updateMetadata)
if err != nil {
fmt.Printf("Failed to migrate due to: %v", err)
}
updateMetadata = "UPDATE tokens SET meta_data='' where meta_data is NULL"
_, err = txn.Exec(updateMetadata)
if err != nil {
fmt.Printf("Failed to migrate due to: %v", err)
}

}

func Down_20180627111300(txn *sql.Tx) {
dropTables := "ALTER TABLE tokens modify meta_data TEXT DEFAULT ''"
_, err := txn.Exec(dropTables)
if err != nil {
fmt.Printf("Failed to migrate due to: %v", err)
}
dropTables = "UPDATE tokens SET meta_data=NULL where meta_data is ''"
_, err = txn.Exec(dropTables)
if err != nil {
fmt.Printf("Failed to migrate due to: %v", err)
}
}
6 changes: 3 additions & 3 deletions src/backend/app-core/repository/tokens/pgsql_tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (p *PgsqlTokenRepository) SaveAuthToken(userGUID string, tr interfaces.Toke
var count int
err = p.db.QueryRow(countAuthTokens, userGUID).Scan(&count)
if err != nil {
log.Debugf("Unknown error attempting to find UAA token: %v", err)
log.Errorf("Unknown error attempting to find UAA token: %v", err)
}

switch count {
Expand Down Expand Up @@ -226,7 +226,7 @@ func (p *PgsqlTokenRepository) SaveCNSIToken(cnsiGUID string, userGUID string, t
var count int
err = p.db.QueryRow(countCNSITokens, cnsiGUID, userGUID).Scan(&count)
if err != nil {
log.Debugf("Unknown error attempting to find CNSI token: %v", err)
log.Errorf("Unknown error attempting to find CNSI token: %v", err)
}

switch count {
Expand Down Expand Up @@ -316,7 +316,7 @@ func (p *PgsqlTokenRepository) findCNSIToken(cnsiGUID string, userGUID string, e

if err != nil {
msg := "Unable to Find CNSI token: %v"
log.Debugf(msg, err)
log.Errorf(msg, err)
return interfaces.TokenRecord{}, fmt.Errorf(msg, err)
}

Expand Down