CakePHP schema checker

If you have seen the previous tool I built for converting raw SQL to CakePHP code you might have an idea what is coming. There was good feedback from the initial tool so I have built something similar for people migrating legacy apps and newcomers alike.

Instead of conversions, this time it helps find specific errors in your schema. For example if you are using a field like user_id it will expect there to be a users table. It will also warn about fields that are not cased correctly such as UserID or userId vs user_id.

This tool makes use of the Inflector class for working out if fields and tables are named correctly, and then attempts to link up models based on the fields in the schema much like bake would do.

Currently I am sure that this does not cover every possible case, so let me know if you spot anything that should be covered. Some cases will be virtually impossible to cover, for example if you are using a field called user_primary_key there is no way to know it should be user_id. With regards to foreign key usage in CakePHP they should always end with _id. All database tables and fields should be lowercase, with tables being plural.

This tool has been designed to work with a dump from phpmyadmin, without data. Just select export and then select 'structure only' option. Fields and tables should be wrapped in back ticks `.

Once it runs, a table is shown with all the models and relations. Errors are highlighted with the following key.

Here are some examples of a good and bad CakePHP schema. The good variant is a dump from Croogo while the bad variant is from Cacti, a PHP based server monitoring tool that is not built using CakePHP.

Schema checker


No more posts