MIOLO20
Carregando...
Procurando...
Nenhuma entrada encontrada
SchemaDiff.php
Ir para a documentação deste ficheiro.
1<?php
2/*
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.
14 *
15 * This software consists of voluntary contributions made by many individuals
16 * and is licensed under the LGPL. For more information, see
17 * <http://www.doctrine-project.org>.
18 */
19
20namespace Doctrine\DBAL\Schema;
21
22use \Doctrine\DBAL\Platforms\AbstractPlatform;
23
36{
42 public $newTables = array();
43
49 public $changedTables = array();
50
56 public $removedTables = array();
57
61 public $newSequences = array();
62
66 public $changedSequences = array();
67
71 public $removedSequences = array();
72
76 public $orphanedForeignKeys = array();
77
85 public function __construct($newTables = array(), $changedTables = array(), $removedTables = array())
86 {
87 $this->newTables = $newTables;
88 $this->changedTables = $changedTables;
89 $this->removedTables = $removedTables;
90 }
91
104 public function toSaveSql(AbstractPlatform $platform)
105 {
106 return $this->_toSql($platform, true);
107 }
108
113 public function toSql(AbstractPlatform $platform)
114 {
115 return $this->_toSql($platform, false);
116 }
117
123 protected function _toSql(AbstractPlatform $platform, $saveMode = false)
124 {
125 $sql = array();
126
127 if ($platform->supportsForeignKeyConstraints() && $saveMode == false) {
128 foreach ($this->orphanedForeignKeys AS $orphanedForeignKey) {
129 $sql[] = $platform->getDropForeignKeySQL($orphanedForeignKey, $orphanedForeignKey->getLocalTableName());
130 }
131 }
132
133 if ($platform->supportsSequences() == true) {
134 foreach ($this->changedSequences AS $sequence) {
135 $sql[] = $platform->getDropSequenceSQL($sequence);
136 $sql[] = $platform->getCreateSequenceSQL($sequence);
137 }
138
139 if ($saveMode === false) {
140 foreach ($this->removedSequences AS $sequence) {
141 $sql[] = $platform->getDropSequenceSQL($sequence);
142 }
143 }
144
145 foreach ($this->newSequences AS $sequence) {
146 $sql[] = $platform->getCreateSequenceSQL($sequence);
147 }
148 }
149
150 $foreignKeySql = array();
151 foreach ($this->newTables AS $table) {
152 $sql = array_merge(
153 $sql,
154 $platform->getCreateTableSQL($table, AbstractPlatform::CREATE_INDEXES)
155 );
156
157 if ($platform->supportsForeignKeyConstraints()) {
158 foreach ($table->getForeignKeys() AS $foreignKey) {
159 $foreignKeySql[] = $platform->getCreateForeignKeySQL($foreignKey, $table);
160 }
161 }
162 }
163 $sql = array_merge($sql, $foreignKeySql);
164
165 if ($saveMode === false) {
166 foreach ($this->removedTables AS $table) {
167 $sql[] = $platform->getDropTableSQL($table);
168 }
169 }
170
171 foreach ($this->changedTables AS $tableDiff) {
172 $sql = array_merge($sql, $platform->getAlterTableSQL($tableDiff));
173 }
174
175 return $sql;
176 }
177}
getCreateSequenceSQL(\Doctrine\DBAL\Schema\Sequence $sequence)
getCreateTableSQL(Table $table, $createFlags=self::CREATE_INDEXES)
getCreateForeignKeySQL(ForeignKeyConstraint $foreignKey, $table)
__construct($newTables=array(), $changedTables=array(), $removedTables=array())
Definição SchemaDiff.php:85
toSaveSql(AbstractPlatform $platform)
Definição SchemaDiff.php:104
toSql(AbstractPlatform $platform)
Definição SchemaDiff.php:113
_toSql(AbstractPlatform $platform, $saveMode=false)
Definição SchemaDiff.php:123