TableDiff.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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 MIT license. For more information, see
  17. * <http://www.doctrine-project.org>.
  18. */
  19. namespace Doctrine\DBAL\Schema;
  20. use Doctrine\DBAL\Platforms\AbstractPlatform;
  21. /**
  22. * Table Diff.
  23. *
  24. * @link www.doctrine-project.org
  25. * @since 2.0
  26. * @author Benjamin Eberlei <kontakt@beberlei.de>
  27. */
  28. class TableDiff
  29. {
  30. /**
  31. * @var string
  32. */
  33. public $name = null;
  34. /**
  35. * @var string|boolean
  36. */
  37. public $newName = false;
  38. /**
  39. * All added fields.
  40. *
  41. * @var \Doctrine\DBAL\Schema\Column[]
  42. */
  43. public $addedColumns;
  44. /**
  45. * All changed fields.
  46. *
  47. * @var \Doctrine\DBAL\Schema\ColumnDiff[]
  48. */
  49. public $changedColumns = array();
  50. /**
  51. * All removed fields.
  52. *
  53. * @var \Doctrine\DBAL\Schema\Column[]
  54. */
  55. public $removedColumns = array();
  56. /**
  57. * Columns that are only renamed from key to column instance name.
  58. *
  59. * @var \Doctrine\DBAL\Schema\Column[]
  60. */
  61. public $renamedColumns = array();
  62. /**
  63. * All added indexes.
  64. *
  65. * @var \Doctrine\DBAL\Schema\Index[]
  66. */
  67. public $addedIndexes = array();
  68. /**
  69. * All changed indexes.
  70. *
  71. * @var \Doctrine\DBAL\Schema\Index[]
  72. */
  73. public $changedIndexes = array();
  74. /**
  75. * All removed indexes
  76. *
  77. * @var \Doctrine\DBAL\Schema\Index[]
  78. */
  79. public $removedIndexes = array();
  80. /**
  81. * Indexes that are only renamed but are identical otherwise.
  82. *
  83. * @var \Doctrine\DBAL\Schema\Index[]
  84. */
  85. public $renamedIndexes = array();
  86. /**
  87. * All added foreign key definitions
  88. *
  89. * @var \Doctrine\DBAL\Schema\ForeignKeyConstraint[]
  90. */
  91. public $addedForeignKeys = array();
  92. /**
  93. * All changed foreign keys
  94. *
  95. * @var \Doctrine\DBAL\Schema\ForeignKeyConstraint[]
  96. */
  97. public $changedForeignKeys = array();
  98. /**
  99. * All removed foreign keys
  100. *
  101. * @var \Doctrine\DBAL\Schema\ForeignKeyConstraint[]
  102. */
  103. public $removedForeignKeys = array();
  104. /**
  105. * @var \Doctrine\DBAL\Schema\Table
  106. */
  107. public $fromTable;
  108. /**
  109. * Constructs an TableDiff object.
  110. *
  111. * @param string $tableName
  112. * @param \Doctrine\DBAL\Schema\Column[] $addedColumns
  113. * @param \Doctrine\DBAL\Schema\ColumnDiff[] $changedColumns
  114. * @param \Doctrine\DBAL\Schema\Column[] $removedColumns
  115. * @param \Doctrine\DBAL\Schema\Index[] $addedIndexes
  116. * @param \Doctrine\DBAL\Schema\Index[] $changedIndexes
  117. * @param \Doctrine\DBAL\Schema\Index[] $removedIndexes
  118. * @param \Doctrine\DBAL\Schema\Table|null $fromTable
  119. */
  120. public function __construct($tableName, $addedColumns = array(),
  121. $changedColumns = array(), $removedColumns = array(), $addedIndexes = array(),
  122. $changedIndexes = array(), $removedIndexes = array(), Table $fromTable = null)
  123. {
  124. $this->name = $tableName;
  125. $this->addedColumns = $addedColumns;
  126. $this->changedColumns = $changedColumns;
  127. $this->removedColumns = $removedColumns;
  128. $this->addedIndexes = $addedIndexes;
  129. $this->changedIndexes = $changedIndexes;
  130. $this->removedIndexes = $removedIndexes;
  131. $this->fromTable = $fromTable;
  132. }
  133. /**
  134. * @param AbstractPlatform $platform The platform to use for retrieving this table diff's name.
  135. *
  136. * @return \Doctrine\DBAL\Schema\Identifier
  137. */
  138. public function getName(AbstractPlatform $platform)
  139. {
  140. return new Identifier(
  141. $this->fromTable instanceof Table ? $this->fromTable->getQuotedName($platform) : $this->name
  142. );
  143. }
  144. /**
  145. * @return \Doctrine\DBAL\Schema\Identifier|boolean
  146. */
  147. public function getNewName()
  148. {
  149. return $this->newName ? new Identifier($this->newName) : $this->newName;
  150. }
  151. }