Skip to content

Commit

Permalink
Merge branch 'feature/CDB-818' into release/2.3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
luisbosque committed Oct 30, 2013
2 parents 0e1e4e8 + 90e5a79 commit 020307d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
14 changes: 10 additions & 4 deletions app/models/synchronization/adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,16 @@ def overwrite(table_name, result)

def cartodbfy(table_name)
table = ::Table.where(name: table_name, user_id: user.id).first
# Set default triggers
table.import_to_cartodb
#table.migrate_existing_table = table_name
table.force_schema = true
table.send :update_updated_at
table.import_to_cartodb(table_name)
table.schema(reload: true)
table.import_cleanup
table.save
table.send(:set_the_geom_column!)
table.schema(reload: true)
table.reload
# Set default triggers
table.send :set_the_geom_column!
table.send :update_table_pg_stats
table.send :add_python
table.send :set_trigger_cache_timestamp
Expand All @@ -56,6 +61,7 @@ def cartodbfy(table_name)
table.send(:invalidate_varnish_cache)
puts '======= after invalidating'
database.run("UPDATE #{table.name} SET updated_at = updated_at")
#WHERE cartodb_id = (SELECT max(cartodb_id) FROM #{table.name})")
rescue => exception
stacktrace = exception.to_s + exception.backtrace.join
puts stacktrace
Expand Down
14 changes: 9 additions & 5 deletions app/models/table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -232,23 +232,27 @@ def append_to_table(options)
# => leaving both in tact while creating a new tthat contains both
end

def import_to_cartodb
if migrate_existing_table.present?
def import_to_cartodb(uniname=nil)
puts "==== before migration existing table"
@data_import ||= DataImport.where(id: data_import_id).first
if migrate_existing_table.present? || uniname
puts "======= import_to_cartodb"
puts "======= import_to_cartodb"
@data_import.data_type = 'external_table'
@data_import.data_source = migrate_existing_table
@data_import.data_source = migrate_existing_table || uniname
#@data_import.migrate
@data_import.save

# ensure unique name, also ensures self.name can override any imported table name
uniname = self.name ? get_valid_name(self.name) : get_valid_name(migrate_existing_table)
uniname ||= self.name ? get_valid_name(self.name) : get_valid_name(migrate_existing_table)

# with table #{uniname} table created now run migrator to CartoDBify
hash_in = ::Rails::Sequel.configuration.environment_for(Rails.env).merge(
"database" => database_name,
:logger => ::Rails.logger,
"username" => owner.database_username,
"password" => owner.database_password,
:current_name => migrate_existing_table,
:current_name => migrate_existing_table || uniname,
:suggested_name => uniname,
:debug => (Rails.env.development?),
:remaining_quota => owner.remaining_quota,
Expand Down

0 comments on commit 020307d

Please sign in to comment.