Skip to content

Commit

Permalink
Added migration tests against real database instances with reverse en…
Browse files Browse the repository at this point in the history
…gineered prove.
  • Loading branch information
Marc J. Schmidt committed Aug 18, 2013
1 parent 6f6570a commit 484bcc8
Show file tree
Hide file tree
Showing 10 changed files with 906 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,7 @@ tests/Fixtures/reverse/mysql/runtime-conf.xml

tests/Fixtures/reverse/pgsql/build/
tests/Fixtures/reverse/pgsql/runtime-conf.xml

tests/Fixtures/migration/build/
tests/Fixtures/migration/build.properties
tests/Fixtures/migration/runtime-conf.xml
3 changes: 2 additions & 1 deletion src/Propel/Generator/Command/TestPrepareCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class TestPrepareCommand extends AbstractCommand
'reverse/mysql' => array('reverse-bookstore'),
'reverse/pgsql' => array('reverse-bookstore'),
'schemas' => array('bookstore-schemas'),
'migration' => array('migration'),
);

/**
Expand Down Expand Up @@ -136,7 +137,7 @@ protected function buildFixtures($fixturesDir, $connections, InputInterface $inp
}
}

if (0 < count((array) $this->getSchemas('.')) || false === strstr($fixturesDir, 'reverse')) {
if (0 < count($this->getSchemas('.'))) {
$in = new ArrayInput(array(
'command' => 'sql:build',
'--input-dir' => '.',
Expand Down
32 changes: 32 additions & 0 deletions tests/Fixtures/migration/build.properties.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# $Id$
#
# This is a project-specific build.properties file. The properties
# in this file override anything set in Propel's top-level build.properties
# file when *this* project is being built.
#
# See top-level build.properties-sample for explanation of configuration
# options.
#
# Because this file is included before the top-level build.properties file,
# you cannot refer to any properties set therein.

propel.project = migration
propel.database = ##DATABASE_VENDOR##
propel.database.url = ##DATABASE_URL##
propel.mysql.tableType = InnoDB
propel.disableIdentifierQuoting = true
propel.schema.autoPrefix = false

# For MySQL or Oracle, you also need to specify username & password
propel.database.user = ##DATABASE_USER##
propel.database.password = ##DATABASE_PASSWORD##

# Note that if you do not wish to specify the database (e.g. if you
# are using multiple databases) you can use the @DB@ token which
# will be replaced with a database at runtime.
# E.g.: propel.database.url = sqlite://localhost/./test/@DB@.db
# This will work for the datadump and the insert-sql tasks.

# propel.database.createUrl = (doesn't apply for SQLite, since db is auto-created)

propel.targetPackage = migration
25 changes: 25 additions & 0 deletions tests/Fixtures/migration/runtime-conf.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<config>
<propel>
<datasources default="migration">
<datasource id="migration">
<adapter>##DATABASE_VENDOR##</adapter>
<connection>
<classname>\Propel\Runtime\Connection\DebugPDO</classname>
<dsn>##DATABASE_URL##</dsn>
<user>##DATABASE_USER##</user>
<password>##DATABASE_PASSWORD##</password>
<options>
<option id="ATTR_PERSISTENT">false</option>
</options>
<attributes>
<option id="ATTR_EMULATE_PREPARES">true</option>
</attributes>
<settings>
<setting id="charset">utf8</setting>
</settings>
</connection>
</datasource>
</datasources>
</propel>
</config>
202 changes: 202 additions & 0 deletions tests/Propel/Tests/Generator/Migration/BaseTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
<?php


namespace Propel\Tests\Generator\Migration;

class BaseTest extends MigrationTestCase {

public function testColumnRequireChange() {
$originXml = '
<database>
<table name="migration_test_1">
<column name="id" type="integer" primaryKey="true" autoIncrement="true" />
<column name="title" required="true" />
</table>
</database>
';

$targetXml = '
<database>
<table name="migration_test_1">
<column name="id" type="integer" primaryKey="true" autoIncrement="true" />
<column name="title" />
</table>
</database>
';

$this->migrateAndTest($originXml, $targetXml);
}

public function testColumnTypeChangeSimple() {
$originXml = '
<database>
<table name="migration_test_2">
<column name="field1" type="VARCHAR" />
<column name="field2" type="INTEGER" />
<column name="field3" type="BOOLEAN" />
</table>
</database>
';

$targetXml = '
<database>
<table name="migration_test_2">
<column name="field1" type="INTEGER" />
<column name="field2" type="VARCHAR" />
<column name="field3" type="VARCHAR" />
</table>
</database>
';
$this->migrateAndTest($originXml, $targetXml);
}

public function testColumnTypeChangeComplex() {
$originXml = '
<database>
<table name="migration_test_3">
<column name="field1" type="CHAR" />
<column name="field2" type="LONGVARCHAR" />
<column name="field3" type="CLOB" />
<column name="field4" type="NUMERIC" />
<column name="field5" type="DECIMAL" />
<column name="field6" type="TINYINT" />
<column name="field7" type="SMALLINT" />
</table>
</database>
';

$targetXml = '
<database>
<table name="migration_test_3">
<column name="field1" type="LONGVARCHAR" />
<column name="field4" type="DECIMAL" />
<column name="field5" type="TINYINT" />
<column name="field6" type="SMALLINT" />
<column name="field7" type="NUMERIC" />
</table>
</database>
';
$this->migrateAndTest($originXml, $targetXml);
}

public function testColumnTypeChangeMoreComplex() {
$originXml = '
<database>
<table name="migration_test_3">
<column name="field1" type="CHAR" size="5" />
<column name="field2" type="INTEGER" size="6" />
<column name="field3" type="BIGINT" />
<column name="field4" type="REAL" />
<column name="field5" type="FLOAT" />
<column name="field6" type="DOUBLE" />
<column name="field7" type="BINARY" />
<column name="field8" type="VARBINARY" />
<column name="field9" type="LONGVARBINARY" />
<column name="field10" type="BLOB" />
<column name="field11" type="DATE" />
<column name="field12" type="TIME" />
<column name="field13" type="TIMESTAMP" />
<column name="field14" type="ENUM" />
</table>
</database>
';

$targetXml = '
<database>
<table name="migration_test_3">
<column name="field1" type="CHAR" size="5" />
<column name="field2" type="INTEGER" size="12" />
<column name="field3" type="REAL" />
<column name="field4" type="FLOAT" />
<column name="field5" type="DOUBLE" />
<column name="field6" type="BIGINT" />
<column name="field7" type="VARBINARY" />
<column name="field8" type="LONGVARBINARY" />
<column name="field9" type="BLOB" />
<column name="field10" type="BINARY" />
<column name="field11" type="TIME" />
<column name="field12" type="TIMESTAMP" />
<column name="field13" type="DATE" />
<column name="field14" type="VARCHAR" size="200" />
</table>
</database>
';
$this->migrateAndTest($originXml, $targetXml);
}

/**
* @group test
*/
public function testColumnChangePrimaryKey() {
$originXml = '
<database>
<table name="migration_test_5">
<column name="id" type="integer" primaryKey="true" autoIncrement="true" />
<column name="title" required="true" />
</table>
</database>
';

$targetXml = '
<database>
<table name="migration_test_5">
<column name="id" type="integer" />
<column name="title" />
</table>
</database>
';

$target2Xml = '
<database>
<table name="migration_test_5">
<column name="id" type="integer" primaryKey="true" />
<column name="title" />
</table>
</database>
';

$target3Xml = '
<database>
<table name="migration_test_5">
<column name="id" type="integer" primaryKey="true" autoIncrement="true" />
<column name="title" />
</table>
</database>
';

$target4Xml = '
<database>
<table name="migration_test_5">
<column name="id" type="integer" primaryKey="true" />
<column name="title" />
</table>
</database>
';

$target5Xml = '
<database>
<table name="migration_test_5">
<column name="id" type="varchar" size="200" primaryKey="true" />
<column name="title" required="true" type="integer" />
</table>
</database>
';
$this->applyXmlAndTest($originXml);
$this->applyXmlAndTest($targetXml);
$this->applyXmlAndTest($target2Xml);
$this->applyXmlAndTest($target3Xml);
$this->applyXmlAndTest($target4Xml);
$this->applyXmlAndTest($target5Xml);
}

}
Loading

0 comments on commit 484bcc8

Please sign in to comment.