summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrion Vibber <brion@pobox.com>2010-10-07 16:49:15 -0700
committerBrion Vibber <brion@pobox.com>2010-10-07 16:49:15 -0700
commit82e9a2eee8ca7b71f6ab81f6c787997e01b75492 (patch)
tree1f6440ff6cd0d290a79aaf9cfbcd4b7fb1487565
parent312b87ea79659b168bdc9569b735253d77994530 (diff)
Add --diff option to dumpschema.php to run a (quickie text) diff betwen the theoretical and detected schemas for the given tables
-rw-r--r--scripts/dumpschema.php50
1 files changed, 46 insertions, 4 deletions
diff --git a/scripts/dumpschema.php b/scripts/dumpschema.php
index 8b5277517..642aedf5f 100644
--- a/scripts/dumpschema.php
+++ b/scripts/dumpschema.php
@@ -25,6 +25,7 @@ Attempt to pull a schema definition for a given table.
END_OF_CHECKSCHEMA_HELP;
+$longoptions = array('diff');
require_once INSTALLDIR.'/scripts/commandline.inc';
function indentOptions($indent)
@@ -79,17 +80,58 @@ function prettyDumpArray($arr, $key=null, $indent=0)
}
}
-function dumpTable($tableName)
+function getCoreSchema($tableName)
{
- $schema = Schema::get();
- $def = $schema->getTableDef($tableName);
+ $schema = array();
+ include INSTALLDIR . '/db/core.php';
+ return $schema[$tableName];
+}
+
+function dumpTable($tableName, $live)
+{
+ if ($live) {
+ $schema = Schema::get();
+ $def = $schema->getTableDef($tableName);
+ } else {
+ // hack
+ $def = getCoreSchema($tableName);
+ }
prettyDumpArray($def, $tableName);
echo "\n";
}
+function showDiff($a, $b)
+{
+ $fnameA = tempnam(sys_get_temp_dir(), 'diff-a');
+ file_put_contents($fnameA, $a);
+
+ $fnameB = tempnam(sys_get_temp_dir(), 'diff-b');
+ file_put_contents($fnameB, $b);
+
+ $cmd = sprintf('diff -U 100 %s %s',
+ escapeshellarg($fnameA),
+ escapeshellarg($fnameB));
+ passthru($cmd);
+
+ unlink($fnameA);
+ unlink($fnameB);
+}
+
if (count($args)) {
foreach ($args as $tableName) {
- dumpTable($tableName);
+ if (have_option('diff')) {
+ ob_start();
+ dumpTable($tableName, false);
+ $defined = ob_get_clean();
+
+ ob_start();
+ dumpTable($tableName, true);
+ $detected = ob_get_clean();
+
+ showDiff($defined, $detected);
+ } else {
+ dumpTable($tableName, true);
+ }
}
} else {
show_help($helptext);