Permalink
Browse files

base

  • Loading branch information...
0 parents commit 2cae0e15b8da1b2556e47132ab3acc53fec77816 @ruckus ruckus committed Nov 3, 2010
Showing with 7,322 additions and 0 deletions.
  1. +17 −0 LICENSE.txt
  2. +22 −0 README.txt
  3. BIN config/.DS_Store
  4. +30 −0 config/config.inc.php
  5. +30 −0 config/database.inc.php
  6. BIN db/.DS_Store
  7. BIN db/migrate/.DS_Store
  8. +96 −0 generate.php
  9. +51 −0 lib/classes/Ruckusing_exceptions.php
  10. +720 −0 lib/classes/adapters/class.Ruckusing_MySQLAdapter.php
  11. +288 −0 lib/classes/adapters/class.Ruckusing_MySQLTableDefinition.php
  12. +40 −0 lib/classes/class.Ruckusing_BaseAdapter.php
  13. +83 −0 lib/classes/class.Ruckusing_BaseMigration.php
  14. +246 −0 lib/classes/class.Ruckusing_FrameworkRunner.php
  15. +9 −0 lib/classes/class.Ruckusing_TableDefinition.php
  16. +35 −0 lib/classes/class.Ruckusing_iAdapter.php
  17. +112 −0 lib/classes/task/class.Ruckusing_TaskManager.php
  18. +11 −0 lib/classes/task/class.Ruckusing_iTask.php
  19. +41 −0 lib/classes/util/class.Ruckusing_Logger.php
  20. +194 −0 lib/classes/util/class.Ruckusing_MigratorUtil.php
  21. +93 −0 lib/classes/util/class.Ruckusing_NamingUtil.php
  22. +174 −0 lib/tasks/class.Ruckusing_DB_Migrate.php
  23. +37 −0 lib/tasks/class.Ruckusing_DB_Schema.php
  24. +38 −0 lib/tasks/class.Ruckusing_DB_Setup.php
  25. +52 −0 lib/tasks/class.Ruckusing_DB_Version.php
  26. BIN logs/.DS_Store
  27. +1,602 −0 logs/development.log
  28. +13 −0 main.php
  29. BIN tests/.DS_Store
  30. +1 −0 tests/dummy/class.Ruckusing_DB_Setup.php
  31. +1 −0 tests/dummy/db/migrate/001_CreateUsers.php
  32. +1 −0 tests/dummy/db/migrate/003_AddIndexToBlogs.php
  33. 0 tests/dummy/db/migrate/20090122193325_AddNewTable.php
  34. 0 tests/dummy/db/migrate/dummy.php
  35. 0 tests/dummy/db/schema.txt
  36. BIN tests/logs/.DS_Store
  37. +2,495 −0 tests/logs/test.log
  38. +26 −0 tests/test_helper.php
  39. +214 −0 tests/unit/MigratorUtilTest.php
  40. +311 −0 tests/unit/MySQLAdapterTest.php
  41. +104 −0 tests/unit/MySQLTableDefinitionTest.php
  42. +73 −0 tests/unit/NamingUtilTest.php
  43. +34 −0 tests/unit/TaskManagerTest.php
  44. +28 −0 update_ruckusing_database.php
@@ -0,0 +1,17 @@
+Ruckus Migrator
+
+Copyright (C) 2007, Cody Caughlan (codycaughlan % gmail . com)
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
@@ -0,0 +1,22 @@
+== License ==
+See LICENSE.txt.
+
+== Author ==
+Cody Caughlan <codycaughlan % gmail . com>
+
+== Intro ==
+
+This package contains a basic framework for creating and running PHP DB migrations. The idea is borrowed from Ruby on Rails migrations, which allow one to use a series of named files to express the state of the DB at any one time.
+
+== Requirements ==
+
+PHP5 or above.
+
+== Optional ==
+
+PHPUnit (optional): if you want to run the provided test-suite
+ Source: http://www.phpunit.de/
+
+
+== Usage ==
+See the Wiki: http://code.google.com/p/ruckusing/w/list
Binary file not shown.
@@ -0,0 +1,30 @@
+<?php
+
+//--------------------------------------------
+//Overall file system configuration paths
+//--------------------------------------------
+
+//These might already be defined, so wrap them in checks
+
+
+// DB table where the version info is stored
+if(!defined('RUCKUSING_SCHEMA_TBL_NAME')) {
+ define('RUCKUSING_SCHEMA_TBL_NAME', 'schema_info');
+}
+
+if(!defined('RUCKUSING_TS_SCHEMA_TBL_NAME')) {
+ define('RUCKUSING_TS_SCHEMA_TBL_NAME', 'schema_migrations');
+}
+
+//Parent of migrations directory.
+//Where schema.txt will be placed when 'db:schema' is executed
+if(!defined('RUCKUSING_DB_DIR')) {
+ define('RUCKUSING_DB_DIR', RUCKUSING_BASE . '/db');
+}
+
+//Where the actual migrations reside
+if(!defined('RUCKUSING_MIGRATION_DIR')) {
+ define('RUCKUSING_MIGRATION_DIR', RUCKUSING_DB_DIR . '/migrate');
+}
+
+?>
@@ -0,0 +1,30 @@
+<?php
+
+
+//----------------------------
+// DATABASE CONFIGURATION
+//----------------------------
+$ruckusing_db_config = array(
+
+ 'development' => array(
+ 'type' => 'mysql',
+ 'host' => 'localhost',
+ 'port' => 3306,
+ 'database' => 'ruckusing_migrations',
+ 'user' => 'root',
+ 'password' => ''
+ ),
+
+ 'test' => array(
+ 'type' => 'mysql',
+ 'host' => 'localhost',
+ 'port' => 3306,
+ 'database' => 'ruckusing_migrations_test',
+ 'user' => 'root',
+ 'password' => ''
+ )
+
+);
+
+
+?>
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,96 @@
+<?php
+
+/*
+ Generator for migrations.
+ Usage: php generate.php <migration name>
+ Call with no arguments to see usage info.
+*/
+
+
+define('RUCKUSING_BASE', realpath(dirname(__FILE__)));
+require_once RUCKUSING_BASE . '/config/config.inc.php';
+require_once RUCKUSING_BASE . '/lib/classes/util/class.Ruckusing_NamingUtil.php';
+require_once RUCKUSING_BASE . '/lib/classes/util/class.Ruckusing_MigratorUtil.php';
+
+$args = parse_args($argv);
+main($args);
+
+
+//-------------------
+
+/*
+ Parse command line arguments.
+*/
+function parse_args($argv) {
+ $num_args = count($argv);
+ if($num_args < 2) {
+ print_help(true);
+ }
+ $migration_name = $argv[1];
+ return array('name' => $migration_name);
+}
+
+
+/*
+ Print a usage scenario for this script.
+ Optionally take a boolean on whether to immediately die or not.
+*/
+function print_help($exit = false) {
+ echo "\nusage: php generate.php <migration name>\n\n";
+ echo "\tWhere <migration name> is a descriptive name of the migration, joined with underscores.\n";
+ echo "\tExamples: add_index_to_users | create_users_table | remove_pending_users\n\n";
+ if($exit) { exit; }
+}
+
+function main($args) {
+ //input sanity check
+ if(!is_array($args) || (is_array($args) && !array_key_exists('name', $args)) ) {
+ print_help(true);
+ }
+ $migration_name = $args['name'];
+
+ //clear any filesystem stats cache
+ clearstatcache();
+
+ //check to make sure our migration directory exists
+ if(!is_dir(RUCKUSING_MIGRATION_DIR)) {
+ die_with_error("ERROR: migration directory '" . RUCKUSING_MIGRATION_DIR . "' does not exist. Specify MIGRATION_DIR in config/config.inc.php and try again.");
+ }
+
+ //generate a complete migration file
+ $next_version = Ruckusing_MigratorUtil::generate_timestamp();
+ $klass = Ruckusing_NamingUtil::camelcase($migration_name);
+ $file_name = $next_version . '_' . $klass . '.php';
+ $full_path = realpath(RUCKUSING_MIGRATION_DIR) . '/' . $file_name;
+ $template_str = get_template($klass);
+
+ //check to make sure our destination directory is writable
+ if(!is_writable(RUCKUSING_MIGRATION_DIR . '/')) {
+ die_with_error("ERROR: migration directory '" . RUCKUSING_MIGRATION_DIR . "' is not writable by the current user. Check permissions and try again.");
+ }
+
+ //write it out!
+ $file_result = file_put_contents($full_path, $template_str);
+ if($file_result === FALSE) {
+ die_with_error("Error writing to migrations directory/file. Do you have sufficient privileges?");
+ } else {
+ echo "\nCreated migration: {$file_name}\n\n";
+ }
+}
+
+function die_with_error($str) {
+ die("\n{$str}\n");
+}
+
+function get_template($klass) {
+$template = <<<TPL
+<?php\n
+class $klass extends Ruckusing_BaseMigration {\n\n\tpublic function up() {\n\n\t}//up()
+\n\tpublic function down() {\n\n\t}//down()
+}
+?>
+TPL;
+return $template;
+}
+
+?>
@@ -0,0 +1,51 @@
+<?php
+
+class Ruckusing_MissingSchemaInfoTableException extends Exception {
+ public function __construct ( $msg = '', $code = 0 ) {
+ parent::__construct ( $msg, $code );
+ }
+}
+class Ruckusing_MissingMigrationDirException extends Exception {
+ public function __construct ( $msg = '', $code = 0 ) {
+ parent::__construct ( $msg, $code );
+ }
+}
+class Ruckusing_MissingTableException extends Exception {
+ public function __construct ( $msg = '', $code = 0 ) {
+ parent::__construct ( $msg, $code );
+ }
+}
+class Ruckusing_MissingAdapterException extends Exception {
+ public function __construct ( $msg = '', $code = 0 ) {
+ parent::__construct ( $msg, $code );
+ }
+}
+class Ruckusing_ArgumentException extends Exception {
+ public function __construct ( $msg = '', $code = 0 ) {
+ parent::__construct ( $msg, $code );
+ }
+}
+class Ruckusing_InvalidTableDefinitionException extends Exception {
+ public function __construct ( $msg = '', $code = 0 ) {
+ parent::__construct ( $msg, $code );
+ }
+}
+
+class Ruckusing_InvalidColumnTypeException extends Exception {
+ public function __construct ( $msg = '', $code = 0 ) {
+ parent::__construct ( $msg, $code );
+ }
+}
+class Ruckusing_MissingAdapterTypeException extends Exception {
+ public function __construct ( $msg = '', $code = 0 ) {
+ parent::__construct ( $msg, $code );
+ }
+}
+class Ruckusing_SQLException extends Exception {
+ public function __construct ( $msg = '', $code = 0 ) {
+ parent::__construct ( $msg, $code );
+ }
+}
+
+
+?>
Oops, something went wrong.

0 comments on commit 2cae0e1

Please sign in to comment.