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.
Comments(1)