Classes for a DB interface and to automate DB migration

Coding Critique is the place to post source code for peer review by other members of DevNetwork. Any kind of code can be posted. Code posted does not have to be limited to PHP. All members are invited to contribute constructive criticism with the goal of improving the code. Posted code should include some background information about it and what areas you specifically would like help with.

Popular code excerpts may be moved to "Code Snippets" by the moderators.

Moderator: General Moderators

Post Reply
jarofgreen
Forum Commoner
Posts: 71
Joined: Sun Jul 11, 2010 12:40 pm

Classes for a DB interface and to automate DB migration

Post by jarofgreen »

This is in early stages, but I'm still keen to get feedback and comments. If others wanted to use it and submit improvements back, that's even better! :-) It's all BSD Licensed.

The Base class for the DB interface:
http://elastik.svn.sourceforge.net/view ... iew=markup
This grew organically rather than being designed, so some of the names aren't consistent or great – something to fix.

So far there are adaptors for MySQL and MS SQL Server:
http://elastik.svn.sourceforge.net/view ... iew=markup
http://elastik.svn.sourceforge.net/view ... iew=markup

Then the Base class for a Migration:
http://elastik.svn.sourceforge.net/view ... iew=markup

A typical migration looks like:
http://elastik.svn.sourceforge.net/view ... iew=markup
Every DB migration is tracked by date, which makes it easy to have multiple branches of code development with migrations on each one and merge them together later.

And the class to actually perform the migrations:
http://elastik.svn.sourceforge.net/view ... iew=markup
The system it comes from has modules and a core system, so it looks for Migrations in both places and sorts them all together.

Hopefully that's not to much code; sorry …

There is no create schema yet; at the moment it creates the DB from scratch by running through all migrations.

There is also no migrateDown process yet. Personally, while I can see it would be handy I've not been convinced that they are an essential feature. I mean, you did back up the DB before migration, right? I think part of my reluctance will disappear when I work out a neat way of unit testing them.

Anyway, any comments or feedback welcome ….
Thanks,
James
Post Reply