1. Phinx 0.2.3 is out with reversible migrations and much more

    I am really excited to announce Phinx 0.2.3. Phinx has come a long way since it started as a tiny open-source tool I used on a few projects. It has received a stack of contributions and is used by thousands of people from all around the world.

    Phinx now includes some great features including reversible migrations, a verbosity parameter, support for foreign keys and PHP configuration files. I want to talk briefly about the first two today.

    Reversible Migrations

    When using reversible migrations you only need to define the ‘up logic’ and Phinx is smart enough to figure out how to migrate down automatically for you. This feature was inspired by the work tenderlove introduced into Rails 3.1.

    To define a reversible migration you simply add a change method to your migration file and insert the database transformations you require. If Phinx detects the change method it will automatically handle the migration both up and down for you.

    Note: Not all commands can be reversed. Phinx will throw an exception if you try to use an irreversible command.

    Let me demonstrate reversible migrations in an example project. First we create a new migration:

    $ php vendor/bin/phinx create ExampleMigration
    Phinx by Rob Morgan. version 0.2.3
    
    using config file ./phinx.yml
    using config parser yaml
    using migration path /Users/robbym/Sites/webapp/scripts/migrations
    created ./scripts/migrations/20130406160342_example_migration.php
    

    And open it using our text editor. Next I’ll uncomment the change method and add some code to create a simple blog posts table. Here’s the source code for the file:

    Now when combined with the new verbose parameter you can see detailed insight into exactly how long various commands take to execute. This is very handy to benchmark various operations. Let’s run the migration we created using the verbose parameter:

    $ php vendor/bin/phinx migrate -e testing -v
    Phinx by Rob Morgan. version 0.2.3
    
    using config file ./phinx.yml
    using config parser yaml
    using migration path /Users/robbym/Sites/webapp/scripts/migrations
    using environment testing
    using adapter mysql
    using database webapp
    
     == 20130406160342 ExampleMigration: migrating
     -- createTable('posts')
        -> 0.0863s
     == 20130406160342 ExampleMigration: migrated 0.0918s
    
    All Done. Took 0.1215s
    

    And now to showcase the power of reversible migrations we can simply roll it back:

    $ php vendor/bin/phinx rollback -e testing -v
    Phinx by Rob Morgan. version 0.2.3
    
    using config file ./phinx.yml
    using config parser yaml
    using migration path /Users/robbym/Sites/webapp/scripts/migrations
    using environment testing
    
     == 20130406160342 ExampleMigration: reverting
     == 20130406160342 ExampleMigration: reverted 0.0059s
    

    There we have it. Phinx was smart enough to reverse the createTable command and drop it when migrating down. Reversible migrations save you both code and time.

    Both these features bring Phinx in-line with other migration tools and platforms. More information on reversible migrations is available on the official Phinx documentation. Thanks for using my project. If your interested in contributing the GitHub project is here: https://github.com/robmorgan/phinx.

     
  2. Getting Started With Phinx

    Phinx

    Update (21st October, 2012): As Phinx 0.1.4 has now shipped, I have updated this tutorial to work with Composer instead of PEAR.

    Earlier this year I decided to open-source one of my personal software projects - Phinx. Phinx is a database migration tool (think Ruby on Rails ActiveRecord migrations) where can you describe all of your database transformations in pure PHP. I have used this tool for many of my consulting projects, however it still took a lot of effort to turn it into a re-usable product. In this tutorial I’m going to explain how to install Phinx and use it with a simple guestbook application.

    Prerequisites

    This tutorial assumes you have working knowledge of PHP, the Composer dependency manager, Zend Framework 1.x and the MySQL database. You should have a copy of Zend Framework 1.x available in your PHP include path. I have coded the sample application against ZF 1.11.11. It is also assumed you are able to configure your webserver to run the sample application. I have used Mac OS X to develop this tutorial.

    Setup the Sample Application

    I have a sample Guestbook application available on GitHub. Start by cloning the application:

    $ git clone https://github.com/robmorgan/guestbook-tutorial
    

    Next setup your webserver to run the sample application.

    Configure your Database

    Create an empty database called guestbook and open the Guestbook configuration file (application/configs/application.ini). Change the database settings to match your system. Now we are ready to start using Phinx.

    Installation

    First we need to install Phinx. By far the best way is via Composer as a dependency. Create an empty file called composer.json in the root of the guestbook application. Now open this file and change it to look like the following:

    Now run Composer to install Phinx as a dependency:

    $ curl -s https://getcomposer.org/installer | php
    $ php composer.phar install
    

    Phinx will now be available under the vendor/bin/phinx command.

    Making Phinx work with the Sample Application

    Phinx uses a configuration file (phinx.yml) in the root of your project to learn about it’s migrations. The configuration file is a simple YAML-based file. More information is available on the official Phinx documentation site: http://docs.phinx.org/en/latest/configuration.html.

    To Phinx-ify your app, simply run:

    $ php vendor/bin/phinx init
    

    Phinx will create a configuration file with a few defaults, open this file in your text editor. A great feature of Phinx is that it supports multiple environments, by default the development environment is enabled. Edit the development environment settings to match your configuration.

    Next we need to create a directory to store the migrations. Unless specified otherwise Phinx expects a directory called migrations in your project root directory:

    $ mkdir migrations
    

    Now execute the status command to test your database connection.

    $ php vendor/bin/phinx status
    

    Phinx will attempt to connect to your default environment database. If a successful connection is made, then Phinx will create an empty table to store the migration history.

    Creating Your First Migration

    Our sample application is a guestbook. We need to create a table to store the posts. For each post I want to be able to enter a title, message and save the time that it was created. Let’s create a new migration called CreatePostsTable:

    $ php vendor/bin/phinx create CreatePostsTable
    Phinx by Rob Morgan. version 0.1.4
    
    using config ./phinx.yml
    using migration path /Users/robbym/Sites/guestbook/migrations
    created ./migrations/20121013151612_create_posts_table.php
    

    Phinx will create an empty migration file in the migrations directory. Open this file in your text editor. In the up method we will use the Table API to create a new database table. Next in the down method we will simply remove this table. By specifying the reverse of our transformations in the down method we are able to use Phinx’s rollback functionality. It is important to note that Phinx creates an id column by default for every table. More information about this column is available in the Phinx documentation. Your migration file should look like this:

    Transforming the Database

    Now it’s time to execute our newly created database migration. Run Phinx with the migrate command:

    $ php vendor/bin/phinx migrate
    Phinx by Rob Morgan. version 0.1.4
    
    using config ./phinx.yml
    using migration path /Users/robbym/Sites/guestbook/migrations
    warning no environment specified, defaulting to: development
    using adapter mysql
    
     == 20121013151612 CreatePostsTable migrating
     == 20121013151612 CreatePostsTable migrated 1.1352s
    
    All Done. Took 1.1485s
    

    Phinx will connect to your database and execute the CreatePostsTable migration. Now you have successfully migrated your database to the latest version. Therefore we can now use the Guestbook application:

    And that’s it!

    Conclusion

    There we have a brief introduction to getting started with Phinx. You can find out more about the project on it’s website here: http://phinx.org. We are also looking for contributors to close bugs, add features and work on the documentation. If you’d like to help checkout the GitHub project here: http://github.com/robmorgan/phinx.

     
  3. 08:37 21st Jun 2012

    notes: 1

    comments: 0

    tags: phinx

    image: download

    Working on some logo mockups for Phinx

    Working on some logo mockups for Phinx

     
  4. Why Apple Needs to Reinvent the TV

    Personally I can’t wait for Apple to come in and reinvent the television. I envisage they’ll raise the bar like they did with the iPhone and make the market several times more competitive.

    Televisions were invented in the late 1920s and colour came in 1940s. Since then we’ve been subject to a business model pioneered by the television networks. They serve us content, they serve us advertising and we have the ability to pay for premium subscription services (such as Foxtel or Cable) and connect peripheral devices.

    At the moment the price point for TV’s is amazing. You can purchase a 40-inch Full-HD LED LCD for around $600 (AUD). Compare that to 4 years ago when I paid over $5000 (AUD) for 43-inch Semi-HD Plasma screen. Both the industrial design and the hardware is great, but this is not the issue. The issue with TVs is the experience.

    The experience with TV’s is appalling. Every user interface varies between brand and model. There is no consistency in terms of design and frankly it’s pathetic. Let’s talk about a common task such as changing the channel. You pick up a remote and try to hit the impossible bulls-eye. Occasionally you do and then the television takes it’s merry time trying to fulfill your request.

    With the UI aside have you forgotten about the plethora of boxes sitting within your cabinet? Let’s go back to 1993 when TV’s only supported one external device; now we have boxes for just about everything - cable networks, gaming consoles, network media devices, premium subscription services, convertors, boxes to connect more boxes and DVD & Blu-Ray players. It’s ridiculous!

    The Apple TV was important for Apple, because it was their entry into the market. Steve Jobs always claimed it was a ‘hobby’ and they ‘weren’t very serious about it’, but it was a lot more than that. The Apple TV was a market tester. Are consumer’s prepared to pay for content? Do people actually listen to music on their TV’s? Or how about viewing photos? Finally how long do people spend watching TV? The latter question is very relevant. I think we all know the answer and the potential market size.

    Now for the big unknowns. Has Apple thought extremely big? Does what their trying to do require commitment from networks all around the world? It’s quite possible. For example a feature such as trying to replay a TV program straight after it’s broadcast would require permission from the copyright holder.

    Will the Apple Television disrupt the model where content is restricted by markets? At the moment networks purchase programs from content providers after they’ve had widespread success in their local markets. But lets not forget the internet exists today and consumers aren’t prepared to wait 12 months to see what the trending topics on Twitter are all about. They want it now and technologies such as BitTorrent enable this. Could we see a global change to this model across the spectrum? One day they might even go as far as allowing you to determine your own programming. Talk about a total change. All of a sudden you will be dictating your own programming instead of the networks. Going out for dinner later tonight? Then watch the news now instead of at 7:00pm. Video on demand already exists, but not in this capacity.

    Last but not least I’m sure there is another billion dollar App market just waiting to be untapped in the living room. The problem Apple has here though is people aren’t going to get off the couch to touch their TV screens, they’ll have to use an iPad or a new category of device (remote on steroids). TheVerge (http://www.theverge.com/2011/12/18/2645399/apple-working-on-tv-new-interfaces-content-partnerships-wsj) claims people will use their voice which makes sense given the successful launch of Siri. I would love to check the weather, watch those videos I’d saved for later, play a few games or catchup on the news. There is definitely room for an App market here.

    For Apple, reinventing the television makes sense. It extends their walled garden into your living room. They already control your phone, tablet and computer and now they want the 10-foot experience. I hope they have solved all of the problems including creating a universal product that works around the world. I look forward to a product debut in 2012.

     
  5. 12:03 15th Jul 2010

    notes: 19

    comments: 0

    tags: petscatsfunnyvideo

    A determined cat trying to break through an impenetrable cake force field.

     
  6. 22:53 1st Jul 2010

    notes: 12

    comments: 0

    reblogged from: felix-cartal

    clubsetc:

    The Intelligence of Crows

     
  7. 13:59 30th Mar 2010

    notes: 49

    comments: 0

    reblogged from: camh

    tags: ipadappletwitterapp store

    image: download

    camh:

I … I just don’t know anymore.

    camh:

    I … I just don’t know anymore.

     
  8. 15:02 23rd Feb 2010

    notes: 17

    comments: 0

    tags: video

    ‘Embrace Life’ - always wear your seat belt. An original approach to road safety advertising from the Sussex Safer Roads Partnership.

     
  9. Howto Log Directly to Your OS X Terminal using Zend Framework and NodeJS

    Are you interested in being able to log directly to your OS X terminal from within your Zend Framework based app? If yes, then this tutorial may be for you!

    What is Zend Framework and NodeJS

    First of all you may be wondering about Zend Framework and NodeJS? Zend Framework is a PHP 5 based development framework. It is commonly used to build web applications. NodeJS is a tool designed to provide an easy way to build scalable network programs. By using the I/O capabilities of NodeJS, I have built a simple TCP server that writes log messages to the OS X terminal (via STDOUT).

    Getting Started

    First of all you will need to have NodeJS installed. You can follow the instructions on their website: http://nodejs.org/#build. You should also have a basic understanding of how to use Git and GitHub.

    Running the Node_Log Server

    Start by cloning my GitHub repository (http://github.com/robmorgan/node_log) to a working directory on your system and start the server:

    $ git clone git://github.com/robmorgan/node_log.git
    $ cd node_log
    $ /usr/local/bin/node node_log.js
    

    The server will fire up and start listening on the default host and port (tcp://localhost:8003):

    Next we can begin logging events to the Node_Log server.

    Logging Events from your Zend Framework App

    I have written a Zend Framework compatible log writer specifically for Node_Log. It is available here: http://github.com/robmorgan/zfnode_log_writer. You can clone my git repository by executing:

    $ git clone git://github.com/robmorgan/zfnode_log_writer.git
    

    Next you should copy the contents of the library/ directory to the library/ directory within your Zend Framework based app. Now we are ready to log our first event to Node_Log. Simply include Zend_Log and the log writer (ignore the includes if you use the Autoloader) and make a standard logging call. I have provided an example below:

    And here’s what the terminal output looks like:

    Conclusion

    Now you have the ability to log to your OS X terminal direct from your ZF-based app! In the future I plan to add a web interface, color highlighting based on severity and persistence of log messages to disk. Feel free to clone my GitHub repository if you’d like to contribute. Have any questions? Please leave a comment below or follow me on Twitter and @reply me.

     
  10. Software I Use

    Somebody asked me the other day about the software I use. So I decided to make a list and share it around. This list covers desktop, phone and web software and I’ll add to it as I go.

    • Text Editor / Simple Coding Tool: TextMate ($56) is the best by far. I use it to write my blog articles, ruby code and simple text files. I highly recommend buying a license.
    • Web Browser: I use Firefox (Free) with the Firebug (Free) development extension.
    • Email: Gmail (Free) is web-based and also works on my iPhone.
    • IDE: Eclipse (Free) with the Flex Builder ($249) and PDT for PHP (Free) plugins.
    • Image Editing: I’m a developer, but I use Pixelmator ($59) to quickly measure designs, chop images up and convert files between formats. It’s lightning fast compared with Photoshop and Fireworks on my MacBook Pro. Well worth the small price-tag.
    • FTP / SFTP / Amazon S3: Transmit by Panic ($29.95) has proved itself over the years.
    • Blogging: Tumblr (Free) is good and it can host your custom domain name as well for nothing.
    • Web Stats: I’ve always used Google Analytics (Free), but I heard there are a few new good contenders albeit with Twitter, Bit.ly integration etc.
    • Twitter: I use Tweetie on my Macs and iPhone. I’ve found it to be alot faster than TweetDeck as it’s written in Cocoa.
    • Short URL Service: Bit.ly (Free) is ridiculously simple and also provides statistics including referrer and timestamps for tracking your links.
    • Web Proxy: Charles ($50) is an indispensable tool. I use it everyday and it’s saved me so much time. The main features I love about it are the throttling for testing slow connections, decoding of binary AMF data, JSON data, XML support and also the ability to repeat and modify HTTP requests.
    • Music: iTunes (Free).
    • Music Downloads: The iTunes Store and Beatport are my favourites.
    • Music Production / Sharing: I have a premium account on SoundCloud ($14/month). I use this to share my DJ sets, tracks and host my podcast.