-
Notifications
You must be signed in to change notification settings - Fork 13
Patch files
sndpl edited this page Aug 25, 2011
·
1 revision
SQL patches can only contain one or more valid SQL commands.
For example:
-- Remove deprecated column from news table
ALTER TABLE `news` DROP COLUMN `is_published`;
PHP patches should start with <?php and after this line you can add all the PHP code you want. In this file you will also have the $this->db (Zend Db), $this->writer and $this->config objects available.
For example:
<?php
// Convert some id's
$this->writer->line('Start patch 1');
$sql = 'UPDATE `order` SET `total` = `total`+ 1;'
$this->db->query($sql);
DbPatch also checks for comments on the 1st line of your patch file (for PHP patch files it's the second line) and add those to the description field of the db_changelog table. Just make sure to start your patch file with some comment like this:
-
SQL
-- SQL Patch comment # SQL Patch comment different notation
-
PHP
<?php // PHP Patch comment /* PHP Patch comment different notation */
Add START TRANSACTION and COMMIT to your patch file.
DbPatch use the following naming convention:
[patch_prefix]-0000.[sql|php]
Examples:
database/patch/patch-0032.sql
database/patch/patch-032.php
With the config setting 'dbpatch_prefix' you can overwrite the default 'patch' naming.
Example:
database/patch/patchfile-1.6-0012.sql