kstevens715
kstevens715

Reputation: 760

Dynamic Views Based on Variable

I'm using views to help slowly transition from a legacy database to a new one. For example, there is a client table in the legacy database which I am re-implementing in the new database (both databases are on the same server). I plan on replacing the client table with a client view in the legacy database that has the same signature as the original table.

I think my idea should work fine, except the new application is being developed in Rails, and depending on the environment the database name might be db_test, db_development or db_production.

How might I create a view in the legacy database that points to a table in the new database when the new database name will be changing? I've tried a number of things, but it's a pretty strange problem so I'm not even really sure where to begin.

This is an example of what I'd like to be able to do:

SET @db = 'db_development';
select * from @db.client;

If anyone can point me in the right direction, it would be greatly appreciated. Thank you.

Upvotes: 1

Views: 195

Answers (1)

eggyal
eggyal

Reputation: 125865

You can define triggers on both databases to keep them in sync.

Upvotes: 1

Related Questions