Skip to content

Latest commit

 

History

History
65 lines (55 loc) · 1.86 KB

README_zh.md

File metadata and controls

65 lines (55 loc) · 1.86 KB

power-schema-sync

Nuget

power-schema-sync是一款使用.Net开发的数据库结构同步工具,通过比对两个数据库的结构,生成同步结构所需执行的sql,其功能类似Navicat中的结构同步;不同的是本项目作为一个开源库,可直接集成到您现有的系统中,实现定时同步或监听某个事件来触发同步任务。

快速开始

安装

dotnet add package PowerSchemaSync

用法

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();

特性

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

支持的数据库

  • Mysql
  • MS SqlServer
  • Orecle