Customizing a plugin schema without getting your hands dirty

In my previous post, I exposed a first approach to making a plugin schema customizable. After some coding, I came up with a clean solution, in the shape of a plugin: the sfPropelAlternativeSchemaPlugin. It introduces a new syntax for propel database schemas. It’s a little more verbose, but easier to read and totally extensible.

Here is an example of a schema with the new syntax:

connection:           propel
noXsd:                false
defaultIdMethod:      none
package:              lib.model

classes:
  Group:
    tableName:        ab_group
    package:          foo.bar.lib.model
    columns:
      id:
      name:           varchar(50)

  User:
    tableName:        cd_user
    isI18N:           true
    i18nTable:        cd_user_i18n
    columns:
      first_name:     { type: varchar, size: 255, default: "Anonymous" }
      last_name:      varchar(50)
      age:            { type: integer, required: true, index: true }
      ab_group_id:
      created_at:

  CdUserI18n:
    columns:
      description:    longvarchar

  EfArticle:
    columns:
      title:          { type: longvarchar, required: true, index: unique }
      stripped_title: { type: longvarchar, required: true, primaryKey: true, sequence: my_custom_sequence_name }
      user_id:
      my_group:       { type: integer, foreignTable: ab_group, foreignReference: id, onDelete: setnull }
      created_at:     timestamp
      updated_at:

  Article:
    tableName:        ij_article
    columns:
      title:          varchar(50)
      user_id:        { type: integer }
      created_at:
    foreignKeys:
      -
        foreignTable: cd_user
        onDelete:     cascade
        references:
          - { local: user_id, foreign: id }
    indexes:
      my_index:       [title, user_id]
    uniques:
      my_other_index: [created_at]

  AbGroupI18n:
    columns:
      motto:          longvarchar

Refer to the plugin’s README file for more information on installation and usage.

1 Comment so far

  1. Ivan Zgoniaiko on November 4th, 2007

    hi. sorry for my bad english.
    if possible, please show how to customize schema of sfSimpleForumPlugin.
    i’m install sfSimpleForumPlugin from trunk (r5833)
    i’m install sfPropelAlternativeSchemaPlugin-1.0.0
    i create file
    config/sfSimpleForumPlugin_schema.custom.yml

    with content

    connection: propel
    noXsd: false
    defaultIdMethod: none
    package: plugins.sfSimpleForumPlugin.lib.model

    classes:
    sfSimpleForumForum:
    package: plugins.sfSimpleForumPlugin.lib.model
    columns:

      foo_bar:  varchar(255)
    

    then execute
    symfony propel-build-all
    but looks that northing was changed :-(

Leave a reply