PHP code example of starker-xp / database-checker

1. Go to this page and download the library: Download starker-xp/database-checker library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

starker-xp / database-checker example snippets


// Depuis une base MySQL live
$pdo = new PDO('mysql:host=localhost', 'user', 'pass');
$repository = new MysqlRepository($pdo);
$factory = new MysqlDatabaseFactory($repository, 'ma_base');
$currentDatabase = $factory->generate();

// Depuis un fichier JSON de référence
$json = file_get_contents('schema-reference.json');
$jsonFactory = new JsonDatabaseFactory($json);
$referenceDatabase = $jsonFactory->generate('ma_base');

// Générer le diff
$checker = new MysqlDatabaseCheckerService();
$checker->enableCheckCollate();   // optionnel
$checker->enableCheckEngine();    // optionnel
$checker->enableDropStatement();  // optionnel — désactivé par défaut
$statements = $checker->diff($currentDatabase, $referenceDatabase);

// $statements contient les ALTER/CREATE/DROP SQL à exécuter

src/
├── Checker/
│   └── MysqlDatabaseCheckerService.php   # Moteur de diff entre deux MysqlDatabase
├── Exception/                             # 10 exceptions métier spécifiques
├── Factory/
│   ├── JsonDatabaseFactory.php            # Construit MysqlDatabase depuis un JSON
│   └── MysqlDatabaseFactory.php           # Construit MysqlDatabase depuis MySQL live
├── Repository/
│   ├── MysqlRepository.php                # Requêtes INFORMATION_SCHEMA
│   └── StructureInterface.php             # Abstraction pour le mock en tests
├── Structure/
│   ├── DatabaseInterface.php              # Contrat commun (create/alter/delete)
│   ├── MysqlDatabase.php                  # Modèle : base de données
│   ├── MysqlDatabaseTable.php             # Modèle : table (colonnes + index)
│   ├── MysqlDatabaseColumn.php            # Modèle : colonne (type, nullable, default...)
│   └── MysqlDatabaseIndex.php             # Modèle : index (unique, primary, standard)
└── LoggerTrait.php                        # PSR-3 logger intégré

tests/
├── Checker/MysqlDatabaseCheckerServiceTest.php
├── Factory/JsonDatabaseFactoryTest.php
├── Factory/MysqlDatabaseFactoryTest.php
├── Structure/MysqlDatabaseColumnTest.php
├── Structure/MysqlDatabaseIndexTest.php
├── Structure/MysqlDatabaseTableTest.php
├── Structure/MysqlDatabaseTest.php
└── LoggetTraitTest.php