thanks for your time first ... after all the google search, github and here, and more embarrassed about the big words (partition / shard / fedorate), I believe that I should describe the specific problem that I met and ask around.
Huge users and orders work in the databases of my company, so we separate databases and tables in various ways, some of which are described below:
way database and table name shard by (maybe it should be called partitioned by?)
YZ.X db_YZ.tb_X order serial number last three digits
YYYYMMDD. db_YYYYMMDD.tb date
YYYYMM.DD db_YYYYMM.tb_ DD date too
The basic concept is that the databases and tables are separated by field (not necessarily the primary key), and there are too many databases and too many tables, so that the record or the magic creation of one database.yml configuration for each database and one model for each table is impossible or at least not the best solution.
I studied smart solutions, as well as data and even the source code of an active record, maybe I could use ERB to generate database.yml and connect to the database around the filter, and maybe I could use named_scope to dynamically solve the table name problem to search, but update / create operations are limited to "self.class.quoted_table_table", so I could not easily solve my problem. And even I could create one model for each table, because its number is up to 30 most.
But it's just not DRY!
I need a clean solution, for example the following DSL:
class Order < ActiveRecord::Base
shard_by :order_serialno do |key|
[get_db_config_by(key),
get_db_name_by(key),
get_tb_name_by(key),
]
end
end
Can anyone tell me? Any help would be greatly appreciated ~~~~