Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

WIP: Sqlite migration and foreignKey support #612

Closed
wants to merge 2 commits into from

3 participants

@marcj
Owner

Just need the PR id in another ticket. Maybe it's done in a few days.

marcj added some commits
@marcj marcj Added SQLite migration and ForeignKey support to the platform layer. WIP 34b9319
@marcj marcj Added buildtime-conf.xml for the bookstore fixure, where we use now '…
…sqlite' in the 'bookstore' database section. (for testing purposes)

This is in WIP. Next step is that travis-ci uses several environments where we test sqlite/pgsql/mysql, not as currently where the most tests are against mysql.
This generated a couple of issues since some tests got the ($this->con) connection from the wrong database. Also fixed a bunch of errors with the new SQLite stuff.
52af705
@staabm staabm commented on the diff
generator/lib/model/Table.php
@@ -1582,6 +1582,18 @@ public function getForeignKeys()
}
/**
+ * Removes a foreign key.
+ *
+ * @param ForeignKey $fk
+ */
+ public function removeForeignKey(ForeignKey $fk){
+ $idx = array_search($fk, $this->foreignKeys);
@staabm Collaborator
staabm added a note

use isset instead because its a lot faster

@marcj Owner
marcj added a note

It's about removing the FK, not checking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@staabm staabm commented on the diff
generator/lib/platform/SqlitePlatform.php
@@ -21,6 +21,22 @@ class SqlitePlatform extends DefaultPlatform
{
/**
+ * If we should generate FOREIGN KEY statements.
+ * This is since SQLite version 3.6.19 possible.
+ *
+ * @var bool
+ */
+ private $foreignKeySupport = true;
+
+ /**
+ * If we should alter the table through creating a temporarily crated table,
@staabm Collaborator
staabm added a note

in which situation is this workaround required?

@marcj Owner
marcj added a note

sqlite.org/lang_altertable.html

@staabm Collaborator
staabm added a note

this should be documented in the code...

@marcj Owner
marcj added a note

It's a WIP. It will be included in the build properties section in a comment. This limitation is very known under SQLite developers, so no need to highlight a apparent fact in the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@staabm staabm commented on the diff
generator/lib/platform/SqlitePlatform.php
((86 lines not shown))
+ }
+
+ }
+
+ /**
+ * Creates a temporarily created table with the new schema,
+ * moves all items into it and drops the origin as well as renames the temp table to the origin then.
+ *
+ * @param PropelTableDiff $tableDiff
+ * @return string
+ */
+ public function getMigrationTableDDL(PropelTableDiff $tableDiff){
+
+ $pattern = "
+%s;
+INSERT INTO %s (%s)
@staabm Collaborator
staabm added a note

shouldn't you use a prepared statement?

@marcj Owner
marcj added a note

No.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@staabm staabm commented on the diff
generator/lib/platform/SqlitePlatform.php
@@ -90,26 +265,130 @@ public function getAddTableDDL(Table $table)
);
}
+ /**
+ * Unfortunately, SQLite does not support composite pks where one is AUTOINCREMENT,
+ * so we have so flag both as NOT NULL and create a UNIQUE constraint.
@staabm Collaborator
staabm added a note

typo: so -> to

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@staabm staabm commented on the diff
generator/lib/platform/SqlitePlatform.php
((13 lines not shown))
+ foreach ($pks as $pk){
+ //no pk can be NULL, as usual
+ $pk->setNotNull(true);
+ //in SQLite the column with the AUTOINCREMENT MUST be a primary key, too.
+ if (!$pk->isAutoIncrement()){
+ //for all other sub keys we remove it, since we create a UNIQUE constraint over all primary keys.
+ $pk->setPrimaryKey(false);
+ }
+ }
+
+ //search if there is already a UNIQUE constraint over the primary keys
+ $pkUniqueExist = false;
+ foreach ($table->getUnices() as $unique){
+ $allPk = false;
+ foreach ($unique->getColumns() as $columnName){
+ $allPk &= $table->getColumn($columnName)->isPrimaryKey();
@staabm Collaborator
staabm added a note

why do you assign by ref?

@staabm Collaborator
staabm added a note

I think you meant $allPk = $table->getColumn($columnName)->isPrimaryKey() && $allPk;, but than you need to init $allPk with true

@marcj Owner
marcj added a note

It's a binary operation, not a ref assign.

@staabm Collaborator
staabm added a note

so you should write it in the long form to improve readability.

@marcj Owner
marcj added a note

I really appreciate your work, but please, don't discuss a WIP PR yet. If your opinion is that combined operators are not readable to you, than that's totally OK to me, but please don't declare it as 'you should not do that'.

@staabm Collaborator
staabm added a note

sure. sorry for that, and don't do it ;-).

@marcj Owner
marcj added a note

What?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@staabm
Collaborator

sorry for the early feedback, I just recognized its an WIP...

@ssokolow

Has there been any progress on this? I have a project which I'd like to move to a fatter model but whether I wait and switch to Propel or just jerry rig something on top of my existing solution will depend on how likely this is to be ready within the next few months.

@staabm
Collaborator

You are welcome to provide the remaing changes for this PR. I don't know if @marcj will have time for this

@ssokolow

Given how little time I have, the "within the next few months" may be a limit imposed by when I have time to migrate to Propel or even just make changes to my existing database code.

As much as I'd love to help, there's no way I have time to grow familiar enough with the Propel codebase to contribute a patch in the near future.

However, in the longer term (say... July, maybe?), it's a possibility if you or someone else familiar with the project can point me to a crash course in how the Propel codebase is laid out, how comprehensive the unit tests are, what standards need to be met for this patch to get accepted (including what extra unit tests I might have to write), etc.

@staabm
Collaborator

Sure. Just give us a ping when you have time

@marcj
Owner

I'll close this PR soon and will integrate it in Propel2.

@ssokolow

@marcj

In three days, it'll have been two months since you said "soon". I'd like to start using Propel2 on an SQLite-backed project before my vacation ends.

Did you forget or is there some hold-up I might be able to handle for you?

@marcj
Owner

Unfortunately, I'm not able to work on this issue, since I'm working on another big project for the next weeks. But I guess I need this PR as well in that project (but in Propel2). However, this PR is 'nearly' done, so it shouldn't be much work to complete it.

@marcj
Owner

I've implemented those features in Propel2: propelorm/Propel2#433

@marcj marcj closed this
@marcj marcj referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 18, 2013
  1. @marcj
  2. @marcj

    Added buildtime-conf.xml for the bookstore fixure, where we use now '…

    marcj authored
    …sqlite' in the 'bookstore' database section. (for testing purposes)
    
    This is in WIP. Next step is that travis-ci uses several environments where we test sqlite/pgsql/mysql, not as currently where the most tests are against mysql.
    This generated a couple of issues since some tests got the ($this->con) connection from the wrong database. Also fixed a bunch of errors with the new SQLite stuff.
This page is out of date. Refresh to see the latest.
Showing with 619 additions and 246 deletions.
  1. +2 −0  generator/lib/model/ForeignKey.php
  2. +14 −2 generator/lib/model/Table.php
  3. +92 −2 generator/lib/model/diff/PropelTableDiff.php
  4. +302 −18 generator/lib/platform/SqlitePlatform.php
  5. +2 −2 test/fixtures/bookstore/build.properties
  6. +7 −34 test/fixtures/bookstore/runtime-conf.xml
  7. +58 −56 test/testsuite/generator/behavior/aggregate_column/AggregateColumnBehaviorTest.php
  8. +24 −10 test/testsuite/generator/behavior/i18n/I18nBehaviorTest.php
  9. +17 −17 test/testsuite/generator/behavior/nestedset/NestedSetBehaviorObjectBuilderModifierTest.php
  10. +14 −14 test/testsuite/generator/behavior/nestedset/NestedSetBehaviorObjectBuilderModifierWithScopeTest.php
  11. +28 −27 test/testsuite/generator/behavior/versionable/VersionableBehaviorTest.php
  12. +2 −2 test/testsuite/generator/builder/om/GeneratedPeerDoSelectTest.php
  13. +22 −20 test/testsuite/generator/builder/om/QueryBuilderTest.php
  14. +12 −12 test/testsuite/generator/platform/PlatformTestProvider.php
  15. +21 −28 test/testsuite/generator/platform/SqlitePlatformTest.php
  16. +1 −1  test/testsuite/generator/util/PropelQuickBuilderTest.php
  17. +1 −1  test/testsuite/runtime/collection/PropelOnDemandCollectionTest.php
View
2  generator/lib/model/ForeignKey.php
@@ -283,6 +283,8 @@ public function setTable(Table $parent)
/**
* Get the parent Table of the foreign key
+ *
+ * @return Table
*/
public function getTable()
{
View
16 generator/lib/model/Table.php
@@ -1582,6 +1582,18 @@ public function getForeignKeys()
}
/**
+ * Removes a foreign key.
+ *
+ * @param ForeignKey $fk
+ */
+ public function removeForeignKey(ForeignKey $fk){
+ $idx = array_search($fk, $this->foreignKeys);
@staabm Collaborator
staabm added a note

use isset instead because its a lot faster

@marcj Owner
marcj added a note

It's about removing the FK, not checking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ if ($idx !== false){
+ unset($this->foreignKeys[$idx]);
+ }
+ }
+
+ /**
* Returns a Collection of parameters relevant for the chosen
* id generation method.
*/
@@ -1601,7 +1613,7 @@ public function getIndices()
/**
* Returns an Array containing all the UKs in the table
- * @return array Unique[]
+ * @return Unique[]
*/
public function getUnices()
{
@@ -1878,7 +1890,7 @@ public function appendXml(DOMNode $node)
* Returns the collection of Columns which make up the single primary
* key for this table.
*
- * @return array Column[] A list of the primary key parts.
+ * @return Column[] A list of the primary key parts.
*/
public function getPrimaryKey()
{
View
94 generator/lib/model/diff/PropelTableDiff.php
@@ -114,7 +114,7 @@ public function removeAddedColumn($columnName)
/**
* Getter for the addedColumns property
*
- * @return array
+ * @return Column[]
*/
public function getAddedColumns()
{
@@ -534,7 +534,7 @@ public function addRemovedFk($fkName, ForeignKey $removedFk)
*/
public function removeRemovedFk($fkName)
{
- unset($this->removedFks[$columnName]);
+ unset($this->removedFks[$fkName]);
}
/**
@@ -579,6 +579,96 @@ public function getModifiedFks()
return $this->modifiedFks;
}
+
+ /**
+ * @return bool
+ */
+ public function hasModifiedFks()
+ {
+ return !!$this->modifiedFks;
+ }
+
+ /**
+ * @return bool
+ */
+ public function hasModifiedIndices()
+ {
+ return !!$this->modifiedIndices;
+ }
+
+ /**
+ * @return bool
+ */
+ public function hasModifiedColumns()
+ {
+ return !!$this->modifiedColumns;
+ }
+
+ /**
+ * @return bool
+ */
+ public function hasRemovedFks()
+ {
+ return !!$this->modifiedColumns;
+ }
+
+ /**
+ * @return bool
+ */
+ public function hasRemovedIndices()
+ {
+ return !!$this->removedIndices;
+ }
+
+ /**
+ * @return bool
+ */
+ public function hasRenamedColumns()
+ {
+ return !!$this->renamedColumns;
+ }
+
+ /**
+ * @return bool
+ */
+ public function hasRemovedColumns()
+ {
+ return !!$this->removedColumns;
+ }
+
+ /**
+ * @return bool
+ */
+ public function hasAddedColumns()
+ {
+ return !!$this->addedColumns;
+ }
+
+ /**
+ * @return bool
+ */
+ public function hasAddedIndices()
+ {
+ return !!$this->addedIndices;
+ }
+
+ /**
+ * @return bool
+ */
+ public function hasAddedFks()
+ {
+ return !!$this->addedFks;
+ }
+
+ /**
+ * @return bool
+ */
+ public function hasAddedPkColumns()
+ {
+ return !!$this->addedPkColumns;
+ }
+
+
/**
* Get the reverse diff for this diff
*
View
320 generator/lib/platform/SqlitePlatform.php
@@ -21,6 +21,22 @@ class SqlitePlatform extends DefaultPlatform
{
/**
+ * If we should generate FOREIGN KEY statements.
+ * This is since SQLite version 3.6.19 possible.
+ *
+ * @var bool
+ */
+ private $foreignKeySupport = true;
+
+ /**
+ * If we should alter the table through creating a temporarily crated table,
@staabm Collaborator
staabm added a note

in which situation is this workaround required?

@marcj Owner
marcj added a note

sqlite.org/lang_altertable.html

@staabm Collaborator
staabm added a note

this should be documented in the code...

@marcj Owner
marcj added a note

It's a WIP. It will be included in the build properties section in a comment. This limitation is very known under SQLite developers, so no need to highlight a apparent fact in the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ * moving all item to the new one and finally rename the temp table.
+ *
+ * @var bool
+ */
+ private $tableAlteringWorkaround = true;
+
+ /**
* Initializes db specific domain mapping.
*/
protected function initialize()
@@ -44,18 +60,171 @@ protected function initialize()
*/
public function getAutoIncrement()
{
- return "PRIMARY KEY";
+ return "PRIMARY KEY AUTOINCREMENT";
}
+ /**
+ * {@inheritdoc}
+ */
public function getMaxColumnNameLength()
{
return 1024;
}
+
+ /**
+ * {@inheritdoc}
+ */
+ public function setGeneratorConfig(GeneratorConfigInterface $generatorConfig)
+ {
+ if ($foreignKeySupport = $generatorConfig->getBuildProperty('sqliteForeignkey')) {
+ $this->foreignKeySupport = !!$foreignKeySupport;
+ }
+ if ($tableAlteringWorkaround = $generatorConfig->getBuildProperty('sqliteTableAlteringWorkaround')) {
+ $this->tableAlteringWorkaround = !!$tableAlteringWorkaround;
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getModifyTableDDL(PropelTableDiff $tableDiff)
+ {
+
+ $this->checkCompositePk($tableDiff->getToTable());
+
+ $changedNotEditableThroughDirectDDL = $this->tableAlteringWorkaround && (false
+ || $tableDiff->hasModifiedFks()
+ || $tableDiff->hasModifiedIndices()
+ || $tableDiff->hasModifiedColumns()
+ || $tableDiff->hasRenamedColumns()
+
+ || $tableDiff->hasRemovedFks()
+ || $tableDiff->hasRemovedIndices()
+ || $tableDiff->hasRemovedColumns()
+
+ || $tableDiff->hasAddedIndices()
+ || $tableDiff->hasAddedFks()
+ || $tableDiff->hasAddedPkColumns()
+ );
+
+ if ($this->tableAlteringWorkaround && !$changedNotEditableThroughDirectDDL && $tableDiff->hasAddedColumns()){
+
+ $addedCols = $tableDiff->getAddedColumns();
+ foreach ($addedCols as $column){
+
+ $sqlChangeNotSupported = false
+
+ //The column may not have a PRIMARY KEY or UNIQUE constraint.
+ || $column->isPrimaryKey()
+ || $column->isUnique()
+
+ //The column may not have a default value of CURRENT_TIME, CURRENT_DATE, CURRENT_TIMESTAMP,
+ //or an expression in parentheses.
+ || false !== array_search(
+ $column->getDefaultValue(), array('CURRENT_TIME', 'CURRENT_DATE', 'CURRENT_TIMESTAMP'))
+ || substr(trim($column->getDefaultValue()), 0, 1) == '('
+
+ //If a NOT NULL constraint is specified, then the column must have a default value other than NULL.
+ || ($column->isNotNull() && $column->getDefaultValue() == 'NULL')
+ ;
+
+ if ($sqlChangeNotSupported){
+ $changedNotEditableThroughDirectDDL = true;
+ break;
+ }
+
+ }
+ }
+
+ if ($changedNotEditableThroughDirectDDL){
+ return $this->getMigrationTableDDL($tableDiff);
+ } else {
+ return parent::getModifyTableDDL($tableDiff);
+ }
+
+ }
+
+ /**
+ * Creates a temporarily created table with the new schema,
+ * moves all items into it and drops the origin as well as renames the temp table to the origin then.
+ *
+ * @param PropelTableDiff $tableDiff
+ * @return string
+ */
+ public function getMigrationTableDDL(PropelTableDiff $tableDiff){
+
+ $pattern = "
+%s;
+INSERT INTO %s (%s)
@staabm Collaborator
staabm added a note

shouldn't you use a prepared statement?

@marcj Owner
marcj added a note

No.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ SELECT %s FROM %s;
+DROP TABLE %s;
+ALTER TABLE %s RENAME TO %s;
+";
+
+ $originTable = $tableDiff->getFromTable();
+ $newTable = $tableDiff->getToTable();
+
+ $originTableName = $originTable->getName();
+ $tempTableName = $newTable->getCommonName().'__migration_temp';
+ $newTable->setCommonName($tempTableName);
+
+ $newTableFields = $this->getColumnListDDL($newTable->getColumns());
+ $originTableFields = $this->getColumnListDDL($originTable->getColumns());
+
+ //todo check field diff
+
+
+
+ $sql = sprintf($pattern,
+ $this->getAddTableDDL($newTable),
+ $this->quoteIdentifier($originTableName),
+ $newTableFields,
+ $originTableFields,
+ $this->quoteIdentifier($originTableName),
+ $this->quoteIdentifier($originTableName),
+ $this->quoteIdentifier($tempTableName),
+ $this->quoteIdentifier($originTableName)
+ );
+
+ if ($this->foreignKeySupport){
+ $sql = sprintf("
+PRAGMA foreign_keys = OFF;
+%s
+PRAGMA foreign_keys = ON;
+",
+ $sql);
+ }
+
+ return $sql;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAddTablesDDL(Database $database)
+ {
+ $ret = $this->getBeginDDL();
+ foreach ($database->getTablesForSql() as $table) {
+ $ret .= $this->getCommentBlockDDL($table->getName());
+ $ret .= $this->getDropTableDDL($table);
+ $ret .= $this->getAddTableDDL($table);
+ $ret .= $this->getAddIndicesDDL($table);
+ }
+ $ret .= $this->getEndDDL();
+
+ return $ret;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
public function getAddTableDDL(Table $table)
{
$tableDescription = $table->hasDescription() ? $this->getCommentLineDDL($table->getDescription()) : '';
+ $this->checkCompositePk($table);
+
$lines = array();
foreach ($table->getColumns() as $column) {
@@ -73,6 +242,12 @@ public function getAddTableDDL(Table $table)
$lines[] = $this->getUniqueDDL($unique);
}
+ foreach ($table->getForeignKeys() as $foreignKey) {
+ if ($line = $this->getForeignKeyDDL($foreignKey)){
+ $lines[] = str_replace("\n", "\n ", $line);
+ }
+ }
+
$sep = ",
";
@@ -90,26 +265,130 @@ public function getAddTableDDL(Table $table)
);
}
+ /**
+ * Unfortunately, SQLite does not support composite pks where one is AUTOINCREMENT,
+ * so we have so flag both as NOT NULL and create a UNIQUE constraint.
@staabm Collaborator
staabm added a note

typo: so -> to

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ *
+ * @param Table $table
+ */
+ public function checkCompositePk(Table $table)
+ {
+ if (count($pks = $table->getPrimaryKey()) > 1 && $table->hasAutoIncrementPrimaryKey()){
+ foreach ($pks as $pk){
+ //no pk can be NULL, as usual
+ $pk->setNotNull(true);
+ //in SQLite the column with the AUTOINCREMENT MUST be a primary key, too.
+ if (!$pk->isAutoIncrement()){
+ //for all other sub keys we remove it, since we create a UNIQUE constraint over all primary keys.
+ $pk->setPrimaryKey(false);
+ }
+ }
+
+ //search if there is already a UNIQUE constraint over the primary keys
+ $pkUniqueExist = false;
+ foreach ($table->getUnices() as $unique){
+ $allPk = false;
+ foreach ($unique->getColumns() as $columnName){
+ $allPk &= $table->getColumn($columnName)->isPrimaryKey();
@staabm Collaborator
staabm added a note

why do you assign by ref?

@staabm Collaborator
staabm added a note

I think you meant $allPk = $table->getColumn($columnName)->isPrimaryKey() && $allPk;, but than you need to init $allPk with true

@marcj Owner
marcj added a note

It's a binary operation, not a ref assign.

@staabm Collaborator
staabm added a note

so you should write it in the long form to improve readability.

@marcj Owner
marcj added a note

I really appreciate your work, but please, don't discuss a WIP PR yet. If your opinion is that combined operators are not readable to you, than that's totally OK to me, but please don't declare it as 'you should not do that'.

@staabm Collaborator
staabm added a note

sure. sorry for that, and don't do it ;-).

@marcj Owner
marcj added a note

What?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ }
+ if ($allPk){
+ //there's already a unique constraint with the composite pk
+ $pkUniqueExist = true;
+ break;
+ }
+ }
+
+ //there is none, let's create it
+ if (!$pkUniqueExist){
+ $unique = new Unique();
+ foreach ($pks as $pk){
+ $unique->addColumn($pk);
+ }
+ $table->addUnique($unique);
+ }
+ }
+
+ }
+
+
+ /**
+ * Returns the SQL for the primary key of a Table object
+ * @return string
+ */
+ public function getPrimaryKeyDDL(Table $table)
+ {
+
+ return parent::getPrimaryKeyDDL($table);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getRemoveColumnDDL(Column $column){
+ //not supported
+ return '';
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getRenameColumnDDL($fromColumn, $toColumn)
+ {
+ //not supported
+ return '';
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getModifyColumnDDL(PropelColumnDiff $columnDiff){
+ //not supported
+ return '';
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getModifyColumnsDDL($columnDiffs){
+ //not supported
+ return '';
+ }
+
+ /**
+ * {@inheritdoc}
+ */
public function getDropPrimaryKeyDDL(Table $table)
{
- // FIXME: not supported by SQLite
+ //not supported
return '';
}
+ /**
+ * {@inheritdoc}
+ */
public function getAddPrimaryKeyDDL(Table $table)
{
- // FIXME: not supported by SQLite
+ //not supported
return '';
}
+ /**
+ * {@inheritdoc}
+ */
public function getAddForeignKeyDDL(ForeignKey $fk)
{
- // no need for an alter table to return comments
- return $this->getForeignKeyDDL($fk);
+ //not supported
+ return '
+--- SQLite does not support altering foreign keys directly; this is just for reference
+';
}
+ /**
+ * {@inheritdoc}
+ */
public function getDropForeignKeyDDL(ForeignKey $fk)
{
+ //not supported
return '';
}
@@ -122,16 +401,29 @@ public function getDropTableDDL(Table $table)
public function getForeignKeyDDL(ForeignKey $fk)
{
- $pattern = "
--- SQLite does not support foreign keys; this is just for reference
--- FOREIGN KEY (%s) REFERENCES %s (%s)
-";
- return sprintf($pattern,
+ if ($fk->isSkipSql() || !$this->foreignKeySupport) {
+ return;
+ }
+
+ $pattern = "FOREIGN KEY (%s) REFERENCES %s (%s)";
+
+ $script = sprintf($pattern,
$this->getColumnListDDL($fk->getLocalColumns()),
$fk->getForeignTableName(),
$this->getColumnListDDL($fk->getForeignColumns())
);
+
+ if ($fk->hasOnUpdate()) {
+ $script .= "
+ ON UPDATE " . $fk->getOnUpdate();
+ }
+ if ($fk->hasOnDelete()) {
+ $script .= "
+ ON DELETE " . $fk->getOnDelete();
+ }
+
+ return $script;
}
public function hasSize($sqlType)
@@ -159,12 +451,4 @@ public function quoteIdentifier($text)
{
return $this->isIdentifierQuotingEnabled ? '[' . $text . ']' : $text;
}
-
- /**
- * @see Platform::supportsMigrations()
- */
- public function supportsMigrations()
- {
- return false;
- }
}
View
4 test/fixtures/bookstore/build.properties
@@ -11,8 +11,8 @@
# you cannot refer to any properties set therein.
propel.project = bookstore
-propel.database = mysql
-propel.database.url = mysql:dbname=test
+#propel.database = sqlite
+#propel.database.url = sqlite:/var/tmp/test2.db
propel.mysql.tableType = InnoDB
propel.disableIdentifierQuoting = true
propel.schema.autoPrefix = true
View
41 test/fixtures/bookstore/runtime-conf.xml
@@ -11,40 +11,13 @@
<datasources default="bookstore">
<datasource id="bookstore">
- <!-- the Propel adapter to use for this connection -->
- <adapter>mysql</adapter>
- <!-- Connection parameters. See PDO documentation for DSN format and available option constants. -->
- <connection>
- <classname>DebugPDO</classname>
- <dsn>mysql:dbname=test</dsn>
- <!--
- For MySQL and Oracle you must specify username + password separate from DSN:
- -->
- <user>root</user>
- <password></password>
- <options>
- <option id="ATTR_PERSISTENT">false</option>
- </options>
-
- <attributes>
- <!--
- For MySQL, you should also turn on prepared statement emulation,
- as prepared statements support is buggy in mysql driver
- -->
- <option id="ATTR_EMULATE_PREPARES">true</option>
- </attributes>
-
- <settings>
- <!-- Set the character set for client connection -->
- <setting id="charset">utf8</setting>
- <!-- you can also execute arbitrary queries after the connection is created
- <setting id="queries">
- <query>SELECT * FROM foo</query>
- <query>INSERT INTO BAR ('hey', 'there')</query>
- </setting>
- -->
- </settings>
- </connection>
+ <!-- the Propel adapter (usually same as phptype of connection DSN) -->
+ <adapter>sqlite</adapter>
+ <!-- Connection DSN. See PEAR DSN format for other supported parameters. -->
+ <connection>
+ <classname>DebugPDO</classname>
+ <dsn>sqlite:/var/tmp/test2.db</dsn>
+ </connection>
</datasource>
<datasource id="bookstore-cms">
View
114 test/testsuite/generator/behavior/aggregate_column/AggregateColumnBehaviorTest.php
@@ -29,57 +29,59 @@ public function testParameters()
public function testCompute()
{
- AggregateCommentQuery::create()->deleteAll($this->con);
- AggregatePostQuery::create()->deleteAll($this->con);
+ $con = Propel::getConnection(AggregatePostPeer::DATABASE_NAME);
+ AggregateCommentQuery::create()->deleteAll();
+ AggregatePostQuery::create()->deleteAll();
$post = new AggregatePost();
- $post->save($this->con);
- $this->assertEquals(0, $post->computeNbComments($this->con), 'The compute method returns 0 for objects with no related objects');
+ $post->save();
+ $this->assertEquals(0, $post->computeNbComments($con), 'The compute method returns 0 for objects with no related objects');
$comment1 = new AggregateComment();
$comment1->setAggregatePost($post);
- $comment1->save($this->con);
- $this->assertEquals(1, $post->computeNbComments($this->con), 'The compute method computes the aggregate function on related objects');
+ $comment1->save();
+ $this->assertEquals(1, $post->computeNbComments($con), 'The compute method computes the aggregate function on related objects');
$comment2 = new AggregateComment();
$comment2->setAggregatePost($post);
- $comment2->save($this->con);
- $this->assertEquals(2, $post->computeNbComments($this->con), 'The compute method computes the aggregate function on related objects');
- $comment1->delete($this->con);
- $this->assertEquals(1, $post->computeNbComments($this->con), 'The compute method computes the aggregate function on related objects');
+ $comment2->save();
+ $this->assertEquals(2, $post->computeNbComments($con), 'The compute method computes the aggregate function on related objects');
+ $comment1->delete();
+ $this->assertEquals(1, $post->computeNbComments($con), 'The compute method computes the aggregate function on related objects');
}
public function testUpdate()
{
- AggregateCommentQuery::create()->deleteAll($this->con);
- AggregatePostQuery::create()->deleteAll($this->con);
+ $con = Propel::getConnection(AggregatePostPeer::DATABASE_NAME);
+ AggregateCommentQuery::create()->deleteAll();
+ AggregatePostQuery::create()->deleteAll();
$post = new AggregatePost();
- $post->save($this->con);
+ $post->save();
$comment = new TestableComment();
$comment->setAggregatePost($post);
- $comment->save($this->con);
+ $comment->save($con);
$this->assertNull($post->getNbComments());
- $post->updateNbComments($this->con);
+ $post->updateNbComments($con);
$this->assertEquals(1, $post->getNbComments(), 'The update method updates the aggregate column');
- $comment->delete($this->con);
+ $comment->delete($con);
$this->assertEquals(1, $post->getNbComments());
- $post->updateNbComments($this->con);
+ $post->updateNbComments($con);
$this->assertEquals(0, $post->getNbComments(), 'The update method updates the aggregate column');
}
public function testCreateRelated()
{
- AggregateCommentQuery::create()->deleteAll($this->con);
- AggregatePostQuery::create()->deleteAll($this->con);
+ AggregateCommentQuery::create()->deleteAll();
+ AggregatePostQuery::create()->deleteAll();
$post = new AggregatePost();
- $post->save($this->con);
+ $post->save();
$comment1 = new AggregateComment();
- $comment1->save($this->con);
+ $comment1->save();
$this->assertNull($post->getNbComments(), 'Adding a new foreign object does not update the aggregate column');
$comment2 = new AggregateComment();
$comment2->setAggregatePost($post);
- $comment2->save($this->con);
+ $comment2->save();
$this->assertEquals(1, $post->getNbComments(), 'Adding a new related object updates the aggregate column');
$comment3 = new AggregateComment();
$comment3->setAggregatePost($post);
- $comment3->save($this->con);
+ $comment3->save();
$this->assertEquals(2, $post->getNbComments(), 'Adding a new related object updates the aggregate column');
}
@@ -88,7 +90,7 @@ public function testUpdateRelated()
list($poll, $item1, $item2) = $this->populatePoll();
$this->assertEquals(19, $poll->getTotalScore());
$item1->setScore(10);
- $item1->save($this->con);
+ $item1->save();
$this->assertEquals(17, $poll->getTotalScore(), 'Updating a related object updates the aggregate column');
}
@@ -96,9 +98,9 @@ public function testDeleteRelated()
{
list($poll, $item1, $item2) = $this->populatePoll();
$this->assertEquals(19, $poll->getTotalScore());
- $item1->delete($this->con);
+ $item1->delete();
$this->assertEquals(7, $poll->getTotalScore(), 'Deleting a related object updates the aggregate column');
- $item2->delete($this->con);
+ $item2->delete();
$this->assertNull($poll->getTotalScore(), 'Deleting a related object updates the aggregate column');
}
@@ -107,7 +109,7 @@ public function testUpdateRelatedWithQuery()
list($poll, $item1, $item2) = $this->populatePoll();
$this->assertEquals(19, $poll->getTotalScore());
AggregateItemQuery::create()
- ->update(array('Score' => 4), $this->con);
+ ->update(array('Score' => 4));
$this->assertEquals(8, $poll->getTotalScore(), 'Updating related objects with a query updates the aggregate column');
}
@@ -117,7 +119,7 @@ public function testUpdateRelatedWithQueryUsingAlias()
$this->assertEquals(19, $poll->getTotalScore());
AggregateItemQuery::create()
->setModelAlias('foo', true)
- ->update(array('Score' => 4), $this->con);
+ ->update(array('Score' => 4));
$this->assertEquals(8, $poll->getTotalScore(), 'Updating related objects with a query using alias updates the aggregate column');
}
@@ -126,7 +128,7 @@ public function testDeleteRelatedWithQuery()
list($poll, $item1, $item2) = $this->populatePoll();
$this->assertEquals(19, $poll->getTotalScore());
AggregateItemQuery::create()
- ->deleteAll($this->con);
+ ->deleteAll();
$this->assertNull($poll->getTotalScore(), 'Deleting related objects with a query updates the aggregate column');
}
@@ -137,51 +139,51 @@ public function testDeleteRelatedWithQueryUsingAlias()
AggregateItemQuery::create()
->setModelAlias('foo', true)
->filterById($item1->getId())
- ->delete($this->con);
+ ->delete();
$this->assertEquals(7, $poll->getTotalScore(), 'Deleting related objects with a query using alias updates the aggregate column');
}
public function testRemoveRelation()
{
- AggregateCommentQuery::create()->deleteAll($this->con);
- AggregatePostQuery::create()->deleteAll($this->con);
+ AggregateCommentQuery::create()->deleteAll();
+ AggregatePostQuery::create()->deleteAll();
$post = new AggregatePost();
- $post->save($this->con);
+ $post->save();
$comment1 = new AggregateComment();
$comment1->setAggregatePost($post);
- $comment1->save($this->con);
+ $comment1->save();
$comment2 = new AggregateComment();
$comment2->setAggregatePost($post);
- $comment2->save($this->con);
+ $comment2->save();
$this->assertEquals(2, $post->getNbComments());
$comment2->setAggregatePost(null);
- $comment2->save($this->con);
+ $comment2->save();
$this->assertEquals(1, $post->getNbComments(), 'Removing a relation changes the related object aggregate column');
}
public function testReplaceRelation()
{
- AggregateCommentQuery::create()->deleteAll($this->con);
- AggregatePostQuery::create()->deleteAll($this->con);
+ AggregateCommentQuery::create()->deleteAll();
+ AggregatePostQuery::create()->deleteAll();
$post1 = new AggregatePost();
- $post1->save($this->con);
+ $post1->save();
$post2 = new AggregatePost();
- $post2->save($this->con);
+ $post2->save();
$comment = new AggregateComment();
$comment->setAggregatePost($post1);
- $comment->save($this->con);
+ $comment->save();
$this->assertEquals(1, $post1->getNbComments());
$this->assertNull($post2->getNbComments());
$comment->setAggregatePost($post2);
- $comment->save($this->con);
+ $comment->save();
$this->assertEquals(0, $post1->getNbComments(), 'Replacing a relation changes the related object aggregate column');
$this->assertEquals(1, $post2->getNbComments(), 'Replacing a relation changes the related object aggregate column');
}
public function testAddMultipleComments()
{
- AggregateCommentQuery::create()->deleteAll($this->con);
- AggregatePostQuery::create()->deleteAll($this->con);
+ AggregateCommentQuery::create()->deleteAll();
+ AggregatePostQuery::create()->deleteAll();
$post1 = new AggregatePost();
@@ -196,15 +198,15 @@ public function testAddMultipleComments()
$this->assertNull($post1->getNbComments(), 'The post start with null aggregate column');
- $post1->save($this->con);
+ $post1->save();
$this->assertEquals(3, $post1->getNbComments(), 'the post has 3 comments');
}
public function testQueryCountOnUpdate()
{
- AggregateCommentQuery::create()->deleteAll($this->con);
- AggregatePostQuery::create()->deleteAll($this->con);
+ AggregateCommentQuery::create()->deleteAll();
+ AggregatePostQuery::create()->deleteAll();
$post1 = new TestablePost();
$comment = new AggregateComment();
@@ -213,7 +215,7 @@ public function testQueryCountOnUpdate()
$comment2->setAggregatePost($post1);
$comment3 = new AggregateComment();
$comment3->setAggregatePost($post1);
- $post1->save($this->con);
+ $post1->save();
$this->assertEquals(3, $post1->getNbComments(), 'the post has 3 comments');
$this->assertEquals(2, $post1->countComputeCall, 'Only two call to count nbComment');
@@ -221,7 +223,7 @@ public function testQueryCountOnUpdate()
$comment4 = new AggregateComment();
$comment4->setAggregatePost($post1);
- $comment4->save($this->con);
+ $comment4->save();
$this->assertEquals(4, $post1->getNbComments(), 'the post has 4 comments');
$this->assertEquals(2, $post1->countComputeCall, 'Only two call to count nbComment');
@@ -230,13 +232,13 @@ public function testQueryCountOnUpdate()
$comment5 = new AggregateComment();
$comment5->setAggregatePost($post1);
- $post1->save($this->con);
+ $post1->save();
$this->assertEquals(5, $post1->getNbComments(), 'the post has 5 comments');
$this->assertEquals(2, $post1->countComputeCall, 'Only two call to count nbComment');
$post1->countComputeCall = 0;
- $post1->save($this->con);
+ $post1->save();
$this->assertEquals(5, $post1->getNbComments(), 'the post has 5 comments');
$this->assertEquals(1, $post1->countComputeCall, 'Only one call to count nbComment');
@@ -244,18 +246,18 @@ public function testQueryCountOnUpdate()
protected function populatePoll()
{
- AggregateItemQuery::create()->deleteAll($this->con);
- AggregatePollQuery::create()->deleteAll($this->con);
+ AggregateItemQuery::create()->deleteAll();
+ AggregatePollQuery::create()->deleteAll();
$poll = new AggregatePoll();
- $poll->save($this->con);
+ $poll->save();
$item1 = new AggregateItem();
$item1->setScore(12);
$item1->setAggregatePoll($poll);
- $item1->save($this->con);
+ $item1->save();
$item2 = new AggregateItem();
$item2->setScore(7);
$item2->setAggregatePoll($poll);
- $item2->save($this->con);
+ $item2->save();
return array($poll, $item1, $item2);
}
View
34 test/testsuite/generator/behavior/i18n/I18nBehaviorTest.php
@@ -48,7 +48,9 @@ public function testModifyDatabaseOverridesDefaultLocale()
(
[id] INTEGER NOT NULL,
[locale] VARCHAR(5) DEFAULT 'fr_FR' NOT NULL,
- PRIMARY KEY ([id],[locale])
+ PRIMARY KEY ([id],[locale]),
+ FOREIGN KEY ([id]) REFERENCES i18n_behavior_test_0 ([id])
+ ON DELETE CASCADE
);
EOF;
$this->assertContains($expected, $builder->getSQL());
@@ -82,7 +84,9 @@ public function testModifyDatabaseDoesNotOverrideTableLocale()
(
[id] INTEGER NOT NULL,
[locale] VARCHAR(5) DEFAULT 'pt_PT' NOT NULL,
- PRIMARY KEY ([id],[locale])
+ PRIMARY KEY ([id],[locale]),
+ FOREIGN KEY ([id]) REFERENCES i18n_behavior_test_0 ([id])
+ ON DELETE CASCADE
);
EOF;
$this->assertContains($expected, $builder->getSQL());
@@ -113,7 +117,7 @@ public function schemaDataProvider()
<column name="id" primaryKey="true" type="INTEGER" />
<column name="locale" primaryKey="true" type="VARCHAR" size="5" default="en_US" />
<column name="bar" type="VARCHAR" size="100" />
- <foreign-key foreignTable="i18n_behavior_test_0">
+ <foreign-key foreignTable="i18n_behavior_test_0" onDelete="CASCADE">
<reference local="id" foreign="id" />
</foreign-key>
</table>
@@ -150,7 +154,7 @@ public function testModifyTableRelatesI18nTableToMainTable($schema)
$builder = new PropelQuickBuilder();
$builder->setSchema($schema);
$expected = <<<EOF
--- FOREIGN KEY ([id]) REFERENCES i18n_behavior_test_0 ([id])
+ FOREIGN KEY ([id]) REFERENCES i18n_behavior_test_0 ([id])
EOF;
$this->assertContains($expected, $builder->getSQL());
}
@@ -184,7 +188,9 @@ public function testModifyTableMovesI18nColumns($schema)
[id] INTEGER NOT NULL,
[locale] VARCHAR(5) DEFAULT 'en_US' NOT NULL,
[bar] VARCHAR(100),
- PRIMARY KEY ([id],[locale])
+ PRIMARY KEY ([id],[locale]),
+ FOREIGN KEY ([id]) REFERENCES i18n_behavior_test_0 ([id])
+ ON DELETE CASCADE
);
EOF;
$this->assertContains($expected, $builder->getSQL());
@@ -200,7 +206,7 @@ public function testModifyTableDoesNotMoveNonI18nColumns($schema)
$expected = <<<EOF
CREATE TABLE [i18n_behavior_test_0]
(
- [id] INTEGER NOT NULL PRIMARY KEY,
+ [id] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
[foo] INTEGER
);
EOF;
@@ -282,7 +288,9 @@ public function testModiFyTableUsesCustomI18nTableName()
(
[id] INTEGER NOT NULL,
[locale] VARCHAR(5) DEFAULT 'en_US' NOT NULL,
- PRIMARY KEY ([id],[locale])
+ PRIMARY KEY ([id],[locale]),
+ FOREIGN KEY ([id]) REFERENCES i18n_behavior_test_0 ([id])
+ ON DELETE CASCADE
);
EOF;
$this->assertContains($expected, $builder->getSQL());
@@ -313,7 +321,9 @@ public function testModiFyTableUsesCustomLocaleColumnName()
(
[id] INTEGER NOT NULL,
[culture] VARCHAR(5) DEFAULT 'en_US' NOT NULL,
- PRIMARY KEY ([id],[culture])
+ PRIMARY KEY ([id],[culture]),
+ FOREIGN KEY ([id]) REFERENCES i18n_behavior_test_0 ([id])
+ ON DELETE CASCADE
);
EOF;
$this->assertContains($expected, $builder->getSQL());
@@ -344,7 +354,9 @@ public function testModiFyTableUsesCustomLocaleDefault()
(
[id] INTEGER NOT NULL,
[locale] VARCHAR(5) DEFAULT 'fr_FR' NOT NULL,
- PRIMARY KEY ([id],[locale])
+ PRIMARY KEY ([id],[locale]),
+ FOREIGN KEY ([id]) REFERENCES i18n_behavior_test_0 ([id])
+ ON DELETE CASCADE
);
EOF;
$this->assertContains($expected, $builder->getSQL());
@@ -395,7 +407,9 @@ public function testModifyTableUseCustomPkName()
(
[custom_id] INTEGER NOT NULL,
[locale] VARCHAR(5) DEFAULT 'fr_FR' NOT NULL,
- PRIMARY KEY ([custom_id],[locale])
+ PRIMARY KEY ([custom_id],[locale]),
+ FOREIGN KEY ([custom_id]) REFERENCES i18n_behavior_test_0 ([id])
+ ON DELETE CASCADE
);
EOF;
$this->assertContains($expected, $builder->getSQL());
View
34 test/testsuite/generator/behavior/nestedset/NestedSetBehaviorObjectBuilderModifierTest.php
@@ -290,10 +290,10 @@ public function testGetParent()
$t3->setTitle('t3')->setLeftValue(3)->setRightValue(4)->setLevel(2)->save();
$t4 = new Table9();
$t4->setTitle('t4')->setLeftValue(5)->setRightValue(6)->setLevel(2)->save();
- $this->assertNull($t1->getParent($this->con), 'getParent() return null for root nodes');
- $this->assertEquals($t2->getParent($this->con), $t1, 'getParent() correctly retrieves parent for nodes');
- $this->assertEquals($t3->getParent($this->con), $t2, 'getParent() correctly retrieves parent for leafs');
- $this->assertEquals($t4->getParent($this->con), $t2, 'getParent() retrieves the same parent for two siblings');
+ $this->assertNull($t1->getParent(), 'getParent() return null for root nodes');
+ $this->assertEquals($t2->getParent(), $t1, 'getParent() correctly retrieves parent for nodes');
+ $this->assertEquals($t3->getParent(), $t2, 'getParent() correctly retrieves parent for leafs');
+ $this->assertEquals($t4->getParent(), $t2, 'getParent() retrieves the same parent for two siblings');
}
public function testGetParentCache()
@@ -308,7 +308,7 @@ public function testGetParentCache()
| \
t6 t7
*/
- $con = Propel::getConnection();
+ $con = Propel::getConnection(Table1Peer::DATABASE_NAME);
$count = $con->getQueryCount();
$parent = $t5->getParent($con);
$parent = $t5->getParent($con);
@@ -344,11 +344,11 @@ public function testGetPrevSibling()
| \
t6 t7
*/
- $this->assertNull($t1->getPrevSibling($this->con), 'getPrevSibling() returns null for root nodes');
- $this->assertNull($t2->getPrevSibling($this->con), 'getPrevSibling() returns null for first siblings');
- $this->assertEquals($t3->getPrevSibling($this->con), $t2, 'getPrevSibling() correctly retrieves prev sibling');
- $this->assertNull($t6->getPrevSibling($this->con), 'getPrevSibling() returns null for first siblings');
- $this->assertEquals($t7->getPrevSibling($this->con), $t6, 'getPrevSibling() correctly retrieves prev sibling');
+ $this->assertNull($t1->getPrevSibling(), 'getPrevSibling() returns null for root nodes');
+ $this->assertNull($t2->getPrevSibling(), 'getPrevSibling() returns null for first siblings');
+ $this->assertEquals($t3->getPrevSibling(), $t2, 'getPrevSibling() correctly retrieves prev sibling');
+ $this->assertNull($t6->getPrevSibling(), 'getPrevSibling() returns null for first siblings');
+ $this->assertEquals($t7->getPrevSibling(), $t6, 'getPrevSibling() correctly retrieves prev sibling');
}
public function testHasNextSibling()
@@ -379,11 +379,11 @@ public function testGetNextSibling()
| \
t6 t7
*/
- $this->assertNull($t1->getNextSibling($this->con), 'getNextSibling() returns null for root nodes');
- $this->assertEquals($t2->getNextSibling($this->con), $t3, 'getNextSibling() correctly retrieves next sibling');
- $this->assertNull($t3->getNextSibling($this->con), 'getNextSibling() returns null for last siblings');
- $this->assertEquals($t6->getNextSibling($this->con), $t7, 'getNextSibling() correctly retrieves next sibling');
- $this->assertNull($t7->getNextSibling($this->con), 'getNextSibling() returns null for last siblings');
+ $this->assertNull($t1->getNextSibling(), 'getNextSibling() returns null for root nodes');
+ $this->assertEquals($t2->getNextSibling(), $t3, 'getNextSibling() correctly retrieves next sibling');
+ $this->assertNull($t3->getNextSibling(), 'getNextSibling() returns null for last siblings');
+ $this->assertEquals($t6->getNextSibling(), $t7, 'getNextSibling() correctly retrieves next sibling');
+ $this->assertNull($t7->getNextSibling(), 'getNextSibling() returns null for last siblings');
}
public function testAddNestedSetChildren()
@@ -447,7 +447,7 @@ public function testGetChildren()
public function testGetChildrenCache()
{
list($t1, $t2, $t3, $t4, $t5, $t6, $t7) = $this->initTree();
- $con = Propel::getConnection();
+ $con = Propel::getConnection(Table1Peer::DATABASE_NAME);
$count = $con->getQueryCount();
$children = $t3->getChildren(null, $con);
$children = $t3->getChildren(null, $con);
@@ -507,7 +507,7 @@ public function testCountChildrenCache()
| \
t6 t7
*/
- $con = Propel::getConnection();
+ $con = Propel::getConnection(Table1Peer::DATABASE_NAME);
$count = $con->getQueryCount();
$children = $t3->getChildren(null, $con);
$nbChildren = $t3->countChildren(null, $con);
View
28 ...uite/generator/behavior/nestedset/NestedSetBehaviorObjectBuilderModifierWithScopeTest.php
@@ -117,13 +117,13 @@ public function testGetParent()
{
$this->initTreeWithScope();
$t1 = $this->getByTitle('t1');
- $this->assertNull($t1->getParent($this->con), 'getParent() return null for root nodes');
+ $this->assertNull($t1->getParent(), 'getParent() return null for root nodes');
$t2 = $this->getByTitle('t2');
- $this->assertEquals($t2->getParent($this->con), $t1, 'getParent() correctly retrieves parent for leafs');
+ $this->assertEquals($t2->getParent(), $t1, 'getParent() correctly retrieves parent for leafs');
$t3 = $this->getByTitle('t3');
- $this->assertEquals($t3->getParent($this->con), $t1, 'getParent() correctly retrieves parent for nodes');
+ $this->assertEquals($t3->getParent(), $t1, 'getParent() correctly retrieves parent for nodes');
$t4 = $this->getByTitle('t4');
- $this->assertEquals($t4->getParent($this->con), $t3, 'getParent() retrieves the same parent for nodes');
+ $this->assertEquals($t4->getParent(), $t3, 'getParent() retrieves the same parent for nodes');
}
public function testGetPrevSibling()
@@ -143,11 +143,11 @@ public function testGetPrevSibling()
| \
t9 t10
*/
- $this->assertNull($t1->getPrevSibling($this->con), 'getPrevSibling() returns null for root nodes');
- $this->assertNull($t2->getPrevSibling($this->con), 'getPrevSibling() returns null for first siblings');
- $this->assertEquals($t3->getPrevSibling($this->con), $t2, 'getPrevSibling() correctly retrieves prev sibling');
- $this->assertNull($t6->getPrevSibling($this->con), 'getPrevSibling() returns null for first siblings');
- $this->assertEquals($t7->getPrevSibling($this->con), $t6, 'getPrevSibling() correctly retrieves prev sibling');
+ $this->assertNull($t1->getPrevSibling(), 'getPrevSibling() returns null for root nodes');
+ $this->assertNull($t2->getPrevSibling(), 'getPrevSibling() returns null for first siblings');
+ $this->assertEquals($t3->getPrevSibling(), $t2, 'getPrevSibling() correctly retrieves prev sibling');
+ $this->assertNull($t6->getPrevSibling(), 'getPrevSibling() returns null for first siblings');
+ $this->assertEquals($t7->getPrevSibling(), $t6, 'getPrevSibling() correctly retrieves prev sibling');
}
public function testGetNextSibling()
@@ -167,11 +167,11 @@ public function testGetNextSibling()
| \
t9 t10
*/
- $this->assertNull($t1->getNextSibling($this->con), 'getNextSibling() returns null for root nodes');
- $this->assertEquals($t2->getNextSibling($this->con), $t3, 'getNextSibling() correctly retrieves next sibling');
- $this->assertNull($t3->getNextSibling($this->con), 'getNextSibling() returns null for last siblings');
- $this->assertEquals($t6->getNextSibling($this->con), $t7, 'getNextSibling() correctly retrieves next sibling');
- $this->assertNull($t7->getNextSibling($this->con), 'getNextSibling() returns null for last siblings');
+ $this->assertNull($t1->getNextSibling(), 'getNextSibling() returns null for root nodes');
+ $this->assertEquals($t2->getNextSibling(), $t3, 'getNextSibling() correctly retrieves next sibling');
+ $this->assertNull($t3->getNextSibling(), 'getNextSibling() returns null for last siblings');
+ $this->assertEquals($t6->getNextSibling(), $t7, 'getNextSibling() correctly retrieves next sibling');
+ $this->assertNull($t7->getNextSibling(), 'getNextSibling() returns null for last siblings');
}
public function testGetDescendants()
View
55 test/testsuite/generator/behavior/versionable/VersionableBehaviorTest.php
@@ -53,7 +53,7 @@ public function testModifyTableAddsVersionColumn($schema)
CREATE TABLE [versionable_behavior_test_0]
(
- [id] INTEGER NOT NULL PRIMARY KEY,
+ [id] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
[bar] INTEGER,
[version] INTEGER DEFAULT 0
);
@@ -85,7 +85,7 @@ public function testModifyTableAddsVersionColumnCustomName()
CREATE TABLE [versionable_behavior_test_0]
(
- [id] INTEGER NOT NULL PRIMARY KEY,
+ [id] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
[bar] INTEGER,
[foo_ver] INTEGER DEFAULT 0
);
@@ -116,7 +116,7 @@ public function testModifyTableDoesNotAddVersionColumnIfExists()
CREATE TABLE [versionable_behavior_test_0]
(
- [id] INTEGER NOT NULL PRIMARY KEY,
+ [id] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
[bar] INTEGER,
[version] BIGINT
);
@@ -164,10 +164,11 @@ public function testModifyTableAddsVersionColumnForForeignKeysIfForeignTableIsVe
CREATE TABLE [versionable_behavior_test_0]
(
- [id] INTEGER NOT NULL PRIMARY KEY,
+ [id] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
[bar] INTEGER,
[foreign_id] INTEGER,
- [version] INTEGER DEFAULT 0
+ [version] INTEGER DEFAULT 0,
+ FOREIGN KEY ([foreign_id]) REFERENCES versionable_behavior_test_1 ([id])
);
EOF;
$this->assertContains($expected, $builder->getSQL());
@@ -186,11 +187,11 @@ public function testModifyTableAddsVersionColumnForForeignKeysIfForeignTableIsVe
[foreign_id] INTEGER,
[version] INTEGER DEFAULT 0 NOT NULL,
[foreign_id_version] INTEGER DEFAULT 0,
- PRIMARY KEY ([id],[version])
+ PRIMARY KEY ([id],[version]),
+ FOREIGN KEY ([id]) REFERENCES versionable_behavior_test_0 ([id])
+ ON DELETE CASCADE
);
--- SQLite does not support foreign keys; this is just for reference
--- FOREIGN KEY ([id]) REFERENCES versionable_behavior_test_0 ([id])
EOF;
$this->assertContains($expected, $builder->getSQL());
}
@@ -211,7 +212,7 @@ public function testModifyTableAddsVersionColumnForReferrersIfForeignTableIsVers
CREATE TABLE [versionable_behavior_test_1]
(
- [id] INTEGER NOT NULL PRIMARY KEY,
+ [id] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
[bar] INTEGER,
[version] INTEGER DEFAULT 0
);
@@ -232,11 +233,11 @@ public function testModifyTableAddsVersionColumnForReferrersIfForeignTableIsVers
[version] INTEGER DEFAULT 0 NOT NULL,
[versionable_behavior_test_0_ids] MEDIUMTEXT,
[versionable_behavior_test_0_versions] MEDIUMTEXT,
- PRIMARY KEY ([id],[version])
+ PRIMARY KEY ([id],[version]),
+ FOREIGN KEY ([id]) REFERENCES versionable_behavior_test_1 ([id])
+ ON DELETE CASCADE
);
--- SQLite does not support foreign keys; this is just for reference
--- FOREIGN KEY ([id]) REFERENCES versionable_behavior_test_1 ([id])
EOF;
$this->assertContains($expected, $builder->getSQL());
}
@@ -260,11 +261,11 @@ public function testModifyTableAddsVersionTable($schema)
[id] INTEGER NOT NULL,
[bar] INTEGER,
[version] INTEGER DEFAULT 0 NOT NULL,
- PRIMARY KEY ([id],[version])
+ PRIMARY KEY ([id],[version]),
+ FOREIGN KEY ([id]) REFERENCES versionable_behavior_test_0 ([id])
+ ON DELETE CASCADE
);
--- SQLite does not support foreign keys; this is just for reference
--- FOREIGN KEY ([id]) REFERENCES versionable_behavior_test_0 ([id])
EOF;
$this->assertContains($expected, $builder->getSQL());
}
@@ -296,11 +297,11 @@ public function testModifyTableAddsVersionTableCustomName()
[id] INTEGER NOT NULL,
[bar] INTEGER,
[version] INTEGER DEFAULT 0 NOT NULL,
- PRIMARY KEY ([id],[version])
+ PRIMARY KEY ([id],[version]),
+ FOREIGN KEY ([id]) REFERENCES versionable_behavior_test_0 ([id])
+ ON DELETE CASCADE
);
--- SQLite does not support foreign keys; this is just for reference
--- FOREIGN KEY ([id]) REFERENCES versionable_behavior_test_0 ([id])
EOF;
$this->assertContains($expected, $builder->getSQL());
}
@@ -332,7 +333,7 @@ public function testModifyTableDoesNotAddVersionTableIfExists()
CREATE TABLE [versionable_behavior_test_0]
(
- [id] INTEGER NOT NULL PRIMARY KEY,
+ [id] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
[bar] INTEGER,
[version] INTEGER DEFAULT 0
);
@@ -345,7 +346,7 @@ public function testModifyTableDoesNotAddVersionTableIfExists()
CREATE TABLE [versionable_behavior_test_0_version]
(
- [id] INTEGER NOT NULL PRIMARY KEY,
+ [id] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
[baz] INTEGER
);
@@ -388,7 +389,7 @@ public function testModifyTableAddsLogColumns($schema)
CREATE TABLE [versionable_behavior_test_0]
(
- [id] INTEGER NOT NULL PRIMARY KEY,
+ [id] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
[bar] INTEGER,
[version] INTEGER DEFAULT 0,
[version_created_at] TIMESTAMP,
@@ -421,11 +422,11 @@ public function testModifyTableAddsVersionTableLogColumns($schema)
[version_created_at] TIMESTAMP,
[version_created_by] VARCHAR(100),
[version_comment] VARCHAR(255),
- PRIMARY KEY ([id],[version])
+ PRIMARY KEY ([id],[version]),
+ FOREIGN KEY ([id]) REFERENCES versionable_behavior_test_0 ([id])
+ ON DELETE CASCADE
);
--- SQLite does not support foreign keys; this is just for reference
--- FOREIGN KEY ([id]) REFERENCES versionable_behavior_test_0 ([id])
EOF;
$this->assertContains($expected, $builder->getSQL());
}
@@ -455,11 +456,11 @@ public function testDatabaseLevelBehavior()
[id] INTEGER NOT NULL,
[bar] INTEGER,
[version] INTEGER DEFAULT 0 NOT NULL,
- PRIMARY KEY ([id],[version])
+ PRIMARY KEY ([id],[version]),
+ FOREIGN KEY ([id]) REFERENCES versionable_behavior_test_0 ([id])
+ ON DELETE CASCADE
);
--- SQLite does not support foreign keys; this is just for reference
--- FOREIGN KEY ([id]) REFERENCES versionable_behavior_test_0 ([id])
EOF;
$this->assertContains($expected, $builder->getSQL());
}
View
4 test/testsuite/generator/builder/om/GeneratedPeerDoSelectTest.php
@@ -145,11 +145,11 @@ public function testDoSelectJoin_NullFk()
public function testDoSelectJoinOneToOne()
{
- $con = Propel::getConnection();
+ $con = Propel::getConnection(BookPeer::DATABASE_NAME);
$count = $con->getQueryCount();
Propel::disableInstancePooling();
$c = new Criteria();
- $accs = BookstoreEmployeeAccountPeer::doSelectJoinBookstoreEmployee($c);
+ $accs = BookstoreEmployeeAccountPeer::doSelectJoinBookstoreEmployee($c, $con);
Propel::enableInstancePooling();
$this->assertEquals(1, $con->getQueryCount() - $count, 'doSelectJoin() makes only one query in a one-to-one relationship');
}
View
42 test/testsuite/generator/builder/om/QueryBuilderTest.php
@@ -139,7 +139,7 @@ public function testFindPkReturnsCorrectObjectForSimplePrimaryKey()
$b = new Book();
$b->setTitle('bar');
$b->setIsbn('2342');
- $b->save($this->con);
+ $b->save();
$count = $this->con->getQueryCount();
BookPeer::clearInstancePool();
@@ -154,7 +154,7 @@ public function testFindPkUsesInstancePoolingForSimplePrimaryKey()
$b = new Book();
$b->setTitle('foo');
$b->setIsbn('2342');
- $b->save($this->con);
+ $b->save();
$count = $this->con->getQueryCount();
$book = BookQuery::create()->findPk($b->getId(), $this->con);
@@ -198,7 +198,7 @@ public function testFindPkSimpleAddsObjectToInstancePool()
$b = new Book();
$b->setTitle('foo');
$b->setIsbn('2342');
- $b->save($this->con);
+ $b->save();
BookPeer::clearInstancePool();
BookQuery::create()->findPk($b->getId(), $this->con);
@@ -214,7 +214,7 @@ public function testFindOneByIdAddsObjectToInstancePool()
$b = new Book();
$b->setTitle('foo');
$b->setIsbn('2342');
- $b->save($this->con);
+ $b->save();
BookPeer::clearInstancePool();
BookQuery::create()->findOneById($b->getId(), $this->con);
@@ -227,8 +227,10 @@ public function testFindOneByIdAddsObjectToInstancePool()
public function testFindPkUsesFindPkComplexOnNonEmptyQueries()
{
- BookQuery::create('b')->findPk(123, $this->con);
- $expected = 'SELECT book.id, book.title, book.isbn, book.price, book.publisher_id, book.author_id FROM `book` WHERE book.id=123';
+ BookQuery::create('b')->findPk(123);
+ $con = Propel::getConnection(BookPeer::DATABASE_NAME);
+ $q = $con instanceof DBMySQL ? '`' : '';
+ $expected = "SELECT book.id, book.title, book.isbn, book.price, book.publisher_id, book.author_id FROM {$q}book{$q} WHERE book.id=123";
$this->assertEquals($expected, $this->con->getLastExecutedQuery());
}
@@ -237,7 +239,7 @@ public function testFindPkComplexAddsObjectToInstancePool()
$b = new Book();
$b->setTitle('foo');
$b->setIsbn('2345');
- $b->save($this->con);
+ $b->save();
BookPeer::clearInstancePool();
BookQuery::create('b')->findPk($b->getId(), $this->con);
@@ -658,22 +660,22 @@ public function testFilterByFkCompositeKey()
public function testFilterByFkObjectCollection()
{
- BookstoreDataPopulator::depopulate($this->con);
- BookstoreDataPopulator::populate($this->con);
+ BookstoreDataPopulator::depopulate();
+ BookstoreDataPopulator::populate();
$authors = AuthorQuery::create()
->orderByFirstName()
->limit(2)
- ->find($this->con);
+ ->find();
$books = BookQuery::create()
->filterByAuthor($authors)
- ->find($this->con);
+ ->find();
$q1 = $this->con->getLastExecutedQuery();
$books = BookQuery::create()
->add(BookPeer::AUTHOR_ID, $authors->getPrimaryKeys(), Criteria::IN)
- ->find($this->con);
+ ->find();
$q2 = $this->con->getLastExecutedQuery();
$this->assertEquals($q2, $q1, 'filterByFk() accepts a collection and results to an IN query');
@@ -720,18 +722,18 @@ public function testFilterByRelationNameCompositePk()
$testLabel = RecordLabelQuery::create()
->limit(2)
- ->find($this->con);
+ ->find();
$testRelease = ReleasePoolQuery::create()
->addJoin(ReleasePoolPeer::RECORD_LABEL_ID, RecordLabelPeer::ID)
->filterByRecordLabel($testLabel)
- ->find($this->con);
+ ->find();
$q1 = $this->con->getLastExecutedQuery();
$releasePool = ReleasePoolQuery::create()
->addJoin(ReleasePoolPeer::RECORD_LABEL_ID, RecordLabelPeer::ID)
->add(ReleasePoolPeer::RECORD_LABEL_ID, $testLabel->toKeyValue('Id', 'Id'), Criteria::IN)
- ->find($this->con);
+ ->find();
$q2 = $this->con->getLastExecutedQuery();
$this->assertEquals($q2, $q1, 'filterBy{RelationName}() only accepts arguments of type {RelationName} or PropelCollection');
@@ -758,23 +760,23 @@ public function testFilterByRefFkCompositeKey()
public function testFilterByRefFkObjectCollection()
{
- BookstoreDataPopulator::depopulate($this->con);
- BookstoreDataPopulator::populate($this->con);
+ BookstoreDataPopulator::depopulate();
+ BookstoreDataPopulator::populate();
$books = BookQuery::create()
->orderByTitle()
->limit(2)
- ->find($this->con);
+ ->find();
$authors = AuthorQuery::create()
->filterByBook($books)
- ->find($this->con);
+ ->find();
$q1 = $this->con->getLastExecutedQuery();
$authors = AuthorQuery::create()
->addJoin(AuthorPeer::ID, BookPeer::AUTHOR_ID, Criteria::LEFT_JOIN)
->add(BookPeer::ID, $books->getPrimaryKeys(), Criteria::IN)
- ->find($this->con);
+ ->find();
$q2 = $this->con->getLastExecutedQuery();
$this->assertEquals($q2, $q1, 'filterByRefFk() accepts a collection and results to an IN query in the joined table');
View
24 test/testsuite/generator/platform/PlatformTestProvider.php
@@ -181,10 +181,10 @@ public function providerForTestGetUniqueDDL()
{
$table = new Table('foo');
$column1 = new Column('bar1');
- $column1->getDomain()->copy(new Domain('FOOTYPE'));
+ $column1->getDomain()->copy(new Domain('INTEGER'));
$table->addColumn($column1);
$column2 = new Column('bar2');
- $column2->getDomain()->copy(new Domain('BARTYPE'));
+ $column2->getDomain()->copy(new Domain('INTEGER'));
$table->addColumn($column2);
$index = new Unique('babar');
$index->addColumn($column1);
@@ -200,10 +200,10 @@ public function providerForTestGetIndicesDDL()
{
$table = new Table('foo');
$column1 = new Column('bar1');
- $column1->getDomain()->copy(new Domain('FOOTYPE'));
+ $column1->getDomain()->copy(new Domain('INTEGER'));
$table->addColumn($column1);
$column2 = new Column('bar2');
- $column2->getDomain()->copy(new Domain('BARTYPE'));
+ $column2->getDomain()->copy(new Domain('INTEGER'));
$table->addColumn($column2);
$index1 = new Index('babar');
$index1->addColumn($column1);
@@ -222,10 +222,10 @@ public function providerForTestGetIndexDDL()
{
$table = new Table('foo');
$column1 = new Column('bar1');
- $column1->getDomain()->copy(new Domain('FOOTYPE'));
+ $column1->getDomain()->copy(new Domain('INTEGER'));
$table->addColumn($column1);
$column2 = new Column('bar2');
- $column2->getDomain()->copy(new Domain('BARTYPE'));
+ $column2->getDomain()->copy(new Domain('INTEGER'));
$table->addColumn($column2);
$index = new Index('babar');
$index->addColumn($column1);
@@ -253,11 +253,11 @@ public function providerForTestGetForeignKeyDDL()
{
$table1 = new Table('foo');
$column1 = new Column('bar_id');
- $column1->getDomain()->copy(new Domain('FOOTYPE'));
+ $column1->getDomain()->copy(new Domain('INTEGER'));
$table1->addColumn($column1);
$table2 = new Table('bar');
$column2 = new Column('id');
- $column2->getDomain()->copy(new Domain('BARTYPE'));
+ $column2->getDomain()->copy(new Domain('INTEGER'));
$table2->addColumn($column2);
$fk = new ForeignKey('foo_bar_FK');
$fk->setForeignTableCommonName('bar');
@@ -286,11 +286,11 @@ public function providerForTestGetForeignKeysDDL()
$table1 = new Table('foo');
$column1 = new Column('bar_id');
- $column1->getDomain()->copy(new Domain('FOOTYPE'));
+ $column1->getDomain()->copy(new Domain('INTEGER'));
$table1->addColumn($column1);
$table2 = new Table('bar');
$column2 = new Column('id');
- $column2->getDomain()->copy(new Domain('BARTYPE'));
+ $column2->getDomain()->copy(new Domain('INTEGER'));
$table2->addColumn($column2);
$fk = new ForeignKey('foo_bar_FK');
@@ -300,11 +300,11 @@ public function providerForTestGetForeignKeysDDL()
$table1->addForeignKey($fk);
$column3 = new Column('baz_id');
- $column3->getDomain()->copy(new Domain('BAZTYPE'));
+ $column3->getDomain()->copy(new Domain('INTEGER'));
$table1->addColumn($column3);
$table3 = new Table('baz');
$column4 = new Column('id');
- $column4->getDomain()->copy(new Domain('BAZTYPE'));
+ $column4->getDomain()->copy(new Domain('INTEGER'));
$table3->addColumn($column4);
$fk = new ForeignKey('foo_baz_FK');
View
49 test/testsuite/generator/platform/SqlitePlatformTest.php
@@ -20,7 +20,7 @@ class SqlitePlatformTest extends PlatformTestProvider
/**
* Get the Platform object for this class
*
- * @return Platform
+ * @return DefaultPlatform
*/
protected function getPlatform()
{
@@ -75,16 +75,14 @@ public function testGetAddTablesDDL($schema)
CREATE TABLE [book]
(
- [id] INTEGER NOT NULL PRIMARY KEY,
+ [id] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
[title] VARCHAR(255) NOT NULL,
- [author_id] INTEGER
+ [author_id] INTEGER,
+ FOREIGN KEY ([author_id]) REFERENCES author ([id])
);
CREATE INDEX [book_I_1] ON [book] ([title]);
--- SQLite does not support foreign keys; this is just for reference
--- FOREIGN KEY ([author_id]) REFERENCES author ([id])
-
-----------------------------------------------------------------------
-- author
-----------------------------------------------------------------------
@@ -93,7 +91,7 @@ public function testGetAddTablesDDL($schema)
CREATE TABLE [author]
(
- [id] INTEGER NOT NULL PRIMARY KEY,
+ [id] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
[first_name] VARCHAR(100),
[last_name] VARCHAR(100)
);
@@ -122,7 +120,7 @@ public function testGetAddTableDDLSimplePK($schema)
-- This is foo table
CREATE TABLE [foo]
(
- [id] INTEGER NOT NULL PRIMARY KEY,
+ [id] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
[bar] VARCHAR(255) NOT NULL
);
";
@@ -174,7 +172,7 @@ public function testGetAddTableDDLUniqueIndex($schema)
$expected = "
CREATE TABLE [foo]
(
- [id] INTEGER NOT NULL PRIMARY KEY,
+ [id] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
[bar] INTEGER,
UNIQUE ([bar])
);
@@ -273,7 +271,7 @@ public function testAddIndicesDDL($table)
CREATE INDEX [foo_index] ON [foo] ([bar1]);
";
- $this->assertEquals($expected, $this->getPLatform()->getAddIndicesDDL($table));
+ $this->assertEquals($expected, $this->getPlatform()->getAddIndicesDDL($table));
}
/**
@@ -284,7 +282,7 @@ public function testAddIndexDDL($index)
$expected = "
CREATE INDEX [babar] ON [foo] ([bar1],[bar2]);
";
- $this->assertEquals($expected, $this->getPLatform()->getAddIndexDDL($index));
+ $this->assertEquals($expected, $this->getPlatform()->getAddIndexDDL($index));
}
/**
@@ -295,7 +293,7 @@ public function testDropIndexDDL($index)
$expected = "
DROP INDEX [babar];
";
- $this->assertEquals($expected, $this->getPLatform()->getDropIndexDDL($index));
+ $this->assertEquals($expected, $this->getPlatform()->getDropIndexDDL($index));
}
/**
@@ -304,7 +302,7 @@ public function testDropIndexDDL($index)
public function testGetIndexDDL($index)
{
$expected = 'INDEX [babar] ([bar1],[bar2])';
- $this->assertEquals($expected, $this->getPLatform()->getIndexDDL($index));
+ $this->assertEquals($expected, $this->getPlatform()->getIndexDDL($index));
}
/**
@@ -322,13 +320,11 @@ public function testGetUniqueDDL($index)
public function testGetAddForeignKeysDDL($table)
{
$expected = "
--- SQLite does not support foreign keys; this is just for reference
--- FOREIGN KEY ([bar_id]) REFERENCES bar ([id])
+--- SQLite does not support altering foreign keys directly; this is just for reference
--- SQLite does not support foreign keys; this is just for reference
--- FOREIGN KEY ([baz_id]) REFERENCES baz ([id])
+--- SQLite does not support altering foreign keys directly; this is just for reference
";
- $this->assertEquals($expected, $this->getPLatform()->getAddForeignKeysDDL($table));
+ $this->assertEquals($expected, $this->getPlatform()->getAddForeignKeysDDL($table));
}
/**
@@ -337,10 +333,9 @@ public function testGetAddForeignKeysDDL($table)
public function testGetAddForeignKeyDDL($fk)
{
$expected = "
--- SQLite does not support foreign keys; this is just for reference
--- FOREIGN KEY ([bar_id]) REFERENCES bar ([id])
+--- SQLite does not support altering foreign keys directly; this is just for reference
";
- $this->assertEquals($expected, $this->getPLatform()->getAddForeignKeyDDL($fk));
+ $this->assertEquals($expected, $this->getPlatform()->getAddForeignKeyDDL($fk));
}