[RFC] Migrations

These requests for comments/change have lead to an implemented feature that has been successfully merged into the 3.1/Ascraeus branch. Everything listed in this forum will be available in phpBB 3.1.
Post Reply
User avatar
MichaelC
Development Team
Development Team
Posts: 889
Joined: Thu Jan 28, 2010 6:29 pm

Re: [RFC] Migrations

Post by MichaelC »

EXreaction wrote:
MichaelC wrote:How do you plan to address the problem that is updating from 3.0.x (where x < 12) to 3.1.x that the migrations table would still need adding with the appropriate migrations depending on which version the update is being done from?
I have a list of phpBB version numbers and the migrations that were applied for those versions. If the migrations table does not exist I automatically fill it with these migrations based on what phpBB version it was.

Right now I am thinking the safest option might be to add a method to each migration, is_installed, which would be able to run custom code to check if the migration was effectively installed (in which case we'd just add the migration data to the migration table and be done). I think this might be best for us and extension authors who update their mods for 3.1.
Optional [so function_exists()] it?
Formerly known as Unknown Bliss
psoTFX wrote: I went with Olympus because as I said to the teams ... "It's been one hell of a hill to climb"
No unsolicited PMs please except for quotes.

User avatar
EXreaction
Registered User
Posts: 1555
Joined: Sat Sep 10, 2005 2:15 am

Re: [RFC] Migrations

Post by EXreaction »

The parent would return false, so yes, it would be optional.

User avatar
EXreaction
Registered User
Posts: 1555
Joined: Sat Sep 10, 2005 2:15 am

Re: [RFC] Migrations

Post by EXreaction »

Last edited by EXreaction on Sun Jan 13, 2013 2:20 am, edited 1 time in total.
Reason: Added page

User avatar
RMcGirr83
Registered User
Posts: 360
Joined: Fri Mar 09, 2007 1:51 am
Contact:

Re: [RFC] Migrations

Post by RMcGirr83 »

Maybe a bit off topic but this doesn't look right to me.

Code: Select all

public function update_schema()
{
    return array(
        'drop_columns'    => array(
            $this->table_prefix . 'styles'        => array(
                'imageset_id',
                'template_id',
                'theme_id',
            ),
        ),

        'drop_tables'    => array(
            $this->table_prefix . 'styles_imageset',
            $this->table_prefix . 'styles_imageset_data',
            $this->table_prefix . 'styles_template',
            $this->table_prefix . 'styles_template_data',
            $this->table_prefix . 'styles_theme',
        ),
    );
}

public function revert_schema()
{
    return array(
        'add_columns'    => array(
            $this->table_prefix . 'styles'        => array(
                'imageset_id'    => array('UINT', 0),
                'template_id'    => array('UINT', 0),
                'theme_id'        => array('UINT', 0),
            ),
        ),

        'add_tables'    => array(
            $this->table_prefix . 'styles_imageset'        => array(
                'COLUMNS'        => array(
                    'imageset_id'                => array('UINT', NULL, 'auto_increment'),
                    'imageset_name'                => array('VCHAR_UNI:255', ''),
                    'imageset_copyright'        => array('VCHAR_UNI', ''),
                    'imageset_path'                => array('VCHAR:100', ''),
                ),
                'PRIMARY_KEY'        => 'imageset_id',
                'KEYS'                => array(
                    'imgset_nm'            => array('UNIQUE', 'imageset_name'),
                ),
            ),
            $this->table_prefix . 'styles_imageset_data'    => array(
                'COLUMNS'        => array(
                    'image_id'                => array('UINT', NULL, 'auto_increment'),
                    'image_name'            => array('VCHAR:200', ''),
                    'image_filename'        => array('VCHAR:200', ''),
                    'image_lang'            => array('VCHAR:30', ''),
                    'image_height'            => array('USINT', 0),
                    'image_width'            => array('USINT', 0),
                    'imageset_id'            => array('UINT', 0),
                ),
                'PRIMARY_KEY'        => 'image_id',
                'KEYS'                => array(
                    'i_d'            => array('INDEX', 'imageset_id'),
                ),
            ),
            $this->table_prefix . 'styles_template'        => array(
                'COLUMNS'        => array(
                    'template_id'            => array('UINT', NULL, 'auto_increment'),
                    'template_name'            => array('VCHAR_UNI:255', ''),
                    'template_copyright'    => array('VCHAR_UNI', ''),
                    'template_path'            => array('VCHAR:100', ''),
                    'bbcode_bitfield'        => array('VCHAR:255', 'kNg='),
                    'template_storedb'        => array('BOOL', 0),
                    'template_inherits_id'        => array('UINT:4', 0),
                    'template_inherit_path'        => array('VCHAR', ''),
                ),
                'PRIMARY_KEY'    => 'template_id',
                'KEYS'            => array(
                    'tmplte_nm'                => array('UNIQUE', 'template_name'),
                ),
            ),
            $this->table_prefix . 'styles_template_data'    => array(
                'COLUMNS'        => array(
                    'template_id'            => array('UINT', 0),
                    'template_filename'        => array('VCHAR:100', ''),
                    'template_included'        => array('TEXT', ''),
                    'template_mtime'        => array('TIMESTAMP', 0),
                    'template_data'            => array('MTEXT_UNI', ''),
                ),
                'KEYS'            => array(
                    'tid'                    => array('INDEX', 'template_id'),
                    'tfn'                    => array('INDEX', 'template_filename'),
                ),
            ),
            $this->table_prefix . 'styles_theme'            => array(
                'COLUMNS'        => array(
                    'theme_id'                => array('UINT', NULL, 'auto_increment'),
                    'theme_name'            => array('VCHAR_UNI:255', ''),
                    'theme_copyright'        => array('VCHAR_UNI', ''),
                    'theme_path'            => array('VCHAR:100', ''),
                    'theme_storedb'            => array('BOOL', 0),
                    'theme_mtime'            => array('TIMESTAMP', 0),
                    'theme_data'            => array('MTEXT_UNI', ''),
                ),
                'PRIMARY_KEY'    => 'theme_id',
                'KEYS'            => array(
                    'theme_name'        => array('UNIQUE', 'theme_name'),
                ),
            ),
        ),
    );
why would someone drop an entire phpBB default table? Wouldn't that then cause issues if a default style is never installed? I may not be thinking completely clearly here as I am sick as a dog (and I have no idea what that even means as dogs rarely get sick as far as I know).
Do not hire Christian Bullock he won't finish the job and will keep your money

User avatar
EXreaction
Registered User
Posts: 1555
Joined: Sat Sep 10, 2005 2:15 am

Re: [RFC] Migrations

Post by EXreaction »

An extension probably should not drop a phpBB table, that is just an example from one case where tables were dropped in a phpBB update. I was trying to show that in revert_schema the table must be recreated.


User avatar
nickvergessen
Former Team Member
Posts: 733
Joined: Sun Oct 07, 2007 11:54 am
Location: Stuttgart, Germany
Contact:

Re: [RFC] Migrations

Post by nickvergessen »

EXreaction wrote:An extension probably should not drop a phpBB table, that is just an example from one case where tables were dropped in a phpBB update. I was trying to show that in revert_schema the table must be recreated.
The problem I have with this kind of "roll-back" is, that additional columns from other Extensions will be dropped and not restored?
It would making deletes a bit more complicated, but can we just log the table/column structure in the migrations db, so we really have the same state after a rollback?
Member of the Development-TeamNo Support via PM

User avatar
EXreaction
Registered User
Posts: 1555
Joined: Sat Sep 10, 2005 2:15 am

Re: [RFC] Migrations

Post by EXreaction »

That would be true, but I am not sure how to get around it. I do not know how it would be possible to log the structure in the database itself.

The roll-back is intended to bring you back to at least a state that is recognizable and not somewhere in-between. Whatever the issue was that caused the roll-back to occur should be resolved and the update run again.

I guess the ideal situation would be that a database backup is made before an update, but I am not sure if that is something we want to either recommend users do themselves or do automatically for users.

User avatar
EXreaction
Registered User
Posts: 1555
Joined: Sat Sep 10, 2005 2:15 am

Re: [RFC] Migrations

Post by EXreaction »

The Migrations documentation is complete I believe, including how to use it in extensions (once the required PR is merged it will work).

keith10456
Registered User
Posts: 523
Joined: Sat Apr 22, 2006 10:29 pm
Contact:

Re: [RFC] Migrations

Post by keith10456 »

EXreaction wrote:... I guess the ideal situation would be that a database backup is made before an update, but I am not sure if that is something we want to either recommend users do themselves or do automatically for users.
That appears to be the right way to go... But do it automatically.

Post Reply