diff --git a/app/connectors/importer.rb b/app/connectors/importer.rb index aac656e01e..b48f347039 100644 --- a/app/connectors/importer.rb +++ b/app/connectors/importer.rb @@ -322,6 +322,7 @@ module CartoDB @table_setup.cartodbfy(name) @table_setup.fix_oid(name) @table_setup.run_table_statements(table_statements, @database) + @table_setup.sanitize_columns(name) @table_setup.update_cdb_tablemetadata(name) restore_permissions_for(name) end @@ -349,6 +350,16 @@ module CartoDB orig_schema = user.in_database.schema(results.first.tables.first, reload: true, schema: ORIGIN_SCHEMA) dest_schema = user.in_database.schema(name, reload: true, schema: user.database_schema) + # NOTE: Sanitize columnn names from 'orig_schema' due to the 'dest_schema' columns were + # already sanitized before table creation in `Table#before_create` + orig_schema.each do |column| + column[0] = CartoDB::Importer2::Column.get_valid_column_name( + column.first.to_s, + data_import&.column_sanitization_version || CartoDB::Importer2::Column::NO_COLUMN_SANITIZATION_VERSION, + orig_schema.map(&:first).map(&:to_s) + ).to_sym + end + dest_schema.each do |dest_row| next if COLUMNS_NOT_TO_VALIDATE.include?(dest_row[0]) return false unless orig_schema.any? { |orig_row| rows_assignable?(dest_row, orig_row) } diff --git a/lib/carto/importer/table_setup.rb b/lib/carto/importer/table_setup.rb index f77ebc3f04..3a91bf9112 100644 --- a/lib/carto/importer/table_setup.rb +++ b/lib/carto/importer/table_setup.rb @@ -73,6 +73,13 @@ module Carto @user.tables.where(name: name).first.update_cdb_tablemetadata end + def sanitize_columns(name) + @user.tables.where(name: name).first.service.sanitize_columns( + database_schema: @user.database_schema, + connection: @user.in_database + ) + end + private def log_context