mysql-diff

Detect and extract diff between two table declarations from schema of MySQL

License

License

Categories

Categories

MySQL Data Databases Net
GroupId

GroupId

net.moznion
ArtifactId

ArtifactId

mysql-diff
Last Version

Last Version

1.1.0
Release Date

Release Date

Type

Type

jar
Description

Description

mysql-diff
Detect and extract diff between two table declarations from schema of MySQL
Project URL

Project URL

https://github.com/moznion/java-mysql-diff
Source Code Management

Source Code Management

https://github.com/moznion/java-mysql-diff

Download mysql-diff

How to add to project

<!-- https://jarcasting.com/artifacts/net.moznion/mysql-diff/ -->
<dependency>
    <groupId>net.moznion</groupId>
    <artifactId>mysql-diff</artifactId>
    <version>1.1.0</version>
</dependency>
// https://jarcasting.com/artifacts/net.moznion/mysql-diff/
implementation 'net.moznion:mysql-diff:1.1.0'
// https://jarcasting.com/artifacts/net.moznion/mysql-diff/
implementation ("net.moznion:mysql-diff:1.1.0")
'net.moznion:mysql-diff:jar:1.1.0'
<dependency org="net.moznion" name="mysql-diff" rev="1.1.0">
  <artifact name="mysql-diff" type="jar" />
</dependency>
@Grapes(
@Grab(group='net.moznion', module='mysql-diff', version='1.1.0')
)
libraryDependencies += "net.moznion" % "mysql-diff" % "1.1.0"
[net.moznion/mysql-diff "1.1.0"]

Dependencies

compile (2)

Group / Artifact Type Version
mysql : mysql-connector-java jar [8.0.21,)
args4j : args4j jar 2.0.29

provided (1)

Group / Artifact Type Version
org.projectlombok : lombok jar 1.14.8

test (2)

Group / Artifact Type Version
junit : junit jar 4.11
com.google.code.findbugs : findbugs jar 3.0.0

Project Modules

There are no modules declared in this project.

mysql-diff Build Status Maven Central javadoc.io

Detect and extract diff between two table declarations from schema of MySQL.

Synopsis

Use as CLI application

Executable fat-jar is available at here.

$ java -jar [old_database] [new_database]

If you want more details, please run this command with --help option.

Programmatically

import net.moznion.mysql.diff.DiffExtractor;
import net.moznion.mysql.diff.MySqlConnectionInfo;
import net.moznion.mysql.diff.SchemaDumper;
import net.moznion.mysql.diff.SchemaParser;

MySqlConnectionInfo localMySqlConnectionInfo = MySqlConnectionInfo.builder()
    // .host("your-host")     // "localhost" is the default value
    // .user("your-name")     // "root" is the default value
    // .pass("your-password") // "" is the default value
    // .url("jdbc:mysql://your-host:3306?cacheServerConfiguration=true") // or you can specify host, port and properties by a URL
    .build();
SchemaDumper schemaDumper = new SchemaDumper(localMySqlConnectionInfo);

final String oldSql = "CREATE TABLE `sample` (\n"
    + "  `id` INTEGER(10) NOT NULL AUTO_INCREMENT,\n"
    + "  PRIMARY KEY (`id`)\n"
    + ") ENGINE=InnoDB DEFAULT CHARSET=utf8;\n";
final String newSql = "CREATE TABLE `sample` (\n"
    + "  `id` INTEGER(10) NOT NULL AUTO_INCREMENT,\n"
    + "  `name` VARCHAR(32) NOT NULL,\n"
    + "  PRIMARY KEY (`id`)\n"
    + ") ENGINE=InnoDB DEFAULT CHARSET=utf8;\n";

String oldSchema = schemaDumper.dump(oldSql);
String newSchema = schemaDumper.dump(newSql);

List<Table> oldTables = SchemaParser.parse(oldSchema);
List<Table> newTables = SchemaParser.parse(newSchema);

String diff = DiffExtractor.extractDiff(oldTables, newTables);

Description

This package provides a function to detect and extract diff between two table declarations from schema.

Extraction processing flow is following;

  1. Dump normalized schema by creating new database according to input and dump it out by using mysqldump
  2. Parse normalized schema
  3. Take diff between parsed structure

This package is port of onishi-san's mysqldiff from Perl to Java.

Dependencies

  • Java 8 or later
  • MySQL 5 or later (mysqld must be upped when this program is executed)
  • mysqldump

How to build fat-jar

If you want to build an executable standalone jar, please run following command;

$ mvn -P fatjar clean package

And now, generated runnable fat-jar file has been available on GitHub Releases.

See Also

Author

moznion ([email protected])

License

The MIT License (MIT)
Copyright © 2014 moznion, http://moznion.net/ <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the “Software”), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

Versions

Version
1.1.0
1.0.2
1.0.1
1.0.0