How To: Build Your Schema from Multiple Database Connections

Multiple database connections are a great feature, but if you plan to generate a schema for each database, you will most certainly run into some problems caused by different connection names. This Howto will show you how to solve the problem.

Connections

Let’s start by defining our database connections: open up the file config/databases.yml and create at least two connections with different names (like „database” and „database1”).

all:
  database:
    class:          sfPropelDatabase
    param:
      dsn:          mysql://ptest:ptest@localhost/ptest 

database1:
    class:          sfPropelDatabase
    param:
      dsn:          mysql://ptest:ptest@localhost/ptest2

Schema

In the config/propel.ini configuration file, go to the the sixth line and edit the „propel.database.url” setting so that it matches the first database connection.

propel.database.url = mysql://ptest:ptest@localhost/ptest

Now we can execute the propel-build-schema command.

The next little problem is that the schema generator always assumes that a connection is named „propel” but since we’ve named it „database”, we need to open the just generated schema file and rename the connection (second line).

Before we go on and generate the second schema, we first need to rename the current one or otherwise symfony would just overwrite it.

mv config/schema.yml config/1_schema.yml

(Note: schema files must end with „schema.yml”)

Second schema

The procedure to generate the schema for the second connection is basically the same as for the first one:

  1. Edit the „propel.database.url” setting in propel.ini.
  2. Execute propel-build-schema.
  3. Open the schema and change the connection name from „propel” to „database1”.
  4. Rename the generated schema.yml to 2_schema.yml.

Finally, we can execute the propel-build-model command and are ready to use our databases.

Published: January 8, 2008 — Tagged: , , , ,

Comments

Ido, January 8th, 2008

Very good point!
I wonder what is the performance effect on such a configuration….
Do you have some details about it?

Arthur, January 8th, 2008

The only thing you’ll notice is that a second “connect” command is used (which doesn’t even need 1ms). It works beautifully.

Post a Comment

© 2008 Arthur Koziel — About | Archive | Colophon | Contact | Feeds

Bookmarks Bookmarks RSS Feed

IEBlog : IE8 Security Part IV: The XSS Filter
IE8 will include and enable an XSS filter by default. To disable it, a custom HTTP header needs to be set.
YAXML
YAXML is a perl script which transforms YAML into XML and back.
Visual language 1.0
PDF describing the BBC.co.uk global page restructure.