title: How to handle lots of tables (5.000) in Rails?
body: <p>I have a Ruby on Rails application running Ruby 2 and Rails 4. The main purpose of the application is to import and view data from other databases, which it does pretty well. To accomplish this I create MVCs and routes for every imported table. But I've come across a little performance problem and want to know if there is a way to optimize it.</p>
  
  <p>As example I import 5.000 tables into my application. For every table I need to define a route, a model, a controller and a view. I need to display, sort, search and export all or selected objects from a table.</p>
  
  <p>My workflow right now is that I have Sidekiq running in background scaffolding all those MVCs for every table and then creating a routes file (of which I have several) with 5.000 routes for those.</p>
  
  <p>The main problem is that having 25.000 files and a routes file with 20.000 lines of code isn't really helpful in keeping the application simple and fast.</p>
  
  <p>Another way I came up with was to have one dynamic MVC and a controller method for each table and get the data via:
  <code>ActiveRecord::Base.connection</code></p>
  
  <p>This would slim everything a little bit down having less files, less controllers and less models, but I would still have a lot of routes and views. And also I haven't found a solution to do searching, sorting and exporting like I do it right now.</p>
  
  <p>So, I would simply like to know, what solutions you have for such an hunge amount of tables. Anything tips, help and outside-the-box-thinking is really appreciated!</p>
  
  <p><strong>Update to clarfiy things:</strong></p>
  
  <p>Having 5.000 tables is neccessary. My application is basically a way to migrate old data from databases, files or whatever and store it in my application and the connected MySQL database. I'm talking here about millions of records, tenthousands of fields and just loads and loads of data that I cannot merge together or simplify, because I did not create the data in the first place, but I have to store it!</p>