diff --git a/lib/pgsync/sync.rb b/lib/pgsync/sync.rb index d80fd085..17210bbf 100644 --- a/lib/pgsync/sync.rb +++ b/lib/pgsync/sync.rb @@ -37,6 +37,8 @@ def perform print_description("From", source) print_description("To", destination) + raise Error, "Destination must be different from source" if source.url == destination.url + if (opts[:preserve] || opts[:overwrite]) && destination.server_version_num < 90500 raise Error, "Postgres 9.5+ is required for --preserve and --overwrite" end diff --git a/test/sync_test.rb b/test/sync_test.rb index e4f573b8..80c1302c 100644 --- a/test/sync_test.rb +++ b/test/sync_test.rb @@ -63,6 +63,10 @@ def test_preserve_no_primary_key assert_error "No primary key", "chapters --preserve", config: true end + def test_same_source_destination + assert_error "Destination must be different from source", "--from pgsync_test1 --to pgsync_test1", config: true + end + def test_no_shared_fields assert_prints "authors: No fields to copy", "authors", config: true end