=> */ return array( 'drop' => array( 'auto_increment' => 'dropAutoIncrement', 'field_default_is_sequence_value' => 'dropDefaultValueSequence', 'sequences' => 'dropSequences', 'limited_index_field_length' => 'dropIndexLimitations', ), ); } /** * Run schema transformations.. * */ public function run( array &$schema, array $targetSchema ) { $srcFeatures = $schema['schema']['_info']['features']; $dstFeatures = $targetSchema['schema']['_info']['features']; $rules = self::getRules(); foreach ( $srcFeatures as $feature => $fValue ) { // Check if the rule must be transformed at all. if ( in_array( $feature, $dstFeatures ) ) { continue; // do nothing: no transformation is required for this feature } // Check if there is a way to remove this feature. elseif ( isset( $rules['drop'][$feature] ) ) { $methodName = $rules['drop'][$feature]; eval( "self::{$methodName}( \$schema );" ); } else { // We don't know how to drop this feature. // Should we show a warning or raise an exception here? } } } /** * Removes mysql auto_increment feature from the schema. */ private static function dropAutoIncrement( &$schema ) { foreach ( $schema['schema']['tables'] as $tableName => $tableSchema ) { foreach ( $tableSchema['fields'] as $fieldName => $fieldSchema ) { if ( isset( $fieldSchema['options']['auto_increment'] ) ) { $origFieldSchemaRef =& $schema['schema']['tables'][$tableName]['fields'][$fieldName]; unset( $origFieldSchemaRef['options']['auto_increment'] ); if ( count( $origFieldSchemaRef['options'] ) == 0 ) unset( $origFieldSchemaRef['options'] ); } } } unset( $schema['schema']['_info']['features']['auto_increment'] ); } /** * Removes mysql limitation on maximum indexed field length. */ private static function dropIndexLimitations( &$schema ) { foreach ( $schema['schema']['tables'] as $tableName => $tableSchema ) { if ( isset( $indexSchema['options']['limitations'] ) ) { unset( $schema['tables'][$tableName]['indexes'][$indexName]['options']['limitations'] ); } } unset( $schema['schema']['_info']['features']['limited_index_field_length'] ); } /** * Drops pgsql-specific DEFAULT values from table fields, referring to sequences. */ private static function dropDefaultValueSequence( &$schema ) { foreach ( $schema['schema']['tables'] as $tableName => $tableSchema ) { foreach ( $tableSchema['fields'] as $fieldName => $fieldSchema ) { $default = $fieldSchema['default']; if ( is_array( $default ) && count( $default ) && $default[0] == 'sequence' ) { $origFieldSchemaRef =& $schema['schema']['tables'][$tableName]['fields'][$fieldName]; $origFieldSchemaRef['default'] = false; unset( $origFieldSchemaRef['not_null'] ); } } } unset( $schema['schema']['_info']['features']['field_default_is_sequence_value'] ); } /** * Drops all sequences from the schema. */ private static function dropSequences( &$schema ) { unset( $schema['schema']['sequences'] ); unset( $schema['schema']['_info']['features']['sequences'] ); } } ?>