Skip to content

Commit 0d20269

Browse files
committed
create option to explicitly unlock users
1 parent 8759c85 commit 0d20269

2 files changed

Lines changed: 20 additions & 5 deletions

File tree

database_admin/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ var (
1313
resetSchema = utils.PodConfig.GetBool("reset_schema", false)
1414
// Create users and update their password
1515
updateUsers = utils.PodConfig.GetBool("update_users", false)
16+
// Unlock users
17+
unlockUsers = utils.PodConfig.GetBool("unlock_users", false)
1618
// rerun config.sql
1719
updateDBConfig = utils.PodConfig.GetBool("update_db_config", false)
1820
)

database_admin/update.go

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,27 @@ func setPgEnv() {
6565
os.Setenv("PGSSLROOTCERT", utils.CoreCfg.DBSslRootCert)
6666
}
6767

68-
func startMigration(conn database.Driver, db *sql.DB, migrationFilesURL string) {
69-
log.Info("Blocking writing users during the migration")
68+
func lockUsers(db *sql.DB) {
7069
execOrPanic(db, "ALTER USER listener NOLOGIN")
7170
execOrPanic(db, "ALTER USER evaluator NOLOGIN")
7271
execOrPanic(db, "ALTER USER vmaas_sync NOLOGIN")
72+
}
73+
74+
func unlockUsers(db *sql.DB) {
75+
execOrPanic(db, "ALTER USER listener LOGIN")
76+
execOrPanic(db, "ALTER USER evaluator LOGIN")
77+
execOrPanic(db, "ALTER USER vmaas_sync LOGIN")
78+
}
79+
80+
func startMigration(conn database.Driver, db *sql.DB, migrationFilesURL string) {
81+
log.Info("Blocking writing users during the migration")
82+
lockUsers(db)
7383
waitForSessionClosed(db)
7484

7585
MigrateUp(conn, migrationFilesURL)
7686

7787
log.Info("Reverting components privileges")
78-
execOrPanic(db, "ALTER USER listener LOGIN")
79-
execOrPanic(db, "ALTER USER evaluator LOGIN")
80-
execOrPanic(db, "ALTER USER vmaas_sync LOGIN")
88+
unlockUsers(db)
8189
}
8290

8391
func dbConn() (database.Driver, *sql.DB) {
@@ -114,6 +122,11 @@ func UpdateDB(migrationFilesURL string) {
114122
execFromFile(db, "./database_admin/schema/create_users.sql")
115123
}
116124

125+
if unlockUsers {
126+
log.Info("Unlocking application components users")
127+
unlockUsers(db)
128+
}
129+
117130
switch action := migrateAction(conn, migrationFilesURL); action {
118131
case BLOCK:
119132
// sleep until next deployment

0 commit comments

Comments
 (0)