Database Comments with Symfony and Propel

I’ve always used propel with Symfony, but occasionally I’ve looked over the fence to have a look at doctrine. One of the things I knew doctrine could do was allow documenting of MySql with comments.

I googled for England for a propel equivalent, no joy.

I’ve been working on a brand new project at work and I’m using the new(ish) sfPropelORMPlugin. Yesterday a colleague told me that you just had to add the following code to the Table and Column declarations in the yaml schema file:


_attributes: { description: ‘My Description’ }

For a table this is easy:

propel:
  my_table:
    _attributes: { description: 'My Description' }

I tried this for the “name” column :

propel:
  my_table:
    _attributes: { description: 'My Description' }
    id: ~
    userid: { type: varchar(255) } #Uncommented
    name:
      _attributes { description: "The Name of the User" }
      type: varchar(255)

This failed when I built the model giving:

PHP Warning: htmlspecialchars() expects parameter 1 to be string, array given in /home/adavies/projects/misc/cmd/trunk/plugins/sfPropelORMPlugin/lib/addon/sfPropelDatabaseSchema.class.php on line 809

I passed an array instead of a string for _attributes. In fact the new plugin is just clever enough to accept the following in the column declaration:


name: { description: 'My Column Description', type: varchar(255) }

So now you can document your dB. What are you waiting for?

Note to self I really must re-investigate some of the code plugins in WordPress for pasting raw code and prettifying it.

symfony svn:externals for newbs

A new job often means doing something that you new you should have done a long time ago. A little while ago, I created a new symfony project on my own @meditemple webspace. I just ftp my updates up to the server as I go (I haven’t done much lately, I’ve stopped) but I’m going to try and finish it.

Anyway, I don’t need to worry about subversion (for now) whilst I’m working on my home projects. However I need to use it more in my new job than I used to in my old one. So in at the deepend, here’s a summary of how I added symfony plugins via svn:externals.

So, I had to create a new project and I’m following along the online documentation and I get to Installing from Subversion in symfony Installation. after creating the directories to hold the symfony code I imported them in a new svn repository. Then I came to the following command in the documentation:

$ svn pe svn:externals lib/vendor/

The “pe” is an alias for propedit which means you are going to edit svn properties for that folder.

Now I understood that this was going to prepare my directory to treat the content as an svn external so that on every svn update I did, it would pull in the latest stable version of 1.4. However the command failed with:

svn: None of the environment variables SVN_EDITOR, VISUAL or EDITOR are set, and no 'editor-cmd' run-time configuration option was found

The command is trying to edit a subversion file called svn:externals but you first need to define an editor, so:

$ export SVN_EDITOR=vi
$ svn pe svn:externals lib/vendor/

Add this line:

symfony http://svn.symfony-project.com/branches/1.4

It is possible to by-pass setting the SVN_EDITOR with a shorthand version:

$ svn propset svn:externals symfony http://svn.symfony-project.com/branches/1.4 lib/vendor/

…but you will need to learn to use an editor because it will be far easier to maintain a list of externals with the editor especially if you plan to have all of your symfony plugins as svn:externals too.

Save the file and commit. Then run a svn update and the symfony code will be included in your project and the latest (v1.4) stable release will be maintained with every subsequent svn up.

I bet you’ll be able to use your new-found skills to svn:ignore log/ and cache/ too, won’t you?