@@ -325,8 +325,10 @@ impl Table {
325325 format ! ( "{}_{}" , self . name, v. as_suffix( ) )
326326 } ) ;
327327
328- // Only include database prefix if name doesn't already contain a dot (fully qualified name)
329- if self . name . contains ( '.' ) {
328+ // Only include database prefix if:
329+ // 1. Name doesn't already contain a dot (fully qualified name)
330+ // 2. Database is not empty (backward compatibility with legacy deployments that had no db prefix)
331+ if self . name . contains ( '.' ) || db. is_empty ( ) {
330332 base_id
331333 } else {
332334 format ! ( "{}_{}" , db, base_id)
@@ -1803,6 +1805,28 @@ mod tests {
18031805 ..table1. clone ( )
18041806 } ;
18051807 assert_eq ! ( table7. id( DEFAULT_DATABASE_NAME ) , "local_users_1_0" ) ;
1808+
1809+ // Test 8: Empty default_database - backward compatibility for legacy deployments
1810+ // Legacy deployments had table IDs without database prefix (e.g., "AWSUploadEvent_0_0_0_0")
1811+ // When db_name is empty, we should NOT add a prefix
1812+ assert_eq ! (
1813+ table1. id( "" ) ,
1814+ "users" ,
1815+ "Empty database should produce ID without prefix"
1816+ ) ;
1817+
1818+ // Test 9: Empty default_database with version
1819+ let table9 = Table {
1820+ name : "AWSUploadEvent_0_0" . to_string ( ) ,
1821+ version : Some ( Version :: from_string ( "0.0" . to_string ( ) ) ) ,
1822+ database : None ,
1823+ ..table1. clone ( )
1824+ } ;
1825+ assert_eq ! (
1826+ table9. id( "" ) ,
1827+ "AWSUploadEvent_0_0_0_0" ,
1828+ "Empty database with version should produce ID without database prefix"
1829+ ) ;
18061830 }
18071831
18081832 #[ test]
0 commit comments