Skip to content

Commit a0ccd10

Browse files
empty case
1 parent 491bc61 commit a0ccd10

File tree

1 file changed

+26
-2
lines changed
  • apps/framework-cli/src/framework/core/infrastructure

1 file changed

+26
-2
lines changed

apps/framework-cli/src/framework/core/infrastructure/table.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,10 @@ impl Table {
321321
format!("{}_{}", self.name, v.as_suffix())
322322
});
323323

324-
// Only include database prefix if name doesn't already contain a dot (fully qualified name)
325-
if self.name.contains('.') {
324+
// Only include database prefix if:
325+
// 1. Name doesn't already contain a dot (fully qualified name)
326+
// 2. Database is not empty (backward compatibility with legacy deployments that had no db prefix)
327+
if self.name.contains('.') || db.is_empty() {
326328
base_id
327329
} else {
328330
format!("{}_{}", db, base_id)
@@ -1720,6 +1722,28 @@ mod tests {
17201722
..table1.clone()
17211723
};
17221724
assert_eq!(table7.id(DEFAULT_DATABASE_NAME), "local_users_1_0");
1725+
1726+
// Test 8: Empty default_database - backward compatibility for legacy deployments
1727+
// Legacy deployments had table IDs without database prefix (e.g., "AWSUploadEvent_0_0_0_0")
1728+
// When db_name is empty, we should NOT add a prefix
1729+
assert_eq!(
1730+
table1.id(""),
1731+
"users",
1732+
"Empty database should produce ID without prefix"
1733+
);
1734+
1735+
// Test 9: Empty default_database with version
1736+
let table9 = Table {
1737+
name: "AWSUploadEvent_0_0".to_string(),
1738+
version: Some(Version::from_string("0.0".to_string())),
1739+
database: None,
1740+
..table1.clone()
1741+
};
1742+
assert_eq!(
1743+
table9.id(""),
1744+
"AWSUploadEvent_0_0_0_0",
1745+
"Empty database with version should produce ID without database prefix"
1746+
);
17231747
}
17241748

17251749
#[test]

0 commit comments

Comments
 (0)