Love it! :-) will give it a good test on postgres and the mollom plugin shortly.
On Fri, Oct 2, 2009 at 8:27 AM, Evan Prodromou <[email protected]> wrote: > Yellow, everyone. I just pushed some code to 0.9.x to let plugins do schema > maintenance -- that is, lets them add, delete or modify tables in the > database. I wanted to explain what's going. > > There's a new library, lib/schema.php. It has a class, Schema. That's a > singleton (just one schema per site), so you get it using Schema::get(). > > It has a bunch of methods for examining the schema and altering tables and > columns. You can peek at it if you wish. > > The most useful is ensureTable(). This takes a table name and an array of > column definitions, and tries to make sure that a) that table exists and b) > it has the structure you define. It will use CREATE TABLE and ALTER TABLE as > necessary to add the table and/or add, drop, or modify columns. > > There is a new event, 'CheckSchema'. Plugin developers can hook this event > to check the schema for your plugin at the "right" time. A typical example: > > function onCheckSchema() { > $schema = Schema::get(); > $schema->ensureTable('person', > array(new ColumnDef('id', 'integer', null, > false, 'PRI'), > new ColumnDef('name', 'varchar', 255), > new ColumnDef('picture', 'blob'), > new ColumnDef('age', 'integer', null, > true, null, 25))); > return true; > } > > You can see the constructor params for ColumnDef in lib/schema.php. > > There is also a new config parameter, $config['db']['schemacheck']. It > determines when the CheckSchema event fires. By default, it is set to > 'runtime', which means that the schema check is run at every web hit. That's > obviously sub-optimal, but necessary for installations that can't run > command-line programs. The value can also be set to 'script', which means > that the event is only fired when you run scripts/checkschema.php. This is > obviously much better, and you should set this if you can (and run the > script whenever you upgrade StatusNet or install a new plugin). > > When we have a Web-based plugin installer (post-0.9.x timeframe), we'll > probably have a new default, 'install', which would trigger that event > whenever a plugin was upgraded, installed, or uninstalled. > > I hope that's clear enough. > > -Evan > > -- > Evan Prodromou > CEO, StatusNet, Inc. > [email protected] - http://identi.ca/evan - +1-514-554-3826 > > _______________________________________________ > StatusNet-dev mailing list > [email protected] > http://lists.status.net/mailman/listinfo/statusnet-dev > -- Kotahi tamaiti, Kotahi rorohiko iti: Aotearoa http://laptop.org.nz _______________________________________________ StatusNet-dev mailing list [email protected] http://lists.status.net/mailman/listinfo/statusnet-dev
