Skip to content

Commit c1fc225

Browse files
committed
fix: Save SerenDB target state from init for use by sync command
Previously, when using interactive SerenDB target selection with init, the captured TargetState (containing project_id, branch_id, etc.) was never persisted to disk. This forced users to manually find their project_id and pass it via --project-id when running sync. This commit fixes two issues: 1. init now saves TargetState to .seren-replicator/target.json after interactive selection 2. sync now loads project_id from saved state if not provided via CLI The infrastructure for this already existed in serendb/target.rs - it just was not being called.
1 parent 2082f5c commit c1fc225

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

src/main.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,8 @@ async fn main() -> anyhow::Result<()> {
275275
let (conn_str, target_state) =
276276
database_replicator::interactive::select_seren_database().await?;
277277
target = Some(conn_str);
278+
// Save target state for use by subsequent commands (sync, status, etc.)
279+
database_replicator::serendb::save_target_state(&target_state)?;
278280
seren_target_state = Some(target_state);
279281
}
280282

@@ -460,8 +462,16 @@ async fn main() -> anyhow::Result<()> {
460462
filter.with_table_rules(table_rule_data)
461463
};
462464

463-
// If project_id is provided and target is SerenDB, check/enable logical replication
464-
if let Some(ref project_id) = project_id {
465+
// Get project_id from CLI or saved target state
466+
let effective_project_id = project_id.or_else(|| {
467+
database_replicator::serendb::load_target_state()
468+
.ok()
469+
.flatten()
470+
.map(|state| state.project_id)
471+
});
472+
473+
// If project_id is available and target is SerenDB, check/enable logical replication
474+
if let Some(ref project_id) = effective_project_id {
465475
if database_replicator::utils::is_serendb_target(&resolved_target) {
466476
check_and_enable_logical_replication(project_id, &console_api).await?;
467477
}

0 commit comments

Comments
 (0)