Friday, July 17, 2009

Announcing MP: Migrations for PHP

As my latest project has grown to need multiple developers, we have started to run into some friction in managing concurrent database changes. Over the last few months I've done a bunch of research on migrations infrastructure, including rails migrations, CakePHP migrations, and several other less-popular implementations.

None of them were perfect for my needs and since the architecture for migrations is pretty simple, I decided to write my own and open-source the results, a php migrations infrastructure called MP.

A few of the features I wanted in MP:
  • Easy-to-use
  • 100% PHP 5+ implementation
  • Command-line utility
  • API access for integration into existing apps, frameworks, or ORMs.
  • Ability to execute arbitrary code in each migration
  • Rollback capabilities
  • "Clean" option to rebuild app state from scratch
  • Persist current version in a file or in DB
  • Prevent collisions of migrations
  • Automatically preserve migrations order without manual sorting effort
Getting Started with MP
One you download mp, you can migration-enable your application in moments:

$ cd myproject

# Migration-enable myproject by creating a first migration
$ mp -c create
MP - The PHP Migrator.
Created migration 20090717_014019 at ./migrations/20090717_014019.php.

# migrate to latest migration
$ mp
MP - The PHP Migrator.

Upgrading from version 0 to 20090717_014019.
Running Upgrade: Migration created at 20090717_014019.
Upgrading to 20090717_014019 succeeded.

To implement the specifics of your migration code, just edit the corresponding migration file's up() method.

Integration
MP's API is intended as an integration point for frameworks to be able to directly implement migrations support without having to write a migrations infrastructure from scratch. Your framework's CLI utilities can programmatically configure, execute and create migrations easily. MP can also be configured with a delegate class to which all migrations have access, making it easy to bootstrap your framework before running migrations so that all of your framework's infrastructure is available for use inside the migrations with no additional effort.

Conclusion
I hope that MP can become a widely adoption standard for php migrations. I will continue to work on it and integrate it into the PHOCOA php framework and also add support for SQL migrations with Propel.

Friday, July 10, 2009

Getting postfix to relay mail through authenicated SMTP

If you're like nearly everyone out there, your home computer network has port 25 blocked by your ISP. Sadly this means that you can't easily use postfix or sendmail to deliver messages. They just pile up in your mail queue.






I have replicated the info here because it's so useful that I don't want to lose it if that link ever goes dead.


  1. Call your ISP and get your email credentials for SMTP. Typically you'll need the SMTP server, username, password, and port number.


  2. Edit /etc/postfix/main.cf:

    relayhost = [smtp.comcast.net]:587
    smtp_sasl_auth_enable = yes
    smtp_sasl_password_maps = hash:/etc/postfix/sasl/passwd
    smtp_sasl_security_options =



  3. Create dir /etc/postfix/sasl if needed then edit file /etc/postfix/sasl/passwd:


    smtp.comcast.net myusername:mypassword



  4. Fix permissions:

    chown root:root /etc/postfix/sasl/passwd;
    chmod 600 /etc/postfix/sasl/passwd
    postmap /etc/postfix/sasl/passwd
    postfix reload



That's it! Blissfully perfect sendmail from now on.