Hi, greetings to Norway!

For my implementation of a proof of concept content repository[1] I need to 
change the database schema on the fly. Changing schemas during production is 
not that uncommon: The search function of eZPublish used to create temporary 
tables and in ERP software you normally create temporary tables to analyze 
data.

With the current state of DbSchema I have to define a table like this:

-----------------------------------------------------------------------------

public static function getCommonTableBase( $name )
{
    return new ezcDbSchemaDiff( array( $name =>
            new ezcDbSchemaTable( array( //         type len notNull default 
autoInc unsigned
        'content_object_id' => new ezcDbSchemaField( 'integer',   0, TRUE,  0, 
FALSE, TRUE ),
        'version'           => new ezcDbSchemaField( 'integer',   0, TRUE,  0, 
FALSE, TRUE ),
        'locale'            => new ezcDbSchemaField( 'text',    255, TRUE, '', 
FALSE, TRUE ),
        'name'              => new ezcDbSchemaField( 'text',    255, TRUE, '', 
FALSE, TRUE ),
        'creator_id'        => new ezcDbSchemaField( 'text',    255, TRUE, '', 
FALSE, TRUE ),
        'created'           => new ezcDbSchemaField( 'timestamp', 0, TRUE,  0, 
FALSE, TRUE ),
        'published'         => new ezcDbSchemaField( 'timestamp', 0, FALSE, 0, 
FALSE, TRUE )
    ), // Indexes
        array( 
        'primary' => new ezcDbSchemaIndex( array( 
                'content_object_id' => new ezcDbSchemaIndexField(),
                'version'           => new ezcDbSchemaIndexField(),
                'locale'            => new ezcDbSchemaIndexField()
                ),
            TRUE, TRUE // primary, unique
            ),
        ),
        'name' => new ezcDbSchemaIndex( array( 
                'name'            => new ezcDbSchemaIndexField()
                ),
            FALSE, FALSE // primary, unique
            ),
        )
    )));
}

---------------------------------------------------------------------------

I propose, to implement an additional fluent interface which would allow me to 
write:

----------------------------------------------------------------------------


public static function getCommonTableBaseNew( $name )
{
    return ezcDbSchemaDiff::create()
           ->addTable()
                ->addColumn( 'content_object_id', ezcDbSchema::INTEGER )
                ->addColumn( 'version',           ezcDbSchema::INTEGER )
                ->addColumn( 'locale',            ezcDbSchema::TEXT )
                ->addColumn( 'name',              ezcDbSchema::TEXT )
                ->addColumn( 'creator_id',        ezcDbSchema::TEXT )
                ->addColumn( 'created',           ezcDbSchema::TIMESTAMP )
                ->addColumn( 'published',         ezcDbSchema::TIMESTAMP )
                ->addIndex( 'primary', 'content_object_id',ezcDbSchema::ASC,
                                       'version',         // Defaults to ASC
                                       'locale',         ezcDbSchema::DESC )
                    ->isPrimary( TRUE )
                    ->isUnique( TRUE )
                ->addIndex( 'name' ) // Default Index name = Column name
                ;
}

----------------------------------------------------------------------------

The implementation is currently only in my head, but I'd be happy to provide a 
patch, if you'd like to implement it.

[1] 
http://www.koch.ro/blog/index.php?/archives/75-Changing-Database-Schemas.html

Best regards,
-- 
Thomas Koch, Software Developer
http://www.koch.ro

Young Media Concepts GmbH
Sonnenstr. 4
CH-8280 Kreuzlingen
Switzerland

Tel    +41 (0)71 / 508 24 86
Fax    +41 (0)71 / 560 53 89
Mobile +49 (0)170 / 753 89 16
Web    www.ymc.ch
-- 
Components mailing list
Components@lists.ez.no
http://lists.ez.no/mailman/listinfo/components

Reply via email to