123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- <?php
-
-
- namespace Doctrine\DBAL\Schema;
-
- use \Doctrine\DBAL\Platforms\AbstractPlatform;
-
-
- class SchemaDiff
- {
-
-
- public $newTables = array();
-
-
-
- public $changedTables = array();
-
-
-
- public $removedTables = array();
-
-
-
- public $newSequences = array();
-
-
-
- public $changedSequences = array();
-
-
-
- public $removedSequences = array();
-
-
-
- public $orphanedForeignKeys = array();
-
-
-
- public function __construct($newTables = array(), $changedTables = array(), $removedTables = array())
- {
- $this->newTables = $newTables;
- $this->changedTables = $changedTables;
- $this->removedTables = $removedTables;
- }
-
-
-
- public function toSaveSql(AbstractPlatform $platform)
- {
- return $this->_toSql($platform, true);
- }
-
-
-
- public function toSql(AbstractPlatform $platform)
- {
- return $this->_toSql($platform, false);
- }
-
-
-
- protected function _toSql(AbstractPlatform $platform, $saveMode = false)
- {
- $sql = array();
-
- if ($platform->supportsForeignKeyConstraints() && $saveMode == false) {
- foreach ($this->orphanedForeignKeys AS $orphanedForeignKey) {
- $sql[] = $platform->getDropForeignKeySQL($orphanedForeignKey, $orphanedForeignKey->getLocalTableName());
- }
- }
-
- if ($platform->supportsSequences() == true) {
- foreach ($this->changedSequences AS $sequence) {
- $sql[] = $platform->getAlterSequenceSQL($sequence);
- }
-
- if ($saveMode === false) {
- foreach ($this->removedSequences AS $sequence) {
- $sql[] = $platform->getDropSequenceSQL($sequence);
- }
- }
-
- foreach ($this->newSequences AS $sequence) {
- $sql[] = $platform->getCreateSequenceSQL($sequence);
- }
- }
-
- $foreignKeySql = array();
- foreach ($this->newTables AS $table) {
- $sql = array_merge(
- $sql,
- $platform->getCreateTableSQL($table, AbstractPlatform::CREATE_INDEXES)
- );
-
- if ($platform->supportsForeignKeyConstraints()) {
- foreach ($table->getForeignKeys() AS $foreignKey) {
- $foreignKeySql[] = $platform->getCreateForeignKeySQL($foreignKey, $table);
- }
- }
- }
- $sql = array_merge($sql, $foreignKeySql);
-
- if ($saveMode === false) {
- foreach ($this->removedTables AS $table) {
- $sql[] = $platform->getDropTableSQL($table);
- }
- }
-
- foreach ($this->changedTables AS $tableDiff) {
- $sql = array_merge($sql, $platform->getAlterTableSQL($tableDiff));
- }
-
- return $sql;
- }
- }
|