File tree Expand file tree Collapse file tree 1 file changed +9
-10
lines changed Expand file tree Collapse file tree 1 file changed +9
-10
lines changed Original file line number Diff line number Diff line change @@ -61,8 +61,8 @@ async function checkCountAfterImport(): Promise<boolean> {
61
61
return allValid ;
62
62
} catch ( error ) {
63
63
console . error ( `ERROR: ${ error } ` ) ;
64
- return false ;
65
64
}
65
+ return false ;
66
66
}
67
67
68
68
/**
@@ -81,17 +81,15 @@ async function updateDatabase(): Promise<boolean> {
81
81
82
82
const userId = user [ 0 ] ?. id ;
83
83
84
- await db
84
+ // Update the user and return the updated row
85
+ const [ updatedUser ] = await db
85
86
. update ( schema . usersTable )
86
87
. set ( { name : updatedName } )
87
- . where ( sql `id = ${ userId } ` ) ;
88
-
89
- const updatedUser = await db
90
- . select ( )
91
- . from ( schema . usersTable )
92
- . where ( sql `id = ${ userId } ` ) ;
88
+ . where ( sql `id = ${ userId } ` )
89
+ . returning ( { name : schema . usersTable . name } ) ;
93
90
94
- if ( updatedUser [ 0 ] ?. name !== updatedName ) {
91
+ // Validate update in one step
92
+ if ( ! updatedUser || updatedUser . name !== updatedName ) {
95
93
console . error ( "ERROR: Database update failed!" ) ;
96
94
return false ;
97
95
}
@@ -119,7 +117,8 @@ async function runValidation(): Promise<void> {
119
117
process . exit ( 1 ) ;
120
118
}
121
119
console . log ( "Database Updation : Success" ) ;
122
- process . exit ( 0 ) ;
120
+ await queryClient . end ( ) ;
121
+ process . exit ( 0 ) ;
123
122
} catch ( error ) {
124
123
if ( error instanceof Error ) {
125
124
console . error ( `\nERROR: ${ error . message } ` ) ;
You can’t perform that action at this time.
0 commit comments