-
Notifications
You must be signed in to change notification settings - Fork 36
Description
There is a need for RMRE to be able to create tables and models that reside in multiple schemas (eg postgres) or multiple databases (eg Sybase). The underlying database allows joins between such tables and the ability to get models that can describe all the tables would be a nice feature.
Postgres tables have the full name as "schema.tablename"
Sybase tables have the full name as "db.owner.tablename"
For example, in Postgres, we could have two schemas, x and y, with the following tables.
x.resources
y.jobs
The models generated should have the fully qualified table names in them, and the model class names have the schema name as part of it
So the resultant model files might be
x_resources.rb
class X_Resource < ActiveRecord::Base
self.table_name = 'x.resources'
has_many :jobs, :class_name => 'Y_Job'
end
y_jobs.rb
class Y_Job < ActiveRecord::Base
self.table_name = 'y.jobs'
belongs_to :resource, :class_name => 'X_Resource', :foreign_key => :resource_id
end
This becomes especially important when the schemas contain tables with the same name in both schemas. Moreover, while it is possible to hand code the models (as I did in the above models), when the schemas contains hundreds of tables with complex relationships (that may change over time), hand coding and maintaining the models is something to be avoided.
Database design and creation is often done external to rails, with tools designed for this purpose, so it would not be reasonable to expect to do this within rails. Hence a tool like RMRE for such databases becomes very important.
Adding the support for table namespaces (schema.table or database.owner.table) would make this tool really robust.