> pear channel-discover pear.phing.info > pear config-set preferred_state beta > pear install phing / phing
example / | - db / β sql files for database management are stored here | `- deltas / | - deploy / β scripts for migration are stored here | `- scripts / | - library / β here is a developed application `- public / β here indicates the directive DOCUMENT ROOT
# Property files contain key / value pairs # key = value # This dir must contain the local application build.dir = .. / # Credentials for the database migrations db.host = localhost db.user = user db.pass = password db.name = example # paths to programs progs.mysql = / usr / bin / mysql
<? xml version ="1.0" ? >
< project name ="PurpleMonkey" basedir ="." default ="build" >
<!-- Sets the DSTAMP, TSTAMP and TODAY properties -->
< tstamp />
<!-- Load our configuration -->
< property file ="./build.properties" />
<!-- create our migration task -->
< target name ="migrate" description ="Database Migrations" >
<!-- load the dbdeploy task -->
< taskdef
name ="dbdeploy"
classname ="phing.tasks.ext.dbdeploy.DbDeployTask" />
<!--
these two filenames will contain the generated SQL
to do the deploy and roll it back
-->
< property
name ="build.dbdeploy.deployfile"
value ="deploy/scripts/deploy-${DSTAMP}${TSTAMP}.sql" />
< property
name ="build.dbdeploy.undofile"
value ="deploy/scripts/undo-${DSTAMP}${TSTAMP}.sql" />
<!-- generate the deployment scripts -->
< dbdeploy
url ="mysql:host=${db.host};dbname=${db.name}"
userid ="${db.user}"
password ="${db.pass}"
dir ="${build.dir}/db/deltas"
outputfile ="${build.dir}/${build.dbdeploy.deployfile}"
undooutputfile ="${build.dir}/${build.dbdeploy.undofile}" />
<!--
Execute the SQL
Use mysql command line to avoid trouble with large files
or many statements and PDO
-->
< exec
command ="${progs.mysql} -h${db.host} -u${db.user} -p${db.pass} ${db.name} < ${build.dbdeploy.deployfile}"
dir ="${build.dir}"
checkreturn ="true" />
</ target >
</ project >
* This source code was highlighted with Source Code Highlighter .
Field | Type | Comment |
---|---|---|
title | VARCHAR (255) | The title of our post |
time_created | DATETIME | The time we created our post |
content | MEDIUMTEXT | The content of our post |
--//
-- Run SQL to do the changes
--//@UNDO
-- RUN SQL to undo the changes
--//
* This source code was highlighted with Source Code Highlighter .
--//
CREATE TABLE `post` (
`title` VARCHAR (255),
`time_created` DATETIME,
`content` MEDIUMTEXT
);
--//@UNDO
DROP TABLE `post`;
--//
* This source code was highlighted with Source Code Highlighter .
> mysql -hlocalhost -uroot -ppassword example > CREATE TABLE changelog ( change_number BIGINT NOT NULL, delta_set VARCHAR (10) NOT NULL, start_dt TIMESTAMP NOT NULL, complete_dt TIMESTAMP NULL, applied_by VARCHAR (100) NOT NULL, description VARCHAR (500) NOT NULL ); > ALTER TABLE changelog ADD CONSTRAINT Pkchangelog PRIMARY KEY (change_number, delta_set);
> cd deploy > phing migrate
--//
CREATE TABLE `author` (
`author_id` INT (10) unsigned auto_increment,
`name` VARCHAR (255),
PRIMARY KEY (`author_id`)
);
ALTER TABLE `post` ADD `author_id` INT (10) unsigned NULL ;
--//@UNDO
ALTER TABLE `post` DROP `author_id`;
DROP TABLE `author`;
--//
* This source code was highlighted with Source Code Highlighter .
shell> cd deploy shell> phing migrate
Source: https://habr.com/ru/post/63585/