Raffaele, thanks for creating the plugin, which I look forward to checking out!
There is a better way to handle migrations for Apostrophe plugins.
Doctrine migrations are not really set up for that, you have to do
things in a very picky order for Doctrine migrations to spot plugin
changes and even if you do it can easily go wrong.
Instead, you want to catch the a.migrateSchemaAdditions event and do
your migrations there via aMysql. This event comes from the
apostrophe:migrate task which is the officially encouraged way to do
migrations at the plugin level for Apostrophe. (You can use it at the
project level too although that works okay with Doctrine migrations.)
Take a look at this code:
class apostropheWorkflowPluginConfiguration extends sfPluginConfiguration
{
static $registered = false;
public function initialize()
{
// Yes, this can get called twice. This is Fabien's workaround:
//
http://trac.symfony-project.org/ticket/8026
if (!self::$registered)
{
$this->dispatcher->connect('a.migrateSchemaAdditions',
array($this, 'migrate'));
self::$registered = true;
}
}
And here's the migrate method:
public function migrate($event)
{
$migrate = $event->getSubject();
if (!$migrate->columnExists('a_area', 'draft_version'))
{
$migrate->sql(array('ALTER TABLE a_area ADD COLUMN draft_version
BIGINT DEFAULT NULL'));
}
}
There is also a tableExists() method, etc. in the aMigrate class.
Be aware that your migrations MUST be safe to run more than once. They
must use tableExists and columnExists to determine what is already in
the schema rather than crashing with an error if the migration has
been carried out before. This simple solution avoids some serious
chicken and egg problems that come up when you try to track migrations
the Doctrine way.
You can use doctrine:build --sql to generate the SQL statements and
then go copy and paste them from data/sql/schema.db.sql or use them as
a guide for things like ALTER TABLE statements.
When you follow this approach other developers can painlessly add your
plugin to an existing project. Our recommended deployment process
(apostrophe:deploy) knows to run apostrophe:migrate on your staging
and production servers, for instance.
--
Tom Boutell
P'unk Avenue
215 755 1330
punkave.com
window.punkave.com