zortje/mysql-keeper

Find incorrect configurations or missed optimization opportunities in MySQL databases

0.4.0 2015-02-22 00:33 UTC

This package is not auto-updated.

Last update: 2024-04-13 14:50:21 UTC


README

Find incorrect configurations or missed optimization opportunities in MySQL databases.

Packagist Travis branch Scrutinizer branch Scrutinizer Dependency Status Packagist

SensioLabsInsight

Features

Detects the following issues

  • Duplicate indices
  • Missing primary key on auto_increment column
  • Redundant unique index on primary key
  • Redundant key index on primary key
  • Inconsistent usage of collation between table and columns

Installing via Composer

The recommended way to install MySQL Keeper is though Composer.

{
    "require": {
        "zortje/mysql-keeper": "~0.0"
    }
}

Usage

$pdo = new PDO('mysql:host=127.0.0.1;dbname=myapp', 'root', '');

$database = DatabaseFactory::create($pdo);
$databaseResult = $database->getResult();

The $databaseResult array will look something like this with the first level keys being table names.

[
	'users' => [
		'issues' => [
			[
				'type' => 'field',
				'field' => 'id',
				'description' => 'Set as auto_increment but has no primary key'
			],
			[
				'type' => 'field',
				'field' => 'id',
				'description' => 'Set as auto_increment but is not set as primary'
			]
		],
		'optimizations' => [
			[
				'type' => 'field',
				'field' => 'id',
				'description' => 'Field should be unsigned, as no field values are negative'
			]
		]
	]
];

Usage with Melody

Melody allows inline Composer requirements to simply execute PHP scripts.

mysql-keeper_myapp.php

<?php

<<<CONFIG
packages:
    - "zortje/mysql-keeper": "~0.0"
CONFIG;

$pdo = new PDO('mysql:host=127.0.0.1;dbname=myapp', 'root', '');

$database = Zortje\MySQLKeeper\DatabaseFactory::create($pdo);

print_r($database->getResult());

Simply run:

$ melody run mysql-keeper_myapp.php