@@ -34,6 +34,11 @@ type DatabaseUpdateStatus =
3434 | DatabaseUpdateStatusUpToDate
3535 | DatabaseUpdateStatusNoDatabase ;
3636
37+ /**
38+ * Check whether a newer database is available for the given repository. Databases are considered updated if:
39+ * - They have a different commit OID, or
40+ * - They have the same commit OID, but the remote database was created after the local database.
41+ */
3742export function isNewerDatabaseAvailable (
3843 databases : CodeqlDatabase [ ] ,
3944 owner : string ,
@@ -78,12 +83,16 @@ export function isNewerDatabaseAvailable(
7883 return null ;
7984 }
8085
81- // We only consider databases to be updated if they have a different `commit_oid` than the
82- // one we have stored. If they have the same `commit_oid`, then they are the same database.
83- // This means that older databases which do not have a `commit_oid` (`null`) are always
84- // considered up-to-date.
86+ // If they are not equal, we assume that the remote database is newer.
8587 if ( matchingDatabase . commit_oid === origin . commitOid ) {
86- return null ;
88+ const remoteDatabaseCreatedAt = new Date ( matchingDatabase . created_at ) ;
89+ const localDatabaseCreatedAt = new Date ( origin . databaseCreatedAt ) ;
90+
91+ // If the remote database was created before the local database,
92+ // we assume that the local database is newer.
93+ if ( remoteDatabaseCreatedAt <= localDatabaseCreatedAt ) {
94+ return null ;
95+ }
8796 }
8897
8998 return {
0 commit comments