TableDiff.php 4.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
<?php
/*
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * This software consists of voluntary contributions made by many individuals
Benjamin Eberlei's avatar
Benjamin Eberlei committed
16
 * and is licensed under the MIT license. For more information, see
17 18 19 20 21
 * <http://www.doctrine-project.org>.
 */

namespace Doctrine\DBAL\Schema;

22 23
use Doctrine\DBAL\Platforms\AbstractPlatform;

24
/**
Benjamin Morel's avatar
Benjamin Morel committed
25
 * Table Diff.
26
 *
Benjamin Morel's avatar
Benjamin Morel committed
27 28 29
 * @link   www.doctrine-project.org
 * @since  2.0
 * @author Benjamin Eberlei <kontakt@beberlei.de>
30 31 32
 */
class TableDiff
{
33 34 35 36 37 38
    /**
     * @var string
     */
    public $name = null;

    /**
Benjamin Morel's avatar
Benjamin Morel committed
39
     * @var string|boolean
40 41 42
     */
    public $newName = false;

43
    /**
Benjamin Morel's avatar
Benjamin Morel committed
44
     * All added fields.
45
     *
Benjamin Morel's avatar
Benjamin Morel committed
46
     * @var \Doctrine\DBAL\Schema\Column[]
47
     */
48
    public $addedColumns;
49 50

    /**
Benjamin Morel's avatar
Benjamin Morel committed
51
     * All changed fields.
52
     *
53
     * @var \Doctrine\DBAL\Schema\ColumnDiff[]
54
     */
55
    public $changedColumns = [];
56 57

    /**
Benjamin Morel's avatar
Benjamin Morel committed
58
     * All removed fields.
59
     *
Benjamin Morel's avatar
Benjamin Morel committed
60
     * @var \Doctrine\DBAL\Schema\Column[]
61
     */
62
    public $removedColumns = [];
63

64 65 66
    /**
     * Columns that are only renamed from key to column instance name.
     *
Benjamin Morel's avatar
Benjamin Morel committed
67
     * @var \Doctrine\DBAL\Schema\Column[]
68
     */
69
    public $renamedColumns = [];
70

71
    /**
Benjamin Morel's avatar
Benjamin Morel committed
72
     * All added indexes.
73
     *
Benjamin Morel's avatar
Benjamin Morel committed
74
     * @var \Doctrine\DBAL\Schema\Index[]
75
     */
76
    public $addedIndexes = [];
77 78

    /**
Benjamin Morel's avatar
Benjamin Morel committed
79
     * All changed indexes.
80
     *
Benjamin Morel's avatar
Benjamin Morel committed
81
     * @var \Doctrine\DBAL\Schema\Index[]
82
     */
83
    public $changedIndexes = [];
84 85 86 87

    /**
     * All removed indexes
     *
Benjamin Morel's avatar
Benjamin Morel committed
88
     * @var \Doctrine\DBAL\Schema\Index[]
89
     */
90
    public $removedIndexes = [];
91 92 93 94 95 96

    /**
     * Indexes that are only renamed but are identical otherwise.
     *
     * @var \Doctrine\DBAL\Schema\Index[]
     */
97
    public $renamedIndexes = [];
98 99 100

    /**
     * All added foreign key definitions
101
     *
Benjamin Morel's avatar
Benjamin Morel committed
102
     * @var \Doctrine\DBAL\Schema\ForeignKeyConstraint[]
103
     */
104
    public $addedForeignKeys = [];
105 106 107 108

    /**
     * All changed foreign keys
     *
Benjamin Morel's avatar
Benjamin Morel committed
109
     * @var \Doctrine\DBAL\Schema\ForeignKeyConstraint[]
110
     */
111
    public $changedForeignKeys = [];
112 113 114 115

    /**
     * All removed foreign keys
     *
Benjamin Morel's avatar
Benjamin Morel committed
116
     * @var \Doctrine\DBAL\Schema\ForeignKeyConstraint[]
117
     */
118
    public $removedForeignKeys = [];
119

120
    /**
Benjamin Morel's avatar
Benjamin Morel committed
121
     * @var \Doctrine\DBAL\Schema\Table
122 123 124
     */
    public $fromTable;

125 126 127
    /**
     * Constructs an TableDiff object.
     *
Steve Müller's avatar
Steve Müller committed
128 129 130 131 132 133 134 135
     * @param string                             $tableName
     * @param \Doctrine\DBAL\Schema\Column[]     $addedColumns
     * @param \Doctrine\DBAL\Schema\ColumnDiff[] $changedColumns
     * @param \Doctrine\DBAL\Schema\Column[]     $removedColumns
     * @param \Doctrine\DBAL\Schema\Index[]      $addedIndexes
     * @param \Doctrine\DBAL\Schema\Index[]      $changedIndexes
     * @param \Doctrine\DBAL\Schema\Index[]      $removedIndexes
     * @param \Doctrine\DBAL\Schema\Table|null   $fromTable
136
     */
137 138 139
    public function __construct($tableName, $addedColumns = [],
        $changedColumns = [], $removedColumns = [], $addedIndexes = [],
        $changedIndexes = [], $removedIndexes = [], Table $fromTable = null)
140
    {
141
        $this->name = $tableName;
142 143 144
        $this->addedColumns = $addedColumns;
        $this->changedColumns = $changedColumns;
        $this->removedColumns = $removedColumns;
145 146 147
        $this->addedIndexes = $addedIndexes;
        $this->changedIndexes = $changedIndexes;
        $this->removedIndexes = $removedIndexes;
148
        $this->fromTable = $fromTable;
149
    }
150

151
    /**
152 153
     * @param AbstractPlatform $platform The platform to use for retrieving this table diff's name.
     *
154 155
     * @return \Doctrine\DBAL\Schema\Identifier
     */
156
    public function getName(AbstractPlatform $platform)
157
    {
158 159 160
        return new Identifier(
            $this->fromTable instanceof Table ? $this->fromTable->getQuotedName($platform) : $this->name
        );
161 162
    }

163
    /**
164
     * @return \Doctrine\DBAL\Schema\Identifier|boolean
165
     */
166 167
    public function getNewName()
    {
168
        return $this->newName ? new Identifier($this->newName) : $this->newName;
169
    }
170
}