Skip to content

Commit 9ead351

Browse files
committed
fix: address PR review feedback
- auto-declare: collect existing tables before delete+recreate so they are preserved in the new database; also pass expires_at through - databases create hint: update to new --catalog/--table flag syntax - api.rs: fix workspace_id() doc comment placement
1 parent 80ab6d6 commit 9ead351

2 files changed

Lines changed: 22 additions & 8 deletions

File tree

src/api.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,11 @@ impl ApiClient {
181181
self
182182
}
183183

184-
/// Test-only client (no config load). Used with a local mock HTTP server.
185184
pub fn workspace_id(&self) -> Option<&str> {
186185
self.workspace_id.as_deref()
187186
}
188187

188+
/// Test-only client (no config load). Used with a local mock HTTP server.
189189
/// The refresher returns `None`, so 401s are not retried — matching the
190190
/// behavior of tests that don't exercise the refresh path.
191191
#[cfg(test)]

src/databases.rs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ pub struct Database {
3030
pub default_catalog: Option<String>,
3131
pub default_connection_id: String,
3232
#[serde(default)]
33+
pub expires_at: Option<String>,
34+
#[serde(default)]
3335
attachments: Vec<DatabaseAttachment>,
3436
}
3537

@@ -653,12 +655,13 @@ pub fn create(
653655
format!(
654656
concat!(
655657
"Load a table:\n",
656-
" hotdata databases load --file <path.parquet> {}.<table_name>\n",
658+
" hotdata databases load --catalog {0} --table <table> --file <path.parquet>\n",
659+
" hotdata databases load --catalog {0} --table <table> --url <url>\n",
657660
"\nQuery with:\n",
658-
" hotdata query --database {} \"SELECT * FROM {}.public.<table> LIMIT 10\"\n",
661+
" hotdata query \"SELECT * FROM {0}.public.<table> LIMIT 10\"\n",
659662
"\n Tip: column names are case-sensitive — wrap uppercase names in double quotes",
660663
),
661-
result.id, result.id, catalog
664+
catalog
662665
)
663666
.dark_grey()
664667
);
@@ -823,8 +826,19 @@ pub fn tables_load(
823826
let (status, resp_body) = if !status.is_success()
824827
&& crate::util::api_error(resp_body.clone()).contains("not declared")
825828
{
826-
// The table wasn't declared at create time. Delete the database and
827-
// recreate it with the table declared, then retry the load.
829+
// The table wasn't declared at create time. Collect existing tables so
830+
// they are re-declared in the replacement database, then delete and
831+
// recreate with all tables (including the new one) declared.
832+
let existing = collect_tables(&api, &db.default_connection_id, None);
833+
let mut all_tables: Vec<String> = existing
834+
.iter()
835+
.map(|t| format!("{}.{}", t.schema, t.table))
836+
.collect();
837+
let new_table_key = format!("{schema}.{table}");
838+
if !all_tables.contains(&new_table_key) {
839+
all_tables.push(new_table_key);
840+
}
841+
828842
let (del_status, del_body) = api.delete_raw(&format!("/databases/{}", db.id));
829843
if !del_status.is_success() {
830844
eprintln!("{}", crate::util::api_error(del_body).red());
@@ -834,8 +848,8 @@ pub fn tables_load(
834848
db.name.as_deref(),
835849
db.default_catalog.as_deref(),
836850
schema,
837-
&[table.to_string()],
838-
None,
851+
&all_tables,
852+
db.expires_at.as_deref(),
839853
);
840854
let (create_status, create_body_resp) = api.post_raw("/databases", &create_body);
841855
if !create_status.is_success() {

0 commit comments

Comments
 (0)