Recent Changes - Search:


PmWiki Help

edit SideBar


As the bot gets upgraded and plugins get added, the database schema will change. Fields will be added or removed, tables will be created, and so on. There needs to be a way of cleanly upgrading the existing database schema to match what is required by the software currently running.

An important aspect of this problem is that some plugins require tables in the schema, but these tables are only created by the ibid-setup script when it calls create_all - if a new plugin is installed, there is no way to create the table just for that plugin as yet.

If we had some sort of schema version number stored in a static table, and methods that could perform simple steps to migrate from one version to the next, it would be easy to step up through all the steps to get to the current version number. In addition, if plugins could detect that their tables had not been created, or were an old version, they could step forward through versions to current.

So, every plugin should be considered to be at schema version zero (0) by default, when no version is specified. When a plugin needs a table to be created, it should specify the table, in its code, and that it is now at schema version one (1). Every time the schema is changed, the schema version number should be bumped up by one. In addition, methods should be supplied by the plugin to move from version zero to version one, and so on up (schema_0_to_1, schema_1_to_2, etc). Now, core can keep track of every plugin, and its currently implemented schema version (plugins not listen have schema version zero by default). When a plugin is loaded, a quick check of its schema version against the stored schema version can be performed - if the plugin's version is greater than the stored version, then the code has clearly been upgraded, and the methods to upgrade the schema can be run.

A core table something along the lines of the following should suffice:

create table schema_info(
     id int(3) not null auto_increment,
     pluginname varchar(100),
     version int(10)

If there is no line in the above table for a plugin, it is at version zero (no tables required).

Now when a bot owner installs a plugin or updates the source, they run ibid-update, which checks that the schema is up to date and does anything else that the new version requires.

Edit - History - Print - Recent Changes - Search
Page last modified on February 28, 2009, at 12:09 AM