Skip to content

Automated upgrade system. #718

Open
Open
@Mike-Benoit

Description

@Mike-Benoit

Currently you leave upgrading the database to the user and require them to manually run SQL commands to upgrade their database. This is especially error prone (potential for data loss) and tedious if the user has many versions to upgrade. Its also made even more difficult when supporting multiple databases like MySQL and PostgreSQL.

It would be nice to have the installer automatically detect that an upgrade is taking place and handle this all for the user automatically, so the original install process and the upgrade process can essentially be the same procedure from the users perspective.

After all, the easier you make the installation and upgrade procedure, the more users will use the software, and of course the higher potential for donations.

ezcDB can already handle this for you in a really simple way:

The following code will dump an existing database schema to an normalized .XML file, so you can use that just before you release a new version:

$db = ezcDbInstance::get();
$schema = ezcDbSchema::createFromDb( $db );
$schema->writeToFile( 'xml', 'lhc_db_schema.xml' );

Then for users to upgrade, you can have the existing installer simply detect that an upgrade is needed and run the following code to calculate the differences in schema and bring it up to date with the latest version:

$db = ezcDbInstance::get();
$xmlSchema = ezcDbSchema::createFromFile( 'xml', 'lhc_db_schema.xml' );
$dbSchema = ezcDbSchema::createFromDb( $db );
$diff = ezcDbSchemaComparator::compareSchemas( $dbSchema, $xmlSchema );
$diff->applyToDb( $db );

Given the above you wouldn't need to handle SQL schema changes manually ever again, and it will work the exact same for both MySQL and PostgreSQL, and be fully automated for end users.

This could even be the basis for a fully automated end-user upgrade system combined with GIT, with something as simple as this:
/var/www/lhc/git pull && php cron.php -s site_admin -c upgrade_schema

If enabled, that could even be run from cron or a button on the LHC admin page. I'm seeing more and more projects provide transparent upgrades in a similar way.

Finally, this should make it much easier to combine the MySQL and PostgreSQL branches into a single one to easier maintenance, and also open the doors for supporting other databases in the future.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions