Permalink
Browse files

fixed case where index of one table flows over to other; added schema…

… integration
  • Loading branch information...
1 parent a8a13bc commit 2196e7a1aca614bad83149fc7561484644aaf437 unknown committed Jan 24, 2010
Showing with 945 additions and 887 deletions.
  1. +6 −5 .gitignore
  2. +49 −49 README
  3. +46 −46 config.sample.php
  4. +2 −2 db.bat
  5. +2 −2 db.sh
  6. +840 −783 migrate.php
View
@@ -1,5 +1,6 @@
-migrate/*
-nbproject/*
-config.php
-.xbackup*
-version.php
+migrate/*
+nbproject/*
+config.php
+.xbackup*
+routes.*
+schema.*
View
98 README
@@ -1,49 +1,49 @@
- Ruby on Rails-like database migration management for PHP
- (c) 2009 nickinuse@ofmy.info
- http://github.com/nickinuse/php-migrations
-
- WARNING
-
- Source provided AS-IS and subject to changes, it's advised to test migrations on a temporary database for now.
-
- DESCRIPTION
-
- The main aim of this project is to provide PHP developers with means of creating
- non-SQL based migrations and tools to maintain database changes between developers/
- different project servers/sandboxes and database adaptors.
-
- Whilst there already exist classes and tools for maintaining migrations in PHP,
- very few of them can generate SQL changes through php functions (or do so through
- awfully long class/function names). It was my aim to port most of the syntax and
- functionality from RoR, being the main pioneer of migration-based approach.
-
- WHAT IS A DATABASE MIGRATION?
-
- A migration is a description of changes made to the database [provided in
- the up() method] and means to revert them [provided in the down() method].
- Migrations allow to automate the tedious process of maintaining the current
- state of the database between developers/database interfaces, keep track of changes
- made (with means to undo them if required), make experimenting easy.
-
- FEATURES
-
- * generic helper functions for database independent SQL generation
- (e.g. create_table, t_[basic type] for columns etc.; see db methods)
- * command-line management
- * timestamp-based migration file naming: avoid conflicts between developers
- * transaction-based migration execution: prevent erroneous changes to succeed
- * migration version is stored in a file, which allows easy transfer of migration setup
- (note: it's adviced to exclude version.php from sandbox repositories)
- * open-ended and flexible: provides means to allow for different database adapters,
- convenient ways to specify function parameters (NB: adaptor implementations are welcome)
-
- INSTALLATION/USE
-
- rename config.sample.php to config.php and modify it as prompted in comments
-
- to get started, launch a console in the directory containing migrate.php and launch:
- php -f migrate.php help
- or use the provided convenience shell script
- db help
-
- Have a look at some documentation: http://wiki.github.com/nickinuse/php-migrations
+ Ruby on Rails-like database migration management for PHP
+ (c) 2009 nickinuse@ofmy.info
+ http://github.com/nickinuse/php-migrations
+
+ WARNING
+
+ Source provided AS-IS and subject to changes, it's advised to test migrations on a temporary database for now.
+
+ DESCRIPTION
+
+ The main aim of this project is to provide PHP developers with means of creating
+ non-SQL based migrations and tools to maintain database changes between developers/
+ different project servers/sandboxes and database adaptors.
+
+ Whilst there already exist classes and tools for maintaining migrations in PHP,
+ very few of them can generate SQL changes through php functions (or do so through
+ awfully long class/function names). It was my aim to port most of the syntax and
+ functionality from RoR, being the main pioneer of migration-based approach.
+
+ WHAT IS A DATABASE MIGRATION?
+
+ A migration is a description of changes made to the database [provided in
+ the up() method] and means to revert them [provided in the down() method].
+ Migrations allow to automate the tedious process of maintaining the current
+ state of the database between developers/database interfaces, keep track of changes
+ made (with means to undo them if required), make experimenting easy.
+
+ FEATURES
+
+ * generic helper functions for database independent SQL generation
+ (e.g. create_table, t_[basic type] for columns etc.; see db methods)
+ * command-line management
+ * timestamp-based migration file naming: avoid conflicts between developers
+ * transaction-based migration execution: prevent erroneous changes to succeed
+ * migration version is stored in a file, which allows easy transfer of migration setup
+ (note: it's adviced to exclude version.php from sandbox repositories)
+ * open-ended and flexible: provides means to allow for different database adapters,
+ convenient ways to specify function parameters (NB: adaptor implementations are welcome)
+
+ INSTALLATION/USE
+
+ rename config.sample.php to config.php and modify it as prompted in comments
+
+ to get started, launch a console in the directory containing migrate.php and launch:
+ php -f migrate.php help
+ or use the provided convenience shell script
+ db help
+
+ Have a look at some documentation: http://wiki.github.com/nickinuse/php-migrations
View
@@ -1,46 +1,46 @@
-<?php
-$config=array(
- 'directory'=>'migrate/',//where migrations are stored. don't forget the trailing slash!
-/* possible values (column-type mappings known):
- * db2, mysql, mysqli, openbase, oracle, postgresql, sqlite, sqlserver, sybase
- * only mysql hook provided/checked for now */
- 'adapter'=>'mysql',
- 'host'=>'localhost',
- 'database'=>'test',
- 'user'=>'root',
- 'password'=>'',
- 'escape'=>'`',//character used to escape table/column names
- 'execute'=>true, //whether to actually execute sql or return the dump
-/* name of the function that performs connection/login to your database
- and accepts sql to either execute (default) or echo depending on $config['execute'] */
- 'hook'=>'_sql_hook',
-);
-
-error_reporting(E_ALL);
-//these will translate to e.g. mysql_connect()
-$config['adapter_connect']=$config['adapter'].'_connect';
-$config['adapter_error']=$config['adapter'].'_error';
-$config['adapter_query']=$config['adapter'].'_query';
-$config['adapter_select_db']=$config['adapter'].'_select_db';
-//generic _sql_hook imlementation
-if (!empty($config['execute'])) {
- $config['link'] = $config['adapter_connect']($config['host'], $config['user'], $config['password']);
- if (!$config['link'])
- die('Could not connect: ' . $config['adapter_error']() );
- $db_selected = $config['adapter_select_db']($config['database'], $config['link']);
- if (!$db_selected)
- die ('Can\'t use database : ' . $config['adapter_error']());
-}
-function _sql_hook($sql) {
- global $config;
- if (empty($config['execute']))
- return "\n".$sql;
- $result = $config['adapter_query']($sql);
- if (!$result)
- {
- echo("\n\nInvalid query: ".$config['adapter_error']()."\n");
- $config['rollback']=true;
- }
-}
-?>
-
+<?php
+$config=array(
+ 'directory'=>'migrate/',//where migrations are stored. don't forget the trailing slash!
+/* possible values (column-type mappings known):
+ * db2, mysql, mysqli, openbase, oracle, postgresql, sqlite, sqlserver, sybase
+ * only mysql hook provided/checked for now */
+ 'adapter'=>'mysql',
+ 'host'=>'localhost',
+ 'database'=>'test',
+ 'user'=>'root',
+ 'password'=>'',
+ 'escape'=>'`',//character used to escape table/column names
+ 'execute'=>true, //whether to actually execute sql or return the dump
+/* name of the function that performs connection/login to your database
+ and accepts sql to either execute (default) or echo depending on $config['execute'] */
+ 'hook'=>'_sql_hook',
+);
+
+error_reporting(E_ALL);
+//these will translate to e.g. mysql_connect()
+$config['adapter_connect']=$config['adapter'].'_connect';
+$config['adapter_error']=$config['adapter'].'_error';
+$config['adapter_query']=$config['adapter'].'_query';
+$config['adapter_select_db']=$config['adapter'].'_select_db';
+//generic _sql_hook imlementation
+if (!empty($config['execute'])) {
+ $config['link'] = $config['adapter_connect']($config['host'], $config['user'], $config['password']);
+ if (!$config['link'])
+ die('Could not connect: ' . $config['adapter_error']() );
+ $db_selected = $config['adapter_select_db']($config['database'], $config['link']);
+ if (!$db_selected)
+ die ('Can\'t use database : ' . $config['adapter_error']());
+}
+function _sql_hook($sql) {
+ global $config;
+ if (empty($config['execute']))
+ return "\n".$sql;
+ $result = $config['adapter_query']($sql);
+ if (!$result)
+ {
+ echo("\n\nInvalid query: ".$config['adapter_error']()."\n");
+ $config['rollback']=true;
+ }
+}
+?>
+
View
4 db.bat
@@ -1,3 +1,3 @@
-@echo off
-php -f migrate.php %1 %2 %3 %4 %5 %6 %7 %8 %9
+@echo off
+php -f migrate.php %1 %2 %3 %4 %5 %6 %7 %8 %9
@echo on
View
4 db.sh
@@ -1,2 +1,2 @@
-#!/bin/bash
-php -f migrate.php $*
+#!/bin/bash
+php -f migrate.php $*
Oops, something went wrong.

0 comments on commit 2196e7a

Please sign in to comment.