feature: Added ability to validate database schema (#6303)

* feature: Added ability to validate database schema

* small scrut fixes

* Check for extra tables and columns
Print 30 items of schema updates, easier to copy paste sql

* Now supports detections and suggested fix for:
tables: missing, extra
columns: missing, extra, incorrect
indexes: missing, extra, incorrect

* final changes + hook into travis
This commit is contained in:
Neil Lathwood
2017-04-05 09:00:28 +01:00
committed by GitHub
parent 18784fdb89
commit 03deb6434a
6 changed files with 1797 additions and 1 deletions

33
scripts/build-schema.php Executable file
View File

@@ -0,0 +1,33 @@
#!/usr/bin/env php
<?php
$install_dir = realpath(__DIR__ . '/..');
if (getenv('DBTEST')) {
if (!is_file($install_dir . '/config.php')) {
exec("cp $install_dir/tests/config/config.test.php $install_dir/config.php");
$create_db = true;
}
}
$init_modules = array();
require realpath(__DIR__ . '/..') . '/includes/init.php';
if (getenv('DBTEST')) {
if ($create_db === true) {
$sql_mode = dbFetchCell("SELECT @@global.sql_mode as sql_mode");
dbQuery("SET NAMES 'utf8'");
dbQuery("SET CHARACTER SET 'utf8'");
dbQuery("SET COLLATION_CONNECTION = 'utf8_unicode_ci'");
dbQuery("SET GLOBAL sql_mode='ONLY_FULL_GROUP_BY,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'");
dbQuery("USE " . $config['db_name']);
$build_base = $config['install_dir'] . '/build-base.php';
exec($build_base, $schema);
}
sleep(60);//Sleep for 60 seconds to ensure db work has completed
$output = dump_db_schema();
echo Symfony\Component\Yaml\Yaml::dump($output, 3, 2);
}

14
scripts/deploy-schema.sh Executable file
View File

@@ -0,0 +1,14 @@
#!/bin/bash
GH_REPO="@github.com/librenms/librenms.git"
FULL_REPO="https://${GH_TOKEN}$GH_REPO"
git config user.name "librenms"
git config user.email "travis@librenms.org"
DBTEST=1 ./scripts/build-schema.php > misc/db_schema.yaml
STATUS=$(git status -s misc/db_schema.yaml)
if [[ "$STATUS" != "" ]]; then
git commit -m "DB Schema updated by travis after $TRAVIS_COMMIT"
git push -q origin master
fi