diff --git a/NEWS.md b/NEWS.md index 7c7463c964..08047d4f0c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -59,6 +59,7 @@ Development - Allow importing datasets with exhausted map quota [#16320](https://github.com/CartoDB/cartodb/pull/16320) - Fix empty ArcGIS imports [#16322](https://github.com/CartoDB/cartodb/pull/16322) - Fix data overwrite when a user is promoted to admin [#16351](https://github.com/CartoDB/cartodb/pull/16351) +- Update analysis schema when a user is promoted to organization owner [#16358](https://github.com/CartoDB/cartodb/pull/16358) - Add setting to disable diagnosis page [#16324](https://github.com/CartoDB/cartodb/pull/16324) - Fix wrong layer schema when creating a map from a shared dataset [#16323](https://github.com/CartoDB/cartodb/pull/16323) - Fix auto guessing when a csv field is wrong [#16326](https://github.com/CartoDB/cartodb/pull/16326) diff --git a/app/models/user/db_service.rb b/app/models/user/db_service.rb index 633220b10d..70dcaed0b5 100644 --- a/app/models/user/db_service.rb +++ b/app/models/user/db_service.rb @@ -277,6 +277,25 @@ module CartoDB end end + def update_analyses_schema + @user.carto_user.tables.each do |table| + table.dependent_visualizations.each do |visualization| + visualization.analyses.each do |analysis| + analysis.update_table_name( + "#{SCHEMA_PUBLIC}.#{table.name}", + "\"#{@user.database_schema}\".#{table.name}" + ) + end + end + end + rescue StandardError => e + Rails.logger.error( + exception: e, + message: 'Error updating schema of user analyses while moving to own schema', + user: @user.username + ) + end + def create_importer_schema create_schema('cdb_importer') end @@ -1193,6 +1212,7 @@ module CartoDB create_public_db_user set_database_search_path + update_analyses_schema end rescue StandardError => e # Undo metadata changes if process fails