protected static function isColumnTypeSmallerThanExistingFieldType($columnType, $fieldType) { return false; // We have intentionally kept this here but not implemented it. // Design wise its bit tough decision with regard to what to allow and what not to. // For example, do we allow change from a text type to mediumblob? // mediumblob is smaller in size but may be user did that knowingly and he wants us to do in db. // and if we don't then his binary data won't be stored as he expects it to be. // What now? // TODO: @Shoaibi: Low: Implement $integerTypes = array_keys(DatabaseCompatibilityUtil::resolveIntegerMaxAllowedValuesByType()); // TODO: @Shoaibi: Low: Shouldn't these types also come from DbCU $floatTypes = array('float', 'double', 'decimal'); $stringTypes = array('char', 'varchar', 'tinytext', 'mediumtext', 'text', 'longtext'); $blogTypes = array('tinyblob', 'mediumblob', 'blob', 'longblob'); //DatabaseCompatibilityUtil::resolveIntegerMaxAllowedValuesByType // type is different, check if we are switching to higher type or not. // check int types // check float types // check string types(blob inclusive) // if types from totally different domain, then what? int < float < text < blob? }
public static function resolveIntegerTypeByMinAndMaxValue(&$type, $min, $max) { $intMaxValuesAllows = DatabaseCompatibilityUtil::resolveIntegerMaxAllowedValuesByType(static::ASSUME_SIGNED); $type = 'integer'; if (isset($max)) { foreach ($intMaxValuesAllows as $relatedType => $valueLimit) { $maxAllowedValue = $valueLimit; $minAllowedValue = 0; if (static::ASSUME_SIGNED) { $minAllowedValue = -1 * $valueLimit; } if ((!isset($min) || $min >= $minAllowedValue) && $max < $maxAllowedValue) { $type = $relatedType; break; } } } }
/** * @depends testResolveWithNumericalValidatorAndVariableMax */ public function testResolveWithNumericalValidatorAndVariableMinForSigned() { $assumedSigned = RedBeanModelMemberRulesToColumnAdapter::ASSUME_SIGNED; if (!$assumedSigned) { return; } $maxAllowed = DatabaseCompatibilityUtil::resolveIntegerMaxAllowedValuesByType($assumedSigned); $modelClassName = 'AuditEvent'; $types = array_keys($maxAllowed); foreach ($types as $type) { $dbType = strtoupper($type); if ($type == 'integer') { $dbType = 'INT'; } $dbType .= '(11)'; $max = $maxAllowed[$type] - $maxAllowed[$type] / 5; $minAllowed = static::calculateMinByMaxAndSigned($maxAllowed[$type], $assumedSigned); $minAllowed = $minAllowed + $max / 5; $rules = array(array('attributeName' . $type, 'type', 'type' => 'integer'), array('attributeName' . $type, 'numerical', 'min' => $minAllowed, 'max' => $max)); $column = RedBeanModelMemberRulesToColumnAdapter::resolve($modelClassName, $rules, static::$messageLogger); $this->assertNotEmpty($column); $this->assertArrayHasKey('name', $column); $this->assertArrayHasKey('type', $column); $this->assertArrayHasKey('unsigned', $column); $this->assertArrayHasKey('notNull', $column); $this->assertArrayHasKey('collation', $column); $this->assertArrayHasKey('default', $column); $this->assertEquals('attributename' . $type, $column['name']); $this->assertEquals($dbType, $column['type']); $this->assertNull($column['unsigned']); $this->assertEquals('NULL', $column['notNull']); // Not Coding Standard $this->assertNull($column['collation']); $this->assertEquals('DEFAULT NULL', $column['default']); // Not Coding Standard } }