views:

99

answers:

2

I'm using YAML to define the doctrine schema and would like to start the id field that's set on auto-increment with a number other than 0, let's say 324 (this is done in mysql by doing something like AUTO_INCREMENT=324.

This Google groups thread has a hint that it may be possible to do with command.pre_command event to execute the SQL before fixtures are loaded and references this page from the symfony documentation, but both the hint and the referenced page don't actually explain a known way to do it. Does anyone know how to actually do this?

A: 

You could try to set the AutoIncrement manually in the database, THEN dump the Schema file and see what it outputs in the YML for the AutoIncrement you set.

The command to dump the schema is symfony doctrine::build-schema

It will create the YML file in the config/doctrine directory. Keep in mind that it will overwrite the schema file that is currently in that directory, so you will want to back that up before you attempt doing this.

Jon
+2  A: 

It appears Doctrine 1 does not support this out of the box, so people are telling you to hook into the event that the Symfony CLI task system generates when it starts a new task (the loading of the fixtures). This would work, but I don't know whether this can load the value from the YAML value (maybe the regular "table creation task" would choke on the extra parameter?). The cleanest way to do this is to write a (little) subclass of the task that executes the Doctrine stuff, which understands an extra parameter you pass to the YAML file. This would first do the regular creation of the databases, and then set the autoincrement base values.

An even easier way (to implement, maybe not to execute) would be to create a separate file with the table names and base values, which is read by a new Symfony task you write, which creates and executes the necessary queries. Just don't forget to execute this task after you create the database but before you load the fixtures. And to update the configuration file every time you add a table.

The most quick-and-dirty way would be an extra SQL script with all the queries, and a shell script that executes everything in a row. But this takes the most maintenance on your side.

Jan Fabry
@jblue: I can't find any reference to it in the Propel source code, so I don't think it has this feature. One of the reasons holding it back could be cross-vendor compatibility (you would need to emulate it in other environments). But Propel allows vendor-specific info in the schema, and currently [the MySQL builder](http://www.propelorm.org/browser/tags/1.5.4/generator/lib/builder/sql/mysql/MysqlDDLBuilder.php#L106) uses this to access extra features. So I think getting support for auto-increment start values should be easy if you create a ticket and mail the developers' list.
Jan Fabry
@Jan Fabry, Read my comments to my main question. It can be done by customizing the sql between sql generation and sql insertion. We tried it with Doctrine but it had a bug, so we tried it with Propel and it worked fine. My colleague doing this work decided to switch to Propel for this reason because we decided that being able to fine tune the sql as needed was important to us down the road for the project.
jblue