PHPackages                             clouddueling/auto-migrate - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. clouddueling/auto-migrate

ActiveLibrary[Database &amp; ORM](/categories/database)

clouddueling/auto-migrate
=========================

This class can be used to generate diffs between a MySQL XML dump file, and a database which currently exists. It will tell you the missing tables and columns (return as an array), or generate MySQL queries to add the missing columns in.

0.0.1(11y ago)326MITPHPPHP &gt;=5.3

Since Jun 18Pushed 11y ago1 watchersCompare

[ Source](https://github.com/clouddueling/auto-migrate)[ Packagist](https://packagist.org/packages/clouddueling/auto-migrate)[ RSS](/packages/clouddueling-auto-migrate/feed)WikiDiscussions master Synced 6d ago

READMEChangelog (1)Dependencies (3)Versions (2)Used By (0)

WARNING
=======

[](#warning)

This project is brand new but will be quickly maturing if it proves to be a big timesaver.

This class can be used to generate diffs between a MySQL XML dump file, and a database which currently exists. It will tell you the missing tables and columns (return as an array), or generate MySQL queries to add the missing columns in.

Getting Started
===============

[](#getting-started)

1. Install via composer:

    ```
    {
        "require": {
            "clouddueling/auto-migrate": "dev-master"
        }
    }
    ```
2. Export your database to XML schema files.

    ```
    sh src/Export/exportMySQL.sh
    ```

    Your output should look like:

    ```
    Creating schema: series
    Creating schema: services
    Creating schema: sessions
    Creating schema: slides
    Creating schema: speakers
    Creating schema: states
    Creating schema: steps
    Creating schema: subscription

    ```

    The XML files outputted will be how you manage what your database looks like from now on.
3. When you make a change to your schema files you then use `CloudDueling\AutoMigrate\MySQL` and to loop through each schema file and to alter your database.

    Example of available methods:

    ```
        $params = array(
            'dbuser' => 'root',
            'dbpass' => 'root',
            'dbname' => 'database',
            'dbhost' => 'localhost'
        );

        try {
            $diff = new MySQLDiff($params);
        } catch(Exception $e) {
            echo $e->getMessage(); exit;
        }

        // This returns an array of what's missing in the database
        try {
            $diff_lines = $diff->getDiffs();
            var_dump($diff_lines);
         catch(Exception $e) {
            echo $e->getMessage(); exit;
        }

        // This returns SQL queries which can be run to fix the database
        try {
            $diff_lines = $diff->getSQLDiffs();
            var_dump($diff_lines);
        } catch(Exception $e) {
            echo $e->getMessage(); exit;
        }

        // This generates the SQL and actually runs all of them
        try {
            $diff_lines = $diff->runSQLDiff();
            var_dump($diff_lines);
        } catch(Exception $e) {
            echo $e->getMessage(); exit;
        }
    ```

    Example looping through a directory of schemas and update your database with them.

    Laravel 4 Task

    ```
    // Coming soon, feel free to PR this
    ```

    Laravel 3 Task

    ```
