Skip to content

Instantly share code, notes, and snippets.

@barkerja
Last active August 29, 2015 14:16
Show Gist options
  • Select an option

  • Save barkerja/1d11f73a1868edbfbe86 to your computer and use it in GitHub Desktop.

Select an option

Save barkerja/1d11f73a1868edbfbe86 to your computer and use it in GitHub Desktop.
include RethinkDB::Shortcuts
conn = r.connect(host: ENV['RETHINKDB_URL'])
databases = r.db_list().run(conn)
databases.each do |database|
puts "Database: #{database}"
tables = r.db(database).table_list().run(conn)
tables.each do |table|
puts "Table: #{table}"
indexes = r.db(database).table(table).index_list().run(conn)
indexes.each do |index|
puts "Index: #{index}"
index_status = r.db(database).table(table).index_status(index).nth(0).run(conn)
next unless index_status['outdated'] == true
index_function = index_status['function']
r.db(database).table(table).index_create('new_index', index_function).run(conn)
r.db(database).table(table).index_wait('new_index').run(conn)
r.db(database).table(table).index_rename('new_index', index, overwrite: true).run(conn)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment