Skip to content

Commit

Permalink
Update last_modified timestamp after Execute()
Browse files Browse the repository at this point in the history
Fixes #230
  • Loading branch information
justinclift committed Dec 12, 2023
1 parent dce1cf1 commit 54d8bb5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
5 changes: 5 additions & 0 deletions common/live.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,11 @@ func LiveExecute(liveNode, loggedInUser, dbOwner, dbName, sql string) (rowsChang
}
}
}

// If no error was thrown, then update the "last_modified" field for the database
if err == nil {
err = UpdateModified(dbOwner, dbName)
}
return
}

Expand Down
24 changes: 24 additions & 0 deletions common/postgresql.go
Original file line number Diff line number Diff line change
Expand Up @@ -4893,6 +4893,30 @@ func UpdateMergeRequestCommits(dbOwner, dbName string, discID int, mrCommits []C
return nil
}

// UpdateModified is a simple function to change the 'last modified' timestamp for a database to now()
func UpdateModified(dbOwner, dbName string) (err error) {
dbQuery := `
UPDATE sqlite_databases AS db
SET last_modified = now()
WHERE user_id = (
SELECT user_id
FROM users
WHERE lower(user_name) = lower($1)
)
AND db_name = $2`
commandTag, err := pdb.Exec(context.Background(), dbQuery, dbOwner, dbName)
if err != nil {
log.Printf("%s: updating last_modified for database '%s/%s' failed: %v", Conf.Live.Nodename, dbOwner,
dbName, err)
return
}
if numRows := commandTag.RowsAffected(); numRows != 1 {
log.Printf("%s: wrong number of rows (%d) affected when updating last_modified for database '%s/%s'",
Conf.Live.Nodename, numRows, dbOwner, dbName)
}
return
}

// User returns details for a user
func User(userName string) (user UserDetails, err error) {
dbQuery := `
Expand Down

0 comments on commit 54d8bb5

Please sign in to comment.