PropelORM v1 multiple databases
Asked Answered
P

1

10

I have few problems with setting PropelORM to work with multiple databases. I couldn't find anything useful in the documentation.

  1. Generating schemas from multiple databases

    I prefer to make a change to database schema first and then run

    $ propel-gen . reverse
    

    to get schema.xml. What if my system consists of more then one database? Can it generate multiple schemas? I know from the documentation buildtime-conf.xml has to be created but it doesn't do anything for me.

  2. Generating classes

    Let's say I created to different schemas blog.schema.xml and platform.schema.xml. Is it possible to:

    1. have a different class prefix for each schema? In build.properties I can set propel.classPrefix but that will work globally for each schema.

    2. have a different project name for each schema? Again in the build.properties I can set propel.project and that will create a certain directory in classes directory. Right now all classes will go to the same place. If I will use the same table name in both schemas one class will overwrite the other.

The solution I can come on my own is to have a 2 different directories setup for a certain database however I would prefer more elegant solution.

Phosphoroscope answered 30/11, 2012 at 15:34 Comment(3)
Those resources might be helpful: propelorm.org/cookbook/using-sql-schemas.html trac.propelorm.org/ticket/940Murrelet
Thank you Frosty. The documentation is clear but when I start following the guidelines it all works in a different way. The manual says about propel.schema.autoPrefix parameter. It doesn't auto prefix classes for me. The only thing it does for me is when propel.schema.autoNamespace is set to TRUE then it overwrites it to FALSE (perhaps not directly but this is the result).Phosphoroscope
Packages propelorm.org/cookbook/multi-component-data-model.html also don't work as per documentation. It says that if you set package on the DATABASE level it will create files in classes/my_project/package_name while for me it doesn't create my_project dir, all packages go directly to class. Just to be clear I got the latest version of propel1 from git.Phosphoroscope
C
1

Can you post the <database> line from your Schema?

As long as you have the following:

<database package="blog" name="blog" defaultIdMethod="native">

Inside of your blog.schema.xml it should generate a new directory for you. If you let propel lazyload those for you though, you are right you'll get collisions, so I just manually pre-pended something to my tables in the schema.xml (which might not be the most efficient thing to handle things).

But you can do something like:

  1. in blog.schema.xml:

     <table name="users" phpName="blogUsers" idMethod="native">
    
  2. in platform.schema.xml:

     <table name="users" phpName="platformUsers" idMethod="native">
    

That worked fine for me.

Cradle answered 4/1, 2013 at 1:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.