fridge-project/dbal — pull request #18 by egeloen (2012-09-08 18:30:35+00:00)
Title: [WIP][Schema] Add schema comparison

The aim of this PR is to be able to compare two schemas, two tables or two columns & then upgrade the database according to the comparison.

Example (schema):

``` php
getSchemaManager()->getSchema();
$newSchema = clone $oldSchema;

$newSchema->dropTable('foo');

$schemaComparator = new SchemaComparator();
$schemaDiff = $schemaComparator->compare($oldSchema, $newSchema);

$connection->getSchemaManager()->alterSchema($schemaDiff);
```

Example (table):

``` php
getSchemaManager()->getTable('foo');
$newTable = clone $oldTable;

$newTable->dropColumn('foo');

$tableComparator = new TableComparator();
$tableDiff = $tableComparator->compare($oldTable, $newTable);

$connection->getSchemaManager()->alterTable($tableDiff);
```

Example (column):

``` php
getSchemaManager()->getTable('foo')->getColumn('foo');
$newColumn = clone $oldColumn;

$newColumn->setNotNull(true);

$columnComparator = new ColumnComparator();
$columnDiff = $tableComparator->compare($oldColumn, $newColumn);

$connection->getSchemaManager()->alterColumn($columnDiff);
```

if you only want to get the queries to alter schemas, you can do:

Example (schema):

``` php
getPlatform());
$sqlCollector->collect($schemaDiff);

$queries = $sqlCollector->getQueries();
```

Example (table):

``` php
getPlatform());
$sqlCollector->collect($tableDiff);

$queries = $sqlCollector->getQueries();
```

Additionally, two more SQL collectors have been added to deal with create/drop tables.