Răsfoiți Sursa

Correctly sort table list for stable schema signatures.

Kestrel 7 luni în urmă
părinte
comite
46f7bb3fc9
1 a modificat fișierele cu 10 adăugiri și 2 ștergeri
  1. 10 2
      microrm/src/schema/build.rs

+ 10 - 2
microrm/src/schema/build.rs

@@ -282,7 +282,11 @@ pub(crate) fn collect_from_database<DB: Database>() -> DatabaseSchema {
 
     let mut queries = vec![];
 
-    for (table_name, table) in tables {
+    // create sorted table list
+    let mut sorted_tables : Vec<_> = tables.into_iter().collect();
+    sorted_tables.sort_by(|a, b| a.0.cmp(&b.0));
+
+    for (table_name, table) in sorted_tables {
         let create_sql = table.build_creation_query();
 
         table_name.hash(&mut signature_hasher);
@@ -295,8 +299,12 @@ pub(crate) fn collect_from_database<DB: Database>() -> DatabaseSchema {
         queries.push(iinfo.build_creation_query());
     }
 
+    let signature = signature_hasher.finish();
+
+    log::trace!("Schema signature: {signature:x}");
+
     DatabaseSchema {
-        signature: signature_hasher.finish(),
+        signature,
         queries,
     }
 }