Giter VIP home page Giter VIP logo

dbstructsync's Introduction

The class provides ability to compare 2 database structure dumps and compile a set of sql statements to update
one database to make it structure identical to another.

Live demo could be found here: 
http://gerr.info/dbSync.html

The input for the script could be taken from the phpMyAdmin structure dump, or provided by some custom code
that uses 'SHOW CREATE TABLE' query to get database structure table by table.
The output is either array of sql statements suitable for executions right from php or a string where the
statements are placed each at new line and delimited with ';' - suitable for execution from phpMyAdmin SQL
page.
The resulting sql may contain queries that aim to:
Create missing table (CREATE TABLE query)
Delete table which should not longer exist (DROP TABLE query)
Update, drop or add table field or index definition (ALTER TABLE query)

Some features:
- AUTO_INCREMENT value is ommited during the comparison and in resulting CREATE TABLE sql
- fields with definitions like "(var)char (255) NOT NULL default ''" and "(var)char (255) NOT NULL" are treated
  as equal, the same for (big|tiny)int NOT NULL default 0;
- IF NOT EXISTS is automatically added to the resulting sql CREATE TABLE statement
- fields updating queries always come before key modification ones for each table
Not implemented:
- The class even does not try to insert or re-order fields in the same order as in the original table.
  Does order matter?
IMPORTANT!!! Class will not handle a case when the field was renamed. It will generate 2 queries - one to drop
the column with the old name and one to create column with the new name, so if there is a data in the dropped
column, it will be lost.
Usage example:
$updater = new dbStructUpdater();
$res = $updater->getUpdates($struct1, $struct2);
-----
$res == array (
	[0]=>"ALTER TABLE `b` MODIFY `name` varchar(255) NOT NULL",
	...
)

dbstructsync's People

Contributors

gerkirill avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.