librenms/scripts/build-schema.php
Tony Murray b1483e3d2e feature: Unit test to validate the db schema (#6367)
* Unit test to validate the db schema
Changes build-schema.php to just write misc/db_schema.yaml

* Only build base if needed
Fix 178.sql

* Database is always created by init.php
add dbSchema test too, should guard against testing against an empty database

* feature: support non-standard unix socket (#5724)

* Add support for custom MySQL unix-socket

* NULL must be lowercase!

* Naive edit of html/install.php

* fixup

* Refactor dbConnect
Use it everywhere

* $config needs to be global
Don't need to set $database_link

* small cleanups

* Connect to the database for every test.

* travis fix for blank line
2017-04-07 15:07:44 +01:00

37 lines
1.2 KiB
PHP
Executable File

#!/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
}
$file = $install_dir . '/misc/db_schema.yaml';
$yaml = Symfony\Component\Yaml\Yaml::dump(dump_db_schema(), 3, 2);
if (file_put_contents($file, $yaml)) {
echo "Updated!\n";
}