3 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15 * This software consists of voluntary contributions made by many individuals
16 * and is licensed under the MIT license. For more information, see
17 * <http://www.doctrine-project.org>.
20 namespace Doctrine\DBAL\Schema\Visitor;
22 use Doctrine\DBAL\Platforms\AbstractPlatform,
23 Doctrine\DBAL\Schema\Table,
24 Doctrine\DBAL\Schema\Schema,
25 Doctrine\DBAL\Schema\Column,
26 Doctrine\DBAL\Schema\ForeignKeyConstraint,
27 Doctrine\DBAL\Schema\Constraint,
28 Doctrine\DBAL\Schema\Sequence,
29 Doctrine\DBAL\Schema\Index;
32 * Remove assets from a schema that are not in the default namespace.
34 * Some databases such as MySQL support cross databases joins, but don't
35 * allow to call DDLs to a database from another connected database.
36 * Before a schema is serialized into SQL this visitor can cleanup schemas with
37 * non default namespaces.
39 * This visitor filters all these non-default namespaced tables and sequences
40 * and removes them from the SChema instance.
42 * @author Benjamin Eberlei <kontakt@beberlei.de>
45 class RemoveNamespacedAssets implements Visitor
53 * @param Schema $schema
55 public function acceptSchema(Schema $schema)
57 $this->schema = $schema;
63 public function acceptTable(Table $table)
65 if ( ! $table->isInDefaultNamespace($this->schema->getName()) ) {
66 $this->schema->dropTable($table->getName());
70 * @param Sequence $sequence
72 public function acceptSequence(Sequence $sequence)
74 if ( ! $sequence->isInDefaultNamespace($this->schema->getName()) ) {
75 $this->schema->dropSequence($sequence->getName());
80 * @param Column $column
82 public function acceptColumn(Table $table, Column $column)
87 * @param Table $localTable
88 * @param ForeignKeyConstraint $fkConstraint
90 public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint)
92 // The table may already be deleted in a previous
93 // RemoveNamespacedAssets#acceptTable call. Removing Foreign keys that
95 if ( ! $this->schema->hasTable($fkConstraint->getForeignTableName())) {
96 $localTable->removeForeignKey($fkConstraint->getName());
100 $foreignTable = $this->schema->getTable($fkConstraint->getForeignTableName());
101 if ( ! $foreignTable->isInDefaultNamespace($this->schema->getName()) ) {
102 $localTable->removeForeignKey($fkConstraint->getName());
107 * @param Table $table
108 * @param Index $index
110 public function acceptIndex(Table $table, Index $index)