|
|
|
@ -39,6 +39,9 @@ class Table
|
|
|
|
|
# See http://www.postgresql.org/docs/9.3/static/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS
|
|
|
|
|
PG_IDENTIFIER_MAX_LENGTH = 63
|
|
|
|
|
|
|
|
|
|
# @see services/importer/lib/importer/column.rb -> RESERVED_WORDS
|
|
|
|
|
# @see config/initializers/carto_db.rb -> RESERVED_COLUMN_NAMES
|
|
|
|
|
RESERVED_COLUMN_NAMES = %w(oid tableoid xmin cmin xmax cmax ctid ogc_fid).freeze
|
|
|
|
|
PUBLIC_ATTRIBUTES = {
|
|
|
|
|
:id => :id,
|
|
|
|
|
:name => :name,
|
|
|
|
@ -857,8 +860,7 @@ class Table
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def add_column!(options)
|
|
|
|
|
raise CartoDB::InvalidColumnName if Carto::DB::Sanitize::RESERVED_COLUMN_NAMES.include?(options[:name]) ||
|
|
|
|
|
options[:name] =~ /^[0-9]/
|
|
|
|
|
raise CartoDB::InvalidColumnName if RESERVED_COLUMN_NAMES.include?(options[:name]) || options[:name] =~ /^[0-9]/
|
|
|
|
|
type = options[:type].convert_to_db_type
|
|
|
|
|
cartodb_type = options[:type].convert_to_cartodb_type
|
|
|
|
|
column_name = options[:name].to_s.sanitize_column_name
|
|
|
|
@ -913,9 +915,7 @@ class Table
|
|
|
|
|
raise 'Please provide a column name' if new_name.empty?
|
|
|
|
|
raise 'This column cannot be renamed' if CARTODB_COLUMNS.include?(old_name.to_s)
|
|
|
|
|
|
|
|
|
|
if new_name =~ /^[0-9]/ ||
|
|
|
|
|
Carto::DB::Sanitize::RESERVED_COLUMN_NAMES.include?(new_name) ||
|
|
|
|
|
CARTODB_COLUMNS.include?(new_name)
|
|
|
|
|
if new_name =~ /^[0-9]/ || RESERVED_COLUMN_NAMES.include?(new_name) || CARTODB_COLUMNS.include?(new_name)
|
|
|
|
|
raise CartoDB::InvalidColumnName, 'That column name is reserved, please choose a different one'
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|