@@ -781,6 +781,8 @@ pub struct GetSchemaV1Response {
781781 pub default_variant_id : SchemaVariantId ,
782782 #[ schema( value_type = Vec <String >, example = json!( [ "01H9ZQD35JPMBGHH69BT0Q79VZ" , "01H9ZQD35JPMBGHH69BT0Q79VY" ] ) ) ]
783783 pub variant_ids : Vec < SchemaVariantId > ,
784+ #[ schema( value_type = Option <bool >, example = true ) ]
785+ pub upgrade_available : Option < bool > ,
784786}
785787
786788/// The response payload when materialized views or data is being built referenced by present or
@@ -921,6 +923,41 @@ pub struct SchemaResponse {
921923 pub schema_id : SchemaId ,
922924 #[ schema( value_type = bool , example = "false" ) ]
923925 pub installed : bool ,
926+ #[ schema( value_type = Option <bool >, example = true ) ]
927+ pub upgrade_available : Option < bool > ,
928+ }
929+
930+ /// Checks if an upgrade is available for an installed schema by comparing
931+ /// the installed module hash with the latest cached module hash.
932+ ///
933+ /// Returns:
934+ /// - `None` if the schema is not installed (no comparison possible)
935+ /// - `Some(true)` if an upgrade is available (hashes differ)
936+ /// - `Some(false)` if no upgrade is available (hashes match or no cached module found)
937+ pub async fn check_schema_upgrade_available (
938+ ctx : & DalContext ,
939+ schema_id : SchemaId ,
940+ ) -> SchemaResult < Option < bool > > {
941+ // Get the latest cached module to find what the latest available version is
942+ let Some ( cached_module) = CachedModule :: find_latest_for_schema_id ( ctx, schema_id) . await ? else {
943+ // No cached module found, so we can't determine if an upgrade is available
944+ return Ok ( Some ( false ) ) ;
945+ } ;
946+
947+ // Try to find the installed module using the schema_id as the module_schema_id
948+ // Convert SchemaId to Ulid
949+ let module_schema_id: si_events:: ulid:: Ulid = schema_id. into ( ) ;
950+ let installed_module = dal:: module:: Module :: find_for_module_schema_id ( ctx, module_schema_id) . await ?;
951+
952+ let Some ( installed_module) = installed_module else {
953+ // Schema is not installed, return None to indicate no comparison is possible
954+ return Ok ( None ) ;
955+ } ;
956+
957+ // Compare the installed module's root_hash with the cached module's latest_hash
958+ let upgrade_available = installed_module. root_hash ( ) != cached_module. latest_hash ;
959+
960+ Ok ( Some ( upgrade_available) )
924961}
925962
926963pub async fn get_full_schema_list ( ctx : & DalContext ) -> SchemaResult < Vec < SchemaResponse > > {
@@ -941,21 +978,25 @@ pub async fn get_full_schema_list(ctx: &DalContext) -> SchemaResult<Vec<SchemaRe
941978 for schema_id in & schema_ids {
942979 if let Some ( module) = cached_module_map. get ( schema_id) {
943980 // Schema is both installed and in cache
981+ let upgrade_available = check_schema_upgrade_available ( ctx, * schema_id) . await ?;
944982 all_schemas. push ( SchemaResponse {
945983 schema_name : module. schema_name . clone ( ) ,
946984 schema_id : * schema_id,
947985 category : module. category . clone ( ) ,
948986 installed : true ,
987+ upgrade_available,
949988 } ) ;
950989 } else {
951990 // Schema is installed but not in cache - this is a local only schema
952991 if let Ok ( schema) = dal:: Schema :: get_by_id ( ctx, * schema_id) . await {
953992 let default_variant = SchemaVariant :: default_for_schema ( ctx, * schema_id) . await ?;
993+ let upgrade_available = check_schema_upgrade_available ( ctx, * schema_id) . await ?;
954994 all_schemas. push ( SchemaResponse {
955995 schema_name : schema. name ,
956996 schema_id : * schema_id,
957997 category : Some ( default_variant. category ( ) . to_owned ( ) ) ,
958998 installed : true ,
999+ upgrade_available,
9591000 } ) ;
9601001 }
9611002 }
@@ -971,6 +1012,7 @@ pub async fn get_full_schema_list(ctx: &DalContext) -> SchemaResult<Vec<SchemaRe
9711012 schema_id,
9721013 category : module. category ,
9731014 installed : is_installed,
1015+ upgrade_available : None , // Not installed, so no upgrade check possible
9741016 } ) ;
9751017 }
9761018
0 commit comments