Merge pull request #2587 from CartoDB/2569-sync_tables_break_visualizations

Using org schema instead of public fixes #2569
pull/2577/head^2
Juan Ignacio Sánchez Lara 10 years ago
commit 5430c09995

2
.gitignore vendored

@ -54,3 +54,5 @@ node_modules
_SpecRunner.html
vendor/assets/javascripts/cartodb.*
vendor/assets/stylesheets/cartodb.*
public/test_support.csv
public/test_guess_country.csv

@ -25,10 +25,11 @@ module CartoDB
data_for_exception << "1st result:#{runner.results.first.inspect}"
raise data_for_exception
end
copy_privileges("public.#{table_name}", result.qualified_table_name)
copy_indexes("public.#{table_name}", result.qualified_table_name)
copy_privileges(user.database_schema, table_name, result.schema, result.table_name)
index_statements = generate_index_statements(user.database_schema, table_name)
overwrite(table_name, result)
cartodbfy(table_name)
run_index_statements(index_statements)
end
self
rescue => exception
@ -151,36 +152,50 @@ module CartoDB
"#{table_name}_to_be_deleted"
end
def copy_privileges(origin_table_name, destination_table_name)
def copy_privileges(origin_schema, origin_table_name, destination_schema, destination_table_name)
user.in_database(as: :superuser).execute(%Q(
UPDATE pg_class
SET relacl=(
SELECT relacl FROM pg_class
WHERE relname='#{origin_table_name}'
SELECT r.relacl FROM pg_class r, pg_namespace n
WHERE r.relname='#{origin_table_name}'
and r.relnamespace = n.oid
and n.nspname = '#{origin_schema}'
)
WHERE relname='#{destination_table_name}'
and relnamespace = (select oid from pg_namespace where nspname = '#{destination_schema}')
))
rescue => exception
Rollbar.report_message('Error copying privileges', 'error',
{ error: exception.inspect,
origin_schema: origin_schema,
origin_table_name: origin_table_name,
destination_schema: destination_schema,
destination_table_name: destination_table_name } )
end
def copy_indexes(origin_table_name, destination_table_name)
origin_schema, origin_table_name = origin_table_name.split('.')
def generate_index_statements(origin_schema, origin_table_name)
user.in_database(as: :superuser)[%Q(
SELECT indexdef AS indexdef
FROM pg_indexes
WHERE schemaname = '#{origin_schema}'
AND tablename = '#{origin_table_name}'
)].each do |record|
)].map { |record|
record.fetch(:indexdef)
}
end
def run_index_statements(statements)
statements.each { |statement|
begin
statement = record.fetch(:indexdef).gsub(
/ON #{origin_table_name}/,
"ON #{destination_table_name}"
)
puts statement.inspect
database.run(statement)
rescue => exception
puts "copy_indexes(#{origin_table_name},#{destination_table_name}) ERROR: #{exception.to_s}"
if exception.message !~ /relation .* already exists/
Rollbar.report_message('Error copying indexes', 'error',
{ error: exception.inspect,
statement: statement } )
end
end
end
}
end
private

@ -292,7 +292,7 @@ class Table < Sequel::Model(:user_tables)
errors.add(:privacy, 'unauthorized to create private tables')
end
# if the table exists, is private, but the owner no longer has private privilidges
# if the table exists, is private, but the owner no longer has private privileges
if !self.new? && privacy == PRIVACY_PRIVATE && self.changed_columns.include?(:privacy)
errors.add(:privacy, 'unauthorized to modify privacy status to private')
end

@ -33,6 +33,6 @@ module CartoDB
@db.drop_table(relation.to_sym)
end #drop
end
end # Visualization
end # CartoDB
end
end

Loading…
Cancel
Save