Note
This project is archived because I no longer actively use it, and there seems to be no recent activity from other users either. If you are still using it and would like to take over maintenance, contact me somewhere.
SQL schema parser.
Usage
Create diff from 2 schema files or input.
# before.sql
CREATE TABLE `table1` (
`column1` INTEGER(11) PRIMARY KEY NOT NULL AUTO_INCREMENT,
`column2` DATETIME DEFAULT NOW()
);
CREATE TABLE `table2` (
`column1` INTEGER(11) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`column1`)
);# after.sql
CREATE TABLE `table1` (
`column1` CHAR(11) NOT NULL AUTO_INCREMENT,
`column2` DATETIME DEFAULT CURRENT_TIMESTAMP(),
`column3` VARCHAR(255) NOT NULL DEFAULT "a",
PRIMARY KEY (`column2`)
);
CREATE TABLE `table3` (
`column1` INTEGER(11) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`column1`)
);$ scheman diff --before before.sql --after after.sql
BEGIN;
SET foreign_key_checks=0;
CREATE TABLE `table3` (
`column1` INTEGER(11) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`column1`)
);
ALTER TABLE `table1` ADD COLUMN `column3` VARCHAR(255) NOT NULL DEFAULT "a",
CHANGE COLUMN `column1` CHAR(11) NOT NULL AUTO_INCREMENT,
DROP PRIMARY KEY,
ADD PRIMARY KEY `column2`;
DROP TABLE `table2`;
SET foreign_key_checks=1;
COMMIT;STDIN
You can input schema data into scheman diff command via STDIN, instead of --before.
For instance, this interface is useful when you want to use mysqldump command to get your current schema.
$ mysqldump --no-data --compact db_name | scheman diff --after after.sql./schema.sql
Scheman use ./schema.sql as a default value of --after option.
$ mysqldump --no-data --compact db_name | scheman diffPipes
Here is an example workflow of schema modification, using UNIX pipes.
$ vi schema.sql
$ mysqldump --no-data --compact db_name | scheman diff | mysql db_nameRails
scheman-rails provides some rake tasks to use scheman with Rails.