1
0
mirror of synced 2025-01-18 14:31:40 +03:00

[2.0] Fixed scale/precision support in SchemaTool

This commit is contained in:
romanb 2009-09-04 20:31:11 +00:00
parent 60b31c7ae0
commit a65ea05f01
4 changed files with 40 additions and 0 deletions

View File

@ -236,6 +236,12 @@ class SchemaTool
$column['type'] = Type::getType($mapping['type']);
$column['length'] = isset($mapping['length']) ? $mapping['length'] : null;
$column['notnull'] = isset($mapping['nullable']) ? ! $mapping['nullable'] : false;
if (isset($mapping['precision'])) {
$column['precision'] = $mapping['precision'];
}
if (isset($mapping['scale'])) {
$column['scale'] = $mapping['scale'];
}
if (isset($mapping['default'])) {
$column['default'] = $mapping['default'];
}

View File

@ -0,0 +1,20 @@
<?php
namespace Doctrine\Tests\Models\Generic;
/**
* @Entity
* @Table(name="date_time_model")
*/
class DecimalModel
{
/**
* @Id @Column(type="integer")
* @GeneratedValue(strategy="AUTO")
*/
public $id;
/**
* @Column(type="decimal", scale=5, precision=2)
*/
public $decimal;
}

View File

@ -20,6 +20,7 @@ class AllTests
$suite = new \Doctrine\Tests\DoctrineTestSuite('Doctrine Orm Functional Tools');
$suite->addTestSuite('Doctrine\Tests\ORM\Functional\SchemaTool\MySqlSchemaToolTest');
//$suite->addTestSuite('Doctrine\Tests\ORM\Functional\SchemaTool\PostgreSqlSchemaToolTest');
return $suite;
}

View File

@ -37,6 +37,19 @@ class MySqlSchemaToolTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this->assertEquals("ALTER TABLE cms_phonenumbers ADD FOREIGN KEY (user_id) REFERENCES cms_users(id)", $sql[7]);
}
public function testGetCreateSchemaSql2()
{
$classes = array(
$this->_em->getClassMetadata('Doctrine\Tests\Models\Generic\DecimalModel')
);
$tool = new SchemaTool($this->_em);
$sql = $tool->getCreateSchemaSql($classes);
$this->assertEquals(1, count($sql));
$this->assertEquals("CREATE TABLE date_time_model (id INT AUTO_INCREMENT NOT NULL, decimal NUMERIC(2, 5) NOT NULL, PRIMARY KEY(id)) ENGINE = InnoDB", $sql[0]);
}
public function testGetUpdateSchemaSql()
{
$classes = array(