Skip to content

Commit 82ab9ba

Browse files
authored
Add files via upload
1 parent 8f6860f commit 82ab9ba

File tree

8 files changed

+124
-14
lines changed

8 files changed

+124
-14
lines changed

src/Model/ChangedTable.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
namespace Camcima\MySqlDiff\Model;
44

5+
/**
6+
* Class ChangedTable
7+
*
8+
* @package Camcima\MySqlDiff\Model
9+
*/
510
class ChangedTable
611
{
712
/**
@@ -367,6 +372,26 @@ public function generateAlterScript()
367372
$tableChanges[] = sprintf('ADD %s', $newForeignKey->generateCreationScript());
368373
}
369374

375+
if ($this->fromTable->getEngine() !== $this->toTable->getEngine()) {
376+
$tableChanges[] = sprintf('ENGINE=%s', $this->toTable->getEngine());
377+
}
378+
379+
if ($this->fromTable->getDefaultCharset() !== $this->toTable->getDefaultCharset()) {
380+
$tableChanges[] = sprintf('DEFAULT CHARSET=%s', $this->toTable->getDefaultCharset());
381+
}
382+
383+
if ($this->fromTable->getRowFormat() !== $this->toTable->getRowFormat()) {
384+
$tableChanges[] = sprintf('ROW_FORMAT=%s', $this->toTable->getRowFormat());
385+
}
386+
387+
if ($this->fromTable->getKeyBlockSize() !== $this->toTable->getKeyBlockSize()) {
388+
$tableChanges[] = sprintf('KEY_BLOCK_SIZE=%s', $this->toTable->getKeyBlockSize());
389+
}
390+
391+
if ($this->fromTable->getComment() !== $this->toTable->getComment()) {
392+
$tableChanges[] = sprintf('COMMENT=\'%s\'', str_replace('\'','\'\'', $this->toTable->getComment()));
393+
}
394+
370395
$alterScript = sprintf('ALTER TABLE `%s`%s %s;', $this->getName(), PHP_EOL, implode(',' . PHP_EOL . ' ', $tableChanges));
371396

372397
return $alterScript;

src/Model/Column.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
namespace Camcima\MySqlDiff\Model;
44

5+
/**
6+
* Class Column
7+
*
8+
* @package Camcima\MySqlDiff\Model
9+
*/
510
class Column
611
{
712
/**
@@ -420,7 +425,7 @@ public function generateCreationScript()
420425

421426
if (!$this->nullable) {
422427
$columnOptions[] = 'NOT NULL';
423-
} elseif ($this->columnType == 'timestamp') {
428+
} elseif ($this->columnType === 'timestamp') {
424429
$columnOptions[] = 'NULL';
425430
}
426431

src/Model/Database.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
namespace Camcima\MySqlDiff\Model;
44

5+
/**
6+
* Class Database
7+
*
8+
* @package Camcima\MySqlDiff\Model
9+
*/
510
class Database
611
{
712
/**
@@ -27,8 +32,8 @@ public function addTable(Table $table)
2732

2833
/**
2934
* @param string $tableName
30-
*
3135
* @return Table
36+
* @throws \RuntimeException
3237
*/
3338
public function getTableByName($tableName)
3439
{

src/Model/DatabaseDiff.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
namespace Camcima\MySqlDiff\Model;
44

5+
/**
6+
* Class DatabaseDiff
7+
*
8+
* @package Camcima\MySqlDiff\Model
9+
*/
510
class DatabaseDiff
611
{
712
/**

src/Model/ForeignKey.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
namespace Camcima\MySqlDiff\Model;
44

5+
/**
6+
* Class ForeignKey
7+
*
8+
* @package Camcima\MySqlDiff\Model
9+
*/
510
class ForeignKey
611
{
712
/**

src/Model/Index.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
namespace Camcima\MySqlDiff\Model;
44

5+
/**
6+
* Class Index
7+
*
8+
* @package Camcima\MySqlDiff\Model
9+
*/
510
class Index
611
{
712
/**
@@ -72,7 +77,7 @@ public function setParentTable($parentTable)
7277
}
7378

7479
/**
75-
* @return Column[]
80+
* @return IndexColumn[]
7681
*/
7782
public function getIndexColumns()
7883
{
@@ -97,13 +102,13 @@ public function addIndexColumn(IndexColumn $indexColumn)
97102

98103
/**
99104
* @param $columnName
100-
*
101105
* @return IndexColumn
106+
* @throws \RuntimeException
102107
*/
103108
public function getIndexColumnByColumnName($columnName)
104109
{
105110
foreach ($this->indexColumns as $indexColumn) {
106-
if ($indexColumn->getColumn()->getName() == $columnName) {
111+
if ($indexColumn->getColumn()->getName() === $columnName) {
107112
return $indexColumn;
108113
}
109114
}

src/Model/IndexColumn.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
namespace Camcima\MySqlDiff\Model;
44

5+
/**
6+
* Class IndexColumn
7+
*
8+
* @package Camcima\MySqlDiff\Model
9+
*/
510
class IndexColumn
611
{
712
/**

src/Model/Table.php

Lines changed: 64 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
namespace Camcima\MySqlDiff\Model;
44

5+
/**
6+
* Class Table
7+
*
8+
* @package Camcima\MySqlDiff\Model
9+
*/
510
class Table
611
{
712
/**
@@ -49,6 +54,16 @@ class Table
4954
*/
5055
private $engine;
5156

57+
/**
58+
* @var string
59+
*/
60+
private $rowFormat;
61+
62+
/**
63+
* @var string
64+
*/
65+
private $keyBlockSize;
66+
5267
/**
5368
* @var int
5469
*/
@@ -155,32 +170,32 @@ public function addColumn(Column $column)
155170

156171
/**
157172
* @param string $columnName
158-
*
159173
* @return Column
174+
* @throws \RuntimeException
160175
*/
161176
public function getColumnByName($columnName)
162177
{
163178
if (!isset($this->columns[$columnName])) {
164-
throw new \RuntimeException(sprintf('Column "%s" not found in table ""!', $columnName, $this->name));
179+
throw new \RuntimeException(sprintf('Column "%s" not found in table "%s"!', $columnName, $this->name));
165180
}
166181

167182
return $this->columns[$columnName];
168183
}
169184

170185
/**
171186
* @param int $columnOrder
172-
*
173187
* @return Column
188+
* @throws \RuntimeException
174189
*/
175190
public function getColumnByOrder($columnOrder)
176191
{
177192
foreach ($this->columns as $column) {
178-
if ($column->getOrder() == $columnOrder) {
193+
if ($column->getOrder() === $columnOrder) {
179194
return $column;
180195
}
181196
}
182197

183-
throw new \RuntimeException(sprintf('Column order "%s" not found in table ""!', $columnOrder, $this->name));
198+
throw new \RuntimeException(sprintf('Column order "%s" not found in table "%s"!', $columnOrder, $this->name));
184199
}
185200

186201
/**
@@ -228,13 +243,13 @@ public function addForeignKey(ForeignKey $foreignKey)
228243

229244
/**
230245
* @param string $foreignKeyName
231-
*
232246
* @return ForeignKey
247+
* @throws \RuntimeException
233248
*/
234249
public function getForeignKeyByName($foreignKeyName)
235250
{
236251
if (!isset($this->foreignKeys[$foreignKeyName])) {
237-
throw new \RuntimeException(sprintf('Foreign key "%s" not found in table ""!', $foreignKeyName, $this->name));
252+
throw new \RuntimeException(sprintf('Foreign key "%s" not found in table "%s"!', $foreignKeyName, $this->name));
238253
}
239254

240255
return $this->foreignKeys[$foreignKeyName];
@@ -269,13 +284,13 @@ public function addIndex(Index $index)
269284

270285
/**
271286
* @param string $indexName
272-
*
273287
* @return Index
288+
* @throws \RuntimeException
274289
*/
275290
public function getIndexByName($indexName)
276291
{
277292
if (!isset($this->indexes[$indexName])) {
278-
throw new \RuntimeException(sprintf('Index "%s" not found in table ""!', $indexName, $this->name));
293+
throw new \RuntimeException(sprintf('Index "%s" not found in table "%s"!', $indexName, $this->name));
279294
}
280295

281296
return $this->indexes[$indexName];
@@ -307,6 +322,38 @@ public function setEngine($engine)
307322
$this->engine = $engine;
308323
}
309324

325+
/**
326+
* @return string
327+
*/
328+
public function getRowFormat()
329+
{
330+
return $this->rowFormat;
331+
}
332+
333+
/**
334+
* @param string $rowFormat
335+
*/
336+
public function setRowFormat($rowFormat)
337+
{
338+
$this->rowFormat = $rowFormat;
339+
}
340+
341+
/**
342+
* @return string
343+
*/
344+
public function getKeyBlockSize()
345+
{
346+
return $this->keyBlockSize;
347+
}
348+
349+
/**
350+
* @param string $keyBlockSize
351+
*/
352+
public function setKeyBlockSize($keyBlockSize)
353+
{
354+
$this->keyBlockSize = $keyBlockSize;
355+
}
356+
310357
/**
311358
* @return int
312359
*/
@@ -436,6 +483,14 @@ public function generateCreationScript($ignoreAutoIncrement = false, $sortKeys =
436483
$tableOptions[] = sprintf('DEFAULT CHARSET=%s', $this->defaultCharset);
437484
}
438485

486+
if ($this->rowFormat) {
487+
$tableOptions[] = sprintf('ROW_FORMAT=%s', $this->rowFormat);
488+
}
489+
490+
if ($this->keyBlockSize) {
491+
$tableOptions[] = sprintf('KEY_BLOCK_SIZE=%s', $this->keyBlockSize);
492+
}
493+
439494
if ($this->comment) {
440495
$tableOptions[] = sprintf('COMMENT=\'%s\'', str_replace('\'','\'\'', $this->comment));
441496
}

0 commit comments

Comments
 (0)