Skip to content

Compare database structures and generate SQL for structure synchronization 数据库结构同步

License

Notifications You must be signed in to change notification settings

GraceDotnet/power-schema-sync

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

power-schema-sync

Nuget

power-schema-sync is a database structure synchronization tool developed using .Net, which compares the structure of the two databases to generate the SQL required to synchronize the structure, which functions similarly to the structure synchronization in Navicat; The difference is that this project is an open source library that can be directly integrated into your existing system to implement regular synchronization or listen for an event to trigger a synchronization task.

Quick Start

install

dotnet add package PowerSchemaSync

usages

IDataBase dbSoruce = DataBaseFactory.GetDataBase(DataBaseType.MYSQL, "connString1");
IDataBase dbTarget = DataBaseFactory.GetDataBase(DataBaseType.MYSQL, "connString2");

// 1.获取整个库的表结构创建sql
var sqlStructure = dbSoruce.ExportStructure("test");
Console.WriteLine(sqlStructure);

// 2.结构比较获取同步结构的sql
var diff = new DiffUtility(dbSoruce, "test", dbTarget, "test").Diff();

Console.WriteLine("------------新建-----------");
foreach (var sqls in diff.Tables.Where(x => x.Operate == OprateEnum.Created).Select(x => x.SyncSqls))
{
    foreach (var sql in sqls)
    {
        Console.WriteLine(sql);
    }
}

Console.WriteLine("------------删除-----------");
foreach (var sqls in diff.Tables.Where(x => x.Operate == OprateEnum.Delete).Select(x => x.SyncSqls))
{
    foreach (var sql in sqls)
    {
        Console.WriteLine(sql);
    }
}

Console.WriteLine("------------修改-----------");
foreach (var sqls in diff.Tables.Where(x => x.Operate == OprateEnum.Edit).Select(x => x.SyncSqls))
{
    foreach (var sql in sqls)
    {
        Console.WriteLine(sql);
    }
}

Console.ReadLine();

Features

  • table sync
  • column ysnc
  • index ysnc
  • primary ysnc
  • view ysnc
  • func sync
  • stored procedure sync

Supported Databases

  • Mysql
  • MS SqlServer
  • Orecle

About

Compare database structures and generate SQL for structure synchronization 数据库结构同步

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published