Meet schema.yml

Until today, Propel integration in symfony implied that your database schema had to be defined in XML files called schema.xml. For instance, the database schema of the first project tutorial looked like this:

<?xml version="1.0" encoding="UTF-8"?>
<database name="propel" defaultIdMethod="native" noxsd="true">
  <table name="weblog_post" phpName="Post">
    <column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true" />
    <column name="title" type="varchar" size="255" />
    <column name="excerpt" type="longvarchar" />
    <column name="body" type="longvarchar" />
    <column name="created_at" type="timestamp" />

  <table name="weblog_comment" phpName="Comment">
    <column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true" />
    <column name="post_id" type="integer" required="true" />
      <foreign-key foreignTable="weblog_post">
        <reference local="post_id" foreign="id"/>
    <column name="author" type="varchar" size="255" />
    <column name="email" type="varchar" size="255" />
    <column name="body" type="longvarchar" />
    <column name="created_at" type="timestamp" />

We thought that, for a framework trying to be as simple as possible, it was not the best we could do. As a matter of fact, quite a number of symfony beginners were afraid about its configuration specifically because of this XML file. Some of them were even caught quitting at that point, when they thought that learning a new syntax for schema files was too much for a first try.

So we made it possible to write database schemas in YAML format. You know how we like this format: It's easy to read and write, it's simple to understand, and it's fun. So for instance, the first project tutorial schema (soon to be updated in the doc) can now look like this:

    _attributes: { phpName: Post }
    title:       varchar(255)
    excerpt:     longvarchar
    body:        longvarchar
    _attributes: { phpName: Comment }
    author:      varchar(255)
    email:       varchar(255)
    body:        longvarchar

Nothing more. Save this into a schema.yml file in your project config/ folder, then run

$ symfony propel-build-model

...and the Propel model classes are generated just as before.

Of course, to make it simple, we added some magic to it. If you follow the conventions, you don't need to write too much configuration (does that ring a bell?). For instance, if your primary key is called id, then symfony will automatically make it an autoincrement integer. If a field ends with _id, then symfony will recognize a foreign key and enrich the schema as you expect it to. Fields called created_at or updated_at are, of course, of type timestamp, so you don't need to specify it. I18N tables will be recognized as such, as long as their name end with _i18n.

There will soon be a full documentation about it, but until then, we invite you to try this new feature and give us your feedback. It is available since the release 1577 in the SVN trunk.


Really glad to see this. Although I'm quite happy with the current schema.xml, it's also a fear of many. The move not only make symfony configuration more consistent, but also attracts more people to enter the gate and... those who have been saying "no thanks for the xml schema too complex" now have no excuse ;)
Is there full parity between the XML and YAML schemas? There's a lot of info in the XML example above that isn't apparent in the YAML example.
MSM: The example shows the basic syntax, but the extended YAML syntax is equivalent to the XML. The documentation is currently being updated on this point, but you can get a glance by looking in the trunk at
Will the XML schema still be supported moving forward. The reason I ask is I like to use DBDesigner to build my database and then use Jonathan Graham's conversion utility to propel schema. I find it simple and very helpfull when trying to map out my DB and make changes.
Draven: of course, you can still use the XML format. As a matter of fact, this is the format expected by Propel, so we just convert YAML files to temporary XML files when building the model.

Your own XML files will be processed as well, just as before.
&lt;table name="shop_person" phpname="Person"&gt;
&lt;column name="id" type="integer" required="true" autoincrement="true" primarykey="true" /&gt;
&lt;column name="type" type="integer" inheritance="single"&gt;
&lt;inheritance key="1" class="Customer" extends="Person"/&gt;
&lt;inheritance key="2" class="Delivery" extends="Person"/&gt;
&lt;column name="name" type="varchar" size="255" /&gt;
&lt;column name="created_at" type="timestamp" /&gt;
&lt;column name="updated_at" type="timestamp" /&gt;
I paste the code and forget the message... (that's why a "preview send" button would be nice :-) )...

here is the question , how to achieve propel inheritance with this yaml description? is it possible?
Brikou: not for now. You'll have to stick to the schema.xml until we build this feature into the schema.xml
Uhm ... so YAML support is new, cause I've spent hours to try to make it work with symfony version 0.6.3 :)
I wonder.... Personally I think the Propel XML sytax is cleaner and easier to read the the yaml styled syntax.
Is it possible to update only files required to implement this in symfony 0.6.3 without update the whole symfony to a nightly build ? Can anyone make a patch ? Otherwise wich file could i update to make build model with yaml work ?

Comments are closed.

To ensure that comments stay relevant, they are closed for old posts.