2

I am currently a developer of a multi-tenant application in which there is a "master" database, which holds customer's data and is also used as a template, that is, it gets copied with a different name for each new customer, to hold its data.

When using Propel ORM in PHP, the model configuration is done in an XML file structured like this:

<?xml version="1.0" encoding="UTF-8"?>
<database name="master_db" defaultIdMethod="native">
  <!-- here are tables' definitions -->
</database>

Is it possible to use the same XML file to model all the connections to all of the customers' databases, or would I need a separate file for each one, completely identical except for the database name?

As my question has been marked as a potential duplicate of this one, which I had found before, I'd like to explain why it is different:

  • in this case, the number of databases will change over time, while in that question it is fixed
  • in this case, all the databases and all the tables in each, will have exactly the same structure
  • I do not want different classes for each customer, but rather a single set of model classes, which will query the last selected database
Community
  • 1
  • 1
Matteo Tassinari
  • 18,121
  • 8
  • 60
  • 81
  • Possible duplicate of [Propel Multiple Database Modeling](http://stackoverflow.com/questions/11270008/propel-multiple-database-modeling) – Dez Dec 24 '16 at 14:05
  • @Dez I had seen that before, I do not think my question is really a dupe though. – Matteo Tassinari Dec 24 '16 at 14:10

1 Answers1

1

What you ask for sounds a good candidate for XML Inclusions in the configuration files:

The master-db.xml file

<?xml version="1.0" encoding="UTF-8"?>
<database name="master_db" defaultIdMethod="native">
  <!-- here are tables' definitions -->
</database>

alongside the propel.xml file

<?xml version="1.0" encoding="UTF-8"?>
<config>
  <propel>
    <database name="blueberryshoechamp_db" defaultIdMethod="native">
      <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
                  href="master-db.xml"
                  xpointer="xpointer( /database/* )"
                  />
    </database>
  ...

This will then include all child-elements of the database document element from the master-db.xml file.

Just the mixing you're looking for.

The good news: Propel2 supports this now, the feature was introduced in:

hakre
  • 193,403
  • 52
  • 435
  • 836
  • If this gets implemented, it would really be what I am looking for! This also confirms that, as of now, I would need to copy the whole XML file too, right? – Matteo Tassinari Jan 02 '17 at 08:07
  • Yes, but you could externalize the process and generalte the propel.xml document with some PHP script. – hakre Jan 02 '17 at 17:10
  • 1
    @MatteoTassinari: This has landed in Propel2 now, https://github.com/propelorm/Propel2/commit/b311676a95eef3dacc229424e73be04992dd7b78 – hakre Jun 20 '17 at 07:55