Version Control, Migrations and Deployment

And Other Things. »
Rob Howard

Operations on a database,
grouped, stored and
versioned as files.
r76
r75
r77
r78
+ libraries/CIModuleFox8UserProfile.php
+ libraries/CIModuleFox8ShowNavigation.php
+ views/module-content_page_show_nav.php
+ migrations/201007032359.vanilla_contentpage_alt_title.php
+ libraries/CIModuleFox8Video.php
+ migrations/201007041100.video_second_level_tagging.php
+ models/Cms_model.php
Each Migration is a
class that defines operations
in two "directions".
UP
...
0.5
0.4
0.3
0.2
0.1
ALTER TABLE `pages`
ADD COLUMN `alt_title`;
INSERT INTO `cms_objects`
VALUES (13142995, 'example_obj', ...);
DOWN
0.5
0.4
0.3
0.2
...
ALTER TABLE `pages_list`
DROP COLUMN `alt_title`
DELETE FROM `cms_objects`
WHERE id = 13142995   
UP is immediately useful.
DOWN is risk reduction.

(DOWN gives you room to
move if a deployment
goes pear-shaped.)
GOTCHAS!
Don't rely on code outside the migrations, eg. models.
The surrounding system's code will change.
Old migrations will stop working with new code; more later.
Database Migrations
But you still have to run
these things manually...
... And hope no-one's
looking while you're
running them.
Automate build, and you
get the foundations for easy:
Separated
Dev Systems
Deployment
Set up a system with defaults, eg. VanillaCMS, the FOX8 Site.
Sets up VHost records.
Creates database.
Imports default database.
Performs any "publishing" steps as needed.
Applies all pending (checked-in) migrations.

<?php

class m201007121337_AddAltTitleToPage extends CDbMigration
{
    public function up() {
        $this->addColumn('pages', 'alt_title', 'string');
        $sCopyTitlesSQL = 'UPDATE pages SET alt_title = title';
        $this->execute($sCopyTitlesSQL);
    }

    public function down() {
        //...
    }
}
Automated Builds
Deploy.

You have your own dev system.
Automated
Testing
Deploy (or redeploy) as per your dev systems.
Automatic upgrades for your dev/testing sites as you go.
PHP-Based build engine
with a silly composite
acronym for a name.
PHING
For Example
Targets
Targets are collections of Tasks, eg.
$ phing -Drevision=1149 fox8_staging
Local subversion checkout at r1149.
Rsync files from local to remote.
Subversion update on remote directly.
OR
Run migrations.
Run a shell command.
Import a database.
Append text to the end of a file.
Push files via FTP or RSync.
Custom block of PHP.
<target name="fox8_deploy_dev" if="svn_host,site_name,site_rev,ci_rev,cms_rev">
       <echo msg="Deploying FOX8 dev system for ${site_name} ..." />
       <svncheckout repositoryurl="svn://${svn_host}/clients/FOX8/www"
             todir="/var/www/domains/fox8/dev_sites/${site_name}"
             revision="${svn_site_rev}"/>
       <exec command="/etc/init.d/httpd configtest" />
       ...
The End Result
One-command deployment of a system,
with configuration, default data,
and a way automatically update
both code and database.
That's kinda cool.
This is what.
Development is Branched.
Problems
NEW TABLES
NEW COLUMNS
REMOVED TABLES
REMOVED COLUMNS
ROW DATA
TRANSFORMS
PACKAGES OF ROWS FROM VANILLACMS
USE FOX8 LIVE DB AS THE DEFAULT
DATA SET FOR NEW DEPLOYMENTS
FURTHER DATABASE "CONFIGURATION" CHANGES DONE VIA MIGRATIONS
Deployment is Linear.
ANTM Hero Video
Fantasy Tipping
FOXM8 Forums
VanillaCMS Internals Revamp
More Problems
Bio Module
Fantasy Tipping
ANTM Hero
Fantasy Tipping
...
"Can we push ANTM Hero?"
"Nope. Fantasy Tipping isn't done yet."
Following the Rules
Our Workaround
Pick files out of the repository, test it on Staging,
and hope it doesn't break.
Tipping
Bio Moduel
...
Tipping
ANTM Hero
Staging
Live
Nasty Side-Effects
Cherry-picking files ad-hoc out of the repo
prevents us from automating anything.
How do we deal
with this?
Create a Deployment Branch
ANTM Hero
Go-Live
Fantasy Tipping
Go-Live
Very lah-dee-day
pie in the sky.
So what?
Development Branch
Deployment Branch
Database Migrations
Deepend Sydney
Rob Howard, 2010
.... And a Few Other Things.
Orangutans
Fruitbats
Breakfast Cereals
Subversion
Deployments
Unicorns
A Revised Go-Live Process
During and at the end of development, commit code files and database migrations into the Development trunk as usual.
Start the Go-Live: merge selected files into the Deployment branch.
Deploys files and database changes to Staging.
phing -Drevision 149 fox8_staging
Deploys files and database changes to Live.
Is intentionally an exact repeat of the push to Staging.
Test changes on staging.
phing -Drevision 149 fox8_live
Test changes on live.
Throw a party.
Exeunt.

Loading comments...

Please log in to add your comment.

Report abuse