08
Script PHP para sincronizar estructuras de BD MySQL
Interesante script que permite dados dos estructuras del MySQL, obtenidas por ejemplo usando un mysqldump, ver que diferencias hay entre ambos y devuelve las queries necesarias para igualar las dos estrucuras.
Por ejemplo, si tenemos la estructura siguiente:
CREATE TABLE IF NOT EXISTS `archive` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`topFile` varchar(255) NOT NULL DEFAULT '',
`msgId` int(11) NOT NULL DEFAULT '0',
`time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`topTpl` varchar(255) NOT NULL DEFAULT '',
`file` varchar(255) NOT NULL DEFAULT '',
`template` varchar(255) NOT NULL DEFAULT '',
`instanceKey` varchar(255) NOT NULL DEFAULT '',
`orderby` varchar(25) NOT NULL DEFAULT '',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=10256 ;
Y este otro:
CREATE TABLE IF NOT EXISTS `archive` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`topFile` varchar(255) NOT NULL DEFAULT '',
`msgId` int(11) NOT NULL DEFAULT '0',
`time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`topTpl` varchar(255) NOT NULL DEFAULT '',
`file` varchar(255) NOT NULL DEFAULT '',
`template` varchar(255) NOT NULL DEFAULT '',
`instanceKey` varchar(255) NOT NULL DEFAULT '',
`encoding` varchar(50) NOT NULL DEFAULT '',
`orderby` varchar(255) NOT NULL DEFAULT '',
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=10256 ;
Nos devolvería las siguientes sentencias:
ALTER TABLE `archive` ADD `encoding` varchar(50) NOT NULL;
ALTER TABLE `archive` MODIFY `orderby` varchar(255) NOT NULL;
ALTER TABLE `archive` MODIFY `time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;
ALTER TABLE `archive` DROP PRIMARY KEY;
Un script bastante útil cuando, debido al despiste, tenemos diferencias entre la base de datos de desarrollo y la de producción y no sabemos qué cambios hemos realizado.
Database structure synchronizer
