Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrations cannot support mlutiple schemas #6

Closed
willdurand opened this issue Aug 4, 2011 · 6 comments
Closed

Migrations cannot support mlutiple schemas #6

willdurand opened this issue Aug 4, 2011 · 6 comments

Comments

@willdurand
Copy link
Contributor

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

schema1:

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

schema2:

<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`;
(snip)
CREATE TABLE `beta`.`projects`
(snip)
CREATE TABLE `analysisdbv2`.`analyzer_log`

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

@drmikecrowe
Copy link

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

@fzaninotto
Copy link
Member

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

(https://github.com/propelorm/Propel/blob/master/generator/lib/model/diff/PropelDatabaseComparator.php)

@drmikecrowe
Copy link

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"/>
    </foreign-key>

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

@fzaninotto
Copy link
Member

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

@drmikecrowe
Copy link

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?

@FernandoFigueroa
Copy link

Hi all, i have the same problem:

SET FOREIGN_KEY_CHECKS = 0;
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

MDrollette pushed a commit to OrderMyGear/Propel that referenced this issue Apr 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants