]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - scripts/dumpschema.php
Merge remote-tracking branch 'upstream/master' into social-master
[quix0rs-gnu-social.git] / scripts / dumpschema.php
old mode 100644 (file)
new mode 100755 (executable)
index 6133644..05638cd
@@ -28,12 +28,13 @@ Attempt to pull a schema definition for a given table.
   --raw     skip compatibility filtering for diffs
   --create  dump SQL that would be run to update or create this table
   --build   dump SQL that would be run to create this table fresh
+  --checksum just output checksums from the source schema defs
 
 
 END_OF_CHECKSCHEMA_HELP;
 
-$longoptions = array('diff', 'all', 'create', 'update', 'raw');
-require_once INSTALLDIR.'/scripts/commandline.inc';
+$longoptions = array('diff', 'all', 'create', 'update', 'raw', 'checksum');
+require_once INSTALLDIR.'/scripts/commandline.inc.php';
 
 function indentOptions($indent)
 {
@@ -176,7 +177,7 @@ function dumpDiff($tableName, $filter)
         if ($section == 'fields') {
             // this shouldn't be needed maybe... wait what?
         }
-        $diff = $schema->diffArrays($old, $def, $section, $compare);
+        $diff = $schema->diffArrays($old, $def, $section);
         $chunks = array('del', 'mod', 'add');
         foreach ($chunks as $chunk) {
             if ($diff[$chunk]) {
@@ -204,9 +205,31 @@ function tweakPrimaryKey($def)
         $def['primary keys'] = array('primary key' => $def['primary key']);
         unset($def['primary key']);
     }
+    if (isset($def['description'])) {
+        $def['descriptions'] = array('description' => $def['description']);
+        unset($def['description']);
+    }
     return $def;
 }
 
+function dumpChecksum($tableName)
+{
+    $schema = Schema::get();
+    $def = getCoreSchema($tableName);
+
+    $updater = new SchemaUpdater($schema);
+    $checksum = $updater->checksum($def);
+    $old = @$updater->checksums[$tableName];
+
+    if ($old == $checksum) {
+        echo "OK  $checksum $tableName\n";
+    } else if (!$old) {
+        echo "NEW $checksum $tableName\n";
+    } else {
+        echo "MOD $checksum $tableName (was $old)\n";
+    }
+}
+
 if (have_option('all')) {
     $args = getCoreTables();
 }
@@ -219,10 +242,12 @@ if (count($args)) {
             dumpBuildTable($tableName);
         } else if (have_option('update')) {
             dumpEnsureTable($tableName);
+        } else if (have_option('checksum')) {
+            dumpChecksum($tableName);
         } else {
             dumpTable($tableName, true);
         }
     }
 } else {
     show_help($helptext);
-}
\ No newline at end of file
+}