TableDiff.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. namespace Doctrine\DBAL\Schema;
  3. use Doctrine\DBAL\Platforms\AbstractPlatform;
  4. /**
  5. * Table Diff.
  6. */
  7. class TableDiff
  8. {
  9. /** @var string */
  10. public $name;
  11. /** @var string|false */
  12. public $newName = false;
  13. /**
  14. * All added columns
  15. *
  16. * @var Column[]
  17. */
  18. public $addedColumns;
  19. /**
  20. * All changed columns
  21. *
  22. * @var ColumnDiff[]
  23. */
  24. public $changedColumns = [];
  25. /**
  26. * All removed columns
  27. *
  28. * @var Column[]
  29. */
  30. public $removedColumns = [];
  31. /**
  32. * Columns that are only renamed from key to column instance name.
  33. *
  34. * @var Column[]
  35. */
  36. public $renamedColumns = [];
  37. /**
  38. * All added indexes.
  39. *
  40. * @var Index[]
  41. */
  42. public $addedIndexes = [];
  43. /**
  44. * All changed indexes.
  45. *
  46. * @var Index[]
  47. */
  48. public $changedIndexes = [];
  49. /**
  50. * All removed indexes
  51. *
  52. * @var Index[]
  53. */
  54. public $removedIndexes = [];
  55. /**
  56. * Indexes that are only renamed but are identical otherwise.
  57. *
  58. * @var Index[]
  59. */
  60. public $renamedIndexes = [];
  61. /**
  62. * All added foreign key definitions
  63. *
  64. * @var ForeignKeyConstraint[]
  65. */
  66. public $addedForeignKeys = [];
  67. /**
  68. * All changed foreign keys
  69. *
  70. * @var ForeignKeyConstraint[]
  71. */
  72. public $changedForeignKeys = [];
  73. /**
  74. * All removed foreign keys
  75. *
  76. * @var ForeignKeyConstraint[]|string[]
  77. */
  78. public $removedForeignKeys = [];
  79. /** @var Table|null */
  80. public $fromTable;
  81. /**
  82. * Constructs an TableDiff object.
  83. *
  84. * @param string $tableName
  85. * @param Column[] $addedColumns
  86. * @param ColumnDiff[] $changedColumns
  87. * @param Column[] $removedColumns
  88. * @param Index[] $addedIndexes
  89. * @param Index[] $changedIndexes
  90. * @param Index[] $removedIndexes
  91. */
  92. public function __construct(
  93. $tableName,
  94. $addedColumns = [],
  95. $changedColumns = [],
  96. $removedColumns = [],
  97. $addedIndexes = [],
  98. $changedIndexes = [],
  99. $removedIndexes = [],
  100. ?Table $fromTable = null
  101. ) {
  102. $this->name = $tableName;
  103. $this->addedColumns = $addedColumns;
  104. $this->changedColumns = $changedColumns;
  105. $this->removedColumns = $removedColumns;
  106. $this->addedIndexes = $addedIndexes;
  107. $this->changedIndexes = $changedIndexes;
  108. $this->removedIndexes = $removedIndexes;
  109. $this->fromTable = $fromTable;
  110. }
  111. /**
  112. * @param AbstractPlatform $platform The platform to use for retrieving this table diff's name.
  113. *
  114. * @return Identifier
  115. */
  116. public function getName(AbstractPlatform $platform)
  117. {
  118. return new Identifier(
  119. $this->fromTable instanceof Table ? $this->fromTable->getQuotedName($platform) : $this->name
  120. );
  121. }
  122. /**
  123. * @return Identifier|false
  124. */
  125. public function getNewName()
  126. {
  127. if ($this->newName === false) {
  128. return false;
  129. }
  130. return new Identifier($this->newName);
  131. }
  132. }