Multi applications on 1 database

Hey,

I have a hosting where I can have only 1 database (shame on them!)
On that hosting I want to run 2 application, but those application has
the same models like

user.rb (table: users)
role.rb

Hey,

I have a hosting where I can have only 1 database (shame on them!)
On that hosting I want to run 2 application, but those application has
the same models like

user.rb (table: users)
role.rb (table: roles)

I have 2 Applcation A and B, and i want to run them at the same time. So
i will do this sort of solution (not very handy)

For each application I when put an extra letter in the tables names

Appliction A: a_users and a_roles
Appliction B: b_users and b_roles

This mean that I need to rename all me class to
a_user.rb a_role.rb
b_user.rb b_role.rb
And everywhere i use it :s:s:s

Isnt there something where i can say per model the tablename
Like:
a_user.rb tablename => a_users
a_role.rb tablename => a_roles
b_user.rb tablename => b_users
b_role.rb tablename => b_roles

Thanks

You can use table_name_prefix (part of your app’s config) to set a
prefix for table names on a per application basis (see
http://glu.ttono.us/articles/2006/05/22/configuring-rails-environments-the-cheat-sheet),
or you can use set_table_name if you want to change a model’s table name
on a per-model basis.

Fred

Frederick C. wrote:

You can use table_name_prefix (part of your app’s config) to set a
prefix for table names on a per application basis (see
http://glu.ttono.us/articles/2006/05/22/configuring-rails-environments-the-cheat-sheet),
or you can use set_table_name if you want to change a model’s table name
on a per-model basis.

Fred

Hey,

I want to have each table this prefix => “d_”

But where do i need to put this:

Rails::Initializer do |config|
config.table_name_prefix = “d_”
end

Thanks

Brutyn N. wrote:

i will do this sort of solution (not very handy)

For each application I when put an extra letter in the tables names

Appliction A: a_users and a_roles
Appliction B: b_users and b_roles

This mean that I need to rename all me class

Nah. First of all you can use ActiveRecord::Base.set_table_name to set
the name of a models table regardless of the name of the model.

But perhaps even easier would be to use
ActiveRecord::Base.table_name_prefix to set a global prefix for all your
tables. Dunno if this is actually easier in your case.


Jakob S. - http://mentalized.net

In your app’s config.rb

Fred

On 11/4/06, Brutyn N. [email protected] wrote:

Hey,

I have a hosting where I can have only 1 database (shame on them!)
On that hosting I want to run 2 application, but those application has
the same models like

user.rb (table: users)
role.rb

Hey, one problem with this is that if you’re using migrations (which
you should be), the migrations will conflict. i.e. let’s say you run
app a’s migrations, then app b will think the schema is up to that
number, which may not be good for app b.

I wrote a plugin to take care of this by recording the schema info
separately for each app you want to run.
http://svn.flpr.org/public/plugins/app_migrations/README

Basically you just install the plugin, and in your environment.rb file
add
ActiveRecord::Base.app_migration(:my_app_name)

Also if you set ActiveRecord::Base.table_name_prefix then all your
tables will have a prefix so there won’t be naming conflicts. With
all this set up you can develop with migrations and not worry about
any kind of migration or naming conflicts.

hth

Pat

thanks that works

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs