Skip to content

Commit b2fda68

Browse files
taariqclaude
andcommitted
fix: Interactive mode fails for non-PostgreSQL sources (SQLite, MongoDB, MySQL)
- Detect source type before entering interactive mode - Skip interactive mode automatically for non-PostgreSQL sources - Update README-SQLite.md examples to include -y flag - Fixes #72 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 812e24a commit b2fda68

5 files changed

Lines changed: 39 additions & 9 deletions

File tree

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## [7.0.5] - 2025-12-09
6+
7+
### Fixed
8+
9+
- **Interactive mode fails for non-PostgreSQL sources**: Fixed bug where `init`, `validate`, and `sync` commands would fail for SQLite, MongoDB, and MySQL sources because interactive mode attempted to connect to the source as PostgreSQL. The tool now detects the source type before entering interactive mode and automatically skips it for non-PostgreSQL sources.
10+
11+
### Changed
12+
13+
- **README-SQLite.md**: Updated all examples to include `-y` flag and added notes explaining that interactive mode only works with PostgreSQL sources.
14+
515
## [7.0.4] - 2025-12-09
616

717
### Fixed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "database-replicator"
3-
version = "7.0.4"
3+
version = "7.0.5"
44
edition = "2021"
55
license = "Apache-2.0"
66
description = "Universal database-to-PostgreSQL replication CLI. Supports PostgreSQL, SQLite, MongoDB, and MySQL."

README-SQLite.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ This guide explains how to replicate SQLite databases to PostgreSQL using databa
1111
**Note:** SQLite replication requires local execution (the `--local` flag) since the source file must be accessible from your machine.
1212

1313
```bash
14-
database-replicator init \
14+
database-replicator init -y \
1515
--source /path/to/database.db \
1616
--target "postgresql://user:pass@your-db.serendb.com:5432/db" \
1717
--local
1818
```
1919

20+
**Important:** The `-y` flag (or `--no-interactive`) is required for SQLite sources to skip the interactive database selection prompt, which only works with PostgreSQL sources.
21+
2022
---
2123

2224
## Installation
@@ -74,11 +76,13 @@ The tool automatically detects SQLite database files and replicates them to Post
7476
Replicate an entire SQLite database to PostgreSQL:
7577

7678
```bash
77-
database-replicator init \
79+
database-replicator init -y \
7880
--source /path/to/database.db \
7981
--target "postgresql://user:pass@target-host:5432/db"
8082
```
8183

84+
> **Note:** The `-y` flag skips interactive mode, which is required for SQLite sources.
85+
8286
The tool automatically:
8387
1. Detects that the source is SQLite (from `.db` extension)
8488
2. Validates the file path for security
@@ -249,7 +253,7 @@ Table names are validated before use in SQL:
249253
wget https://example.com/sample.db
250254

251255
# Migrate to PostgreSQL
252-
database-replicator init \
256+
database-replicator init -y \
253257
--source ./sample.db \
254258
--target "postgresql://localhost:5432/mydb"
255259
```
@@ -454,7 +458,7 @@ FROM users;
454458
sqlite3 test.db < test_data.sql
455459

456460
# Test replication
457-
database-replicator init --source test.db --target "postgresql://localhost/test"
461+
database-replicator init -y --source test.db --target "postgresql://localhost/test"
458462
```
459463

460464
3. **Verify PostgreSQL Space**

src/main.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,12 @@ async fn main() -> anyhow::Result<()> {
255255
anyhow::anyhow!("Target database URL not provided and not set in state. Use `--target` or `database-replicator target set`.")
256256
})?;
257257

258-
let filter = if !no_interactive {
258+
// Detect source type - interactive mode only works with PostgreSQL
259+
let source_type = database_replicator::detect_source_type(&source)
260+
.context("Failed to detect source database type")?;
261+
let is_postgres_source = matches!(source_type, database_replicator::SourceType::PostgreSQL);
262+
263+
let filter = if !no_interactive && is_postgres_source {
259264
// Interactive mode (default) - prompt user to select databases and tables
260265
let (filter, rules) =
261266
database_replicator::interactive::select_databases_and_tables(&source).await?;
@@ -324,17 +329,23 @@ async fn main() -> anyhow::Result<()> {
324329
|| include_tables.is_some()
325330
|| exclude_tables.is_some();
326331

332+
// Detect source type early to determine if interactive mode is supported
333+
let source_type = database_replicator::detect_source_type(&source)
334+
.context("Failed to detect source database type")?;
335+
let is_postgres_source = matches!(source_type, database_replicator::SourceType::PostgreSQL);
336+
327337
// Interactive mode is default unless:
328338
// - --no-interactive flag is set
329339
// - --yes flag is set (implies automation)
330340
// - CLI filter flags are provided
341+
// - Source is not PostgreSQL (interactive mode only works with PostgreSQL sources)
331342
// Run this BEFORE remote execution check so interactive mode works for both local and remote
332343
let (
333344
final_include_databases,
334345
final_exclude_databases,
335346
final_include_tables,
336347
final_exclude_tables,
337-
) = if !no_interactive && !yes && !has_cli_filters {
348+
) = if !no_interactive && !yes && !has_cli_filters && is_postgres_source {
338349
// Interactive mode (default) - prompt user to select databases and tables
339350
let (filter, _rules) =
340351
database_replicator::interactive::select_databases_and_tables(&source).await?;
@@ -525,7 +536,12 @@ async fn main() -> anyhow::Result<()> {
525536
|| include_tables.is_some()
526537
|| exclude_tables.is_some();
527538

528-
let filter = if !no_interactive && !has_cli_filters {
539+
// Detect source type - interactive mode only works with PostgreSQL
540+
let source_type = database_replicator::detect_source_type(&source)
541+
.context("Failed to detect source database type")?;
542+
let is_postgres_source = matches!(source_type, database_replicator::SourceType::PostgreSQL);
543+
544+
let filter = if !no_interactive && !has_cli_filters && is_postgres_source {
529545
// Interactive mode (default) - prompt user to select databases and tables
530546
let (filter, rules) =
531547
database_replicator::interactive::select_databases_and_tables(&source).await?;

0 commit comments

Comments
 (0)