X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=scripts%2Fdumpschema.php;h=9c5e3cf8b38c2fd9808803ba9c2c8437fcddfb89;hb=0dbdcf2936a00282114f1368ead2f5edebc6ae61;hp=cab02d910e6575097d16b49aba0107097c216f7b;hpb=a421dd934aeb4a1064608bdeca44b5b5986e7358;p=quix0rs-gnu-social.git diff --git a/scripts/dumpschema.php b/scripts/dumpschema.php index cab02d910e..9c5e3cf8b3 100644 --- a/scripts/dumpschema.php +++ b/scripts/dumpschema.php @@ -26,13 +26,14 @@ Attempt to pull a schema definition for a given table. --all run over all defined core tables --diff show differences between the expected and live table defs --raw skip compatibility filtering for diffs - --update dump SQL that would be run to update or create this table + --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', 'build', 'update', 'raw'); +$longoptions = array('diff', 'all', 'create', 'update', 'raw', 'checksum'); require_once INSTALLDIR.'/scripts/commandline.inc'; function indentOptions($indent) @@ -154,7 +155,7 @@ function dumpDiff($tableName, $filter) $old = $schema->getTableDef($tableName); } catch (Exception $e) { // @fixme this is a terrible check :D - if (preg_match('/no such table/', $e->getMessage())) { + if (preg_match('/no such table/i', $e->getMessage())) { return dumpTable($tableName, false); } else { throw $e; @@ -162,7 +163,7 @@ function dumpDiff($tableName, $filter) } if ($filter) { - $old = $schema->filterDef($old); + //$old = $schema->filterDef($old); $def = $schema->filterDef($def); } @@ -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(); } @@ -215,10 +238,12 @@ if (count($args)) { foreach ($args as $tableName) { if (have_option('diff')) { dumpDiff($tableName, !have_option('raw')); - } else if (have_option('build')) { + } else if (have_option('create')) { dumpBuildTable($tableName); } else if (have_option('update')) { dumpEnsureTable($tableName); + } else if (have_option('checksum')) { + dumpChecksum($tableName); } else { dumpTable($tableName, true); }