diff --git a/lib/apartment/adapters/postgresql_adapter.rb b/lib/apartment/adapters/postgresql_adapter.rb index 1c41b49f..4c4770e9 100644 --- a/lib/apartment/adapters/postgresql_adapter.rb +++ b/lib/apartment/adapters/postgresql_adapter.rb @@ -175,14 +175,28 @@ def preserving_search_path # def clone_pg_schema pg_schema_sql = patch_search_path(pg_dump_schema) - Apartment.connection.execute(pg_schema_sql) + + # Create a temporary file to store the SQL + Tempfile.create do |temp_file| + temp_file.write(pg_schema_sql) + temp_file.close # Close the file so psql can read it + + with_pg_env { system("psql", "-q", "-d", dbname, "-f", temp_file.path) } + end end # Copy data from schema_migrations into new schema # def copy_schema_migrations pg_migrations_data = patch_search_path(pg_dump_schema_migrations_data) - Apartment.connection.execute(pg_migrations_data) + + # Create a temporary file to store the SQL + Tempfile.create do |temp_file| + temp_file.write(pg_migrations_data) + temp_file.close # Close the file so psql can read it + + with_pg_env { system("psql", "-q", "-d", dbname, "-f", temp_file.path) } + end end # Dump postgres default schema