Migrations cannot support mlutiple schemas #6

willdurand opened this Issue Aug 4, 2011 · 6 comments

4 participants

Propel member

The new 1.6 migrations cannot support multiple schemas. If you have 2 schemas:


<database package="beta" name="scratch" schema="beta" defaultIdMethod="native">
  <table name="projects" phpName="Projects">


<database package="analysisdbv2" name="scratch" schema="analysisdbv2" defaultIdMethod="native">
  <table name="analyzer_log" phpName="AnalyzerLog">

The diff task generates:

DROP TABLE IF EXISTS `analyzer_log`;
CREATE TABLE `beta`.`projects`
CREATE TABLE `analysisdbv2`.`analyzer_log`

Imported from: http://www.propelorm.org/ticket/1483


I'll take a crack at fixing this, if somebody can point me in the right direction.

Propel member

Look at PropelDatabaseComparator::compareTable(). I think it only compare table names, not schemas.



Francois, Initially, looks like Database->hasTable() and getTable() should have some code like this:

                if ($this->schema && $this->getPlatform() && $this->getPlatform()->supportsSchemas()) {
                    $offset = strlen($this->schema)+1;
                    if ( substr(strtolower($name),0,$offset) == $this->schema . '.') {
                        $name = substr($name,$offset);

However, in Table->setupReferrers(), there is this line:

    $foreignTable = $this->getDatabase()->getTable($foreignKey->getForeignTableName());

I am using multiple schemas to reference a foreign key to the other schema (and what's worse, in SQL only, not a real foreign key). XML looks like:

    <foreign-key name="beta_projects" foreignTable="projects" foreignSchema="beta" skipSql = "true" phpName="BetaProjects">
      <reference local="project_id" foreign="id"/>

Any suggestions on how to handle a foreign key reference to a different schema?

Propel member

Well, with your example, that wouldn't work with 'hasTable(), but that would work with 'getTable()', right?


The issue is the foreign key references a table/field in another schema, and hence another Database (I believe). Therefore, when checking the database analysisdbv2, the above foreign key references the beta schema, which would be beta.projects.id. When you are in the analysisdbv2 database structure, inspecting foreign keys, how can/should we validate a reference to an external schema?

@willdurand willdurand closed this in cf3d4cb Sep 9, 2013

Hi all, i have the same problem:

DROP TABLE IF EXISTS fos_user_group;
RENAME TABLE fos_user TO master.fos_user;
RENAME TABLE fos_group TO master.fos_group;

And so on, is there any workaround for this issue (Using other tools e.g)?? I have symfony 2.6.11 and propel-bundle 1.4.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment