public function createEnumColumn($defaultValues, $defaultValue) { $column = new Column(); $column->setType(PropelTypes::ENUM); $column->setValueSet($defaultValues); $column->setDefaultValue($defaultValue); return $column; }
public static function getDefaultValueStringProvider() { $col1 = new Column('Bar'); $col1->setDomain(new Domain('VARCHAR')); $col1->setDefaultValue(new ColumnDefaultValue('abc', ColumnDefaultValue::TYPE_VALUE)); $val1 = "'abc'"; $col2 = new Column('Bar'); $col2->setDomain(new Domain('INTEGER')); $col2->setDefaultValue(new ColumnDefaultValue(1234, ColumnDefaultValue::TYPE_VALUE)); $val2 = "1234"; $col3 = new Column('Bar'); $col3->setDomain(new Domain('DATE')); $col3->setDefaultValue(new ColumnDefaultValue('0000-00-00', ColumnDefaultValue::TYPE_VALUE)); $val3 = "NULL"; return array(array($col1, $val1), array($col2, $val2), array($col3, $val3)); }
public function providerForTestGetModifyColumnRemoveDefaultValueDDL() { $t1 = new Table('test'); $t1->setIdentifierQuoting(true); $c1 = new Column(); $c1->setName('test'); $c1->getDomain()->setType('INTEGER'); $c1->setDefaultValue(0); $t1->addColumn($c1); $t2 = new Table('test'); $t2->setIdentifierQuoting(true); $c2 = new Column(); $c2->setName('test'); $c2->getDomain()->setType('INTEGER'); $t2->addColumn($c2); return [[ColumnComparator::computeDiff($c1, $c2)]]; }
public function getColumnDDL(Column $col) { if ($col->isAutoIncrement()) { $col->setType('INTEGER'); $col->setDomainForType('INTEGER'); } if ($col->getDefaultValue() && $col->getDefaultValue()->isExpression() && 'CURRENT_TIMESTAMP' === $col->getDefaultValue()->getValue()) { //sqlite use CURRENT_TIMESTAMP different than mysql/pgsql etc //we set it to the more common behavior $col->setDefaultValue(new ColumnDefaultValue("(datetime(CURRENT_TIMESTAMP, 'localtime'))", ColumnDefaultValue::TYPE_EXPR)); } return parent::getColumnDDL($col); }
public function providerForTestGetModifyColumnRemoveDefaultValueDDL() { $t1 = new Table('test'); $c1 = new Column(); $c1->setName('test'); $c1->getDomain()->setType('INTEGER'); $c1->setDefaultValue(0); $t1->addColumn($c1); $t2 = new Table('test'); $c2 = new Column(); $c2->setName('test'); $c2->getDomain()->setType('INTEGER'); $t2->addColumn($c2); return array(array(PropelColumnComparator::computeDiff($c1, $c2))); }
$column51->setNotNull(); $column51->setPrimaryKey(); $column52 = new Column('tag_id', 'integer', 7); $column52->setNotNull(); $column52->setPrimaryKey(); $column61 = new Column('id', 'integer', 5); $column61->setNotNull(); $column61->setAutoIncrement(); $column61->setPrimaryKey(); $column62 = new Column('title', 'varchar', 150); $column62->setNotNull(); $column63 = new Column('content', 'clob'); $column63->addVendorInfo(new VendorInfo('mysql', ['Charset' => 'latin1', 'Collate' => 'latin1_general_ci'])); $column64 = new Column('is_published', 'boolean'); $column64->setNotNull(); $column64->setDefaultValue('false'); /* Foreign Keys */ $fkAuthorPost = new ForeignKey('fk_post_has_author'); $fkAuthorPost->addReference('author_id', 'id'); $fkAuthorPost->setForeignTableCommonName('blog_author'); $fkAuthorPost->setRefPhpName('Posts'); $fkAuthorPost->setPhpName('Author'); $fkAuthorPost->setDefaultJoin('Criteria::LEFT_JOIN'); $fkAuthorPost->setOnDelete('CASCADE'); $fkCategoryPost = new ForeignKey('fk_post_has_category'); $fkCategoryPost->addReference('category_id', 'id'); $fkCategoryPost->setForeignTableCommonName('blog_category'); $fkCategoryPost->setRefPhpName('Posts'); $fkCategoryPost->setPhpName('Category'); $fkCategoryPost->setDefaultJoin('Criteria::INNER_JOIN'); $fkCategoryPost->setOnDelete('SETNULL');
public function createMigrationTable($datasource) { $platform = $this->getPlatform($datasource); // modelize the table $database = new Database($datasource); $database->setPlatform($platform); $table = new Table($this->getMigrationTable()); $database->addTable($table); $column = new Column('version'); $column->getDomain()->copy($platform->getDomainForType('INTEGER')); $column->setDefaultValue(0); $table->addColumn($column); // insert the table into the database $statements = $platform->getAddTableDDL($table); $conn = $this->getAdapterConnection($datasource); $res = SqlParser::executeString($statements, $conn); if (!$res) { throw new \Exception(sprintf('Unable to create migration table in datasource "%s"', $datasource)); } }
/** * @dataProvider provideDefaultValues */ public function testGetDefaultValueString($mappingType, $value, $expected) { $defaultValue = $this->getMockBuilder('Propel\\Generator\\Model\\ColumnDefaultValue')->disableOriginalConstructor()->getMock(); $defaultValue->expects($this->any())->method('getValue')->will($this->returnValue($value)); $domain = $this->getDomainMock(); $domain->expects($this->any())->method('getDefaultValue')->will($this->returnValue($defaultValue)); $domain->expects($this->any())->method('setDefaultValue'); $domain->expects($this->any())->method('getType')->will($this->returnValue($mappingType)); $column = new Column(); $column->setDomain($domain); $column->setDefaultValue('foo'); // Test with a scalar $column->setDefaultValue($defaultValue); // Test with an object $this->assertSame($expected, $column->getDefaultValueString()); }