PHP Classes

PHP MySQL Scheman: Make MySQL database schema changes generating SQL

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 116 All time: 9,555 This week: 69Up
Version License PHP version Categories
mysql-scheman 1.0.0The PHP License5PHP 5, Databases, Systems administration
Description 

Authors

Shabeer Ali M
Harish UW


Contributor

This package can make MySQL database schema changes generating SQL.

It can connect to a given MySQL database server using credentials read from an XML or JSON configuration files.

The package can extract the database table schema and generates a JSON file that describes the table structure.

It can also connect to another MySQL database server and generates the necessary SQL statements to perform the table schema changes to update it to be the same that is read from a JSON file previously generated from the schema of the database that is more up to date.

Innovation Award
PHP Programming Innovation award nominee
July 2021
Number 5
Database schema changes are necessary to perform when an application needs to evolve and store more information in its database tables.

Changing a database schema is a delicate operation. The changes to be done on the database schema need to be done in the right order and use the correct SQL statements so that multiple changes can be done successfully.

This package provides a safer solution by generating a JSON file with the current database table schema definition.

Then the developer can make the database schema changes he wants in the JSON file so that the package can perform the necessary changes executing the correct SQL statements in the correct order.

Manuel Lemos
Picture of Shabeer ALi M
  Performance   Level  
Name: Shabeer ALi M <contact>
Classes: 4 packages by
Country: India India
Age: ???
All time rank: 3531233 in India India
Week rank: 227 Up15 in India India Up
Innovation award
Innovation award
Nominee: 2x

Example

<?php

require __DIR__.'/../vendor/autoload.php';

$scheman = new MysqlScheman\MysqlScheman('127.0.0.1','root','','test');

//$scheman->export('db.xml');
$scheman->sync2db('db.xml');


Details

MySQL Scheman

MySQL schema, a simple MySQL schema synchronization utility. This will create an UPDATE/ADD query automatically based on the schema difference in the database and schema file.

Build

Why we use MySQL Scheman

Developers find it very hard to synchronize MySQL schema while developing any application. The current conventional method is to create an SQL file with all the changes & update it in the staging/production server. The main demerit of this method is if there are multiple people and multiple SQL changes on the same table the process is a bit hectic. In order to solve this, we developed a platform where you can update the schema in a file, and by running sync to database it will create the SQL Query for the changes and it will execute.

Installation

If you use Composer, you can install MySQL Scheman with the following command:


Or alternatively, include a dependency for MySQL Scheman in your composer.json file. For example

{

"require-dev": {
    "smart-php/mysql-scheman": "dev-master"
}

}


### Config

A database configuration file should be there to communicate with the database. Please see the sample files and create a copy in your working directory with your database credentials.

JSON: config.json
XML: config.xml

### Usage (CLI)

To CLI Help

./vendor/bin/scheman --help


Exporting Database to Schema File:

./vendor/bin/scheman --config config.json --export yourdatabase.json


Sync the file schema with your database

./vendor/bin/scheman --config config.json --sync yourdatabase.json


## License
See the `LICENSE` file.

  Files folder image Files (20)  
File Role Description
Files folder image.github (1 directory)
Files folder imagebin (2 files)
Files folder imagesrc (7 files, 3 directories)
Files folder imagetests (1 file)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file config.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (20)  /  .github  
File Role Description
Files folder imageworkflows (1 file)

  Files folder image Files (20)  /  .github  /  workflows  
File Role Description
  Accessible without login Plain text file php.yml Data Auxiliary data

  Files folder image Files (20)  /  bin  
File Role Description
  Accessible without login Plain text file scheman Appl. Application script to run from the shell
  Plain text file scheman.php Class Class source

  Files folder image Files (20)  /  src  
File Role Description
Files folder imageDriver (2 directories)
Files folder imageReader (2 directories)
Files folder imageWriter (2 directories)
  Plain text file DriverInterface.php Class Class source
  Plain text file MysqlScheman.php Class Class source
  Plain text file MysqlSchemanCli.php Class Class source
  Plain text file QueryBuilder.php Class Class source
  Plain text file ReaderInterface.php Class Class source
  Plain text file SchemaDiffer.php Class Class source
  Plain text file WriterInterface.php Class Class source

  Files folder image Files (20)  /  src  /  Driver  
File Role Description
Files folder imageMysqli (1 file)
Files folder imagePdo (1 file)

  Files folder image Files (20)  /  src  /  Driver  /  Mysqli  
File Role Description
  Plain text file Driver.php Class Class source

  Files folder image Files (20)  /  src  /  Driver  /  Pdo  
File Role Description
  Plain text file Driver.php Class Class source

  Files folder image Files (20)  /  src  /  Reader  
File Role Description
Files folder imageJson (1 file)
Files folder imageXml (1 file)

  Files folder image Files (20)  /  src  /  Reader  /  Json  
File Role Description
  Plain text file Reader.php Class Class source

  Files folder image Files (20)  /  src  /  Reader  /  Xml  
File Role Description
  Plain text file Reader.php Class Class source

  Files folder image Files (20)  /  src  /  Writer  
File Role Description
Files folder imageJson (1 file)
Files folder imageXml (1 file)

  Files folder image Files (20)  /  src  /  Writer  /  Json  
File Role Description
  Plain text file Writer.php Class Class source

  Files folder image Files (20)  /  src  /  Writer  /  Xml  
File Role Description
  Plain text file Writer.php Class Class source

  Files folder image Files (20)  /  tests  
File Role Description
  Accessible without login Plain text file test.php Example Example script

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:116
This week:0
All time:9,555
This week:69Up