Initial commit

This commit is contained in:
2021-08-26 20:59:17 +02:00
commit 3afa4c82ef
524 changed files with 52428 additions and 0 deletions

6
OpenDBDiffCmd/App.config Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="OpenDBDiff.NewIssueUri" value="https://github.com/OpenDBDiff/OpenDBDiff/issues/new" />
</appSettings>
</configuration>

View File

@@ -0,0 +1,26 @@
using CommandLine;
using CommandLine.Text;
namespace OpenDBDiff.OCDB
{
public class CommandlineOptions
{
[Option('b', "before", Required = true, HelpText = "Connection string of database before changes are applied.")]
public string Before { get; set; }
[Option('a', "after", Required = true, HelpText = "Connection string of database after changes are applied.")]
public string After { get; set; }
[Option('o', "outputfile", Required = false, HelpText = "Output file of action script. If omitted, script is written to the console.")]
public string OutputFile { get; set; }
[ParserState]
public IParserState LastParserState { get; set; }
[HelpOption]
public string GetUsage()
{
return HelpText.AutoBuild(this, (HelpText current) => HelpText.DefaultParsingErrorsHandler(this, current));
}
}
}

View File

@@ -0,0 +1,90 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{E794AA28-EE68-44BD-827B-1BFD9C106B65}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>OpenDBDiff.OCDB</RootNamespace>
<AssemblyName>OCDB</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<FileUpgradeFlags>
</FileUpgradeFlags>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<OldToolsVersion>3.5</OldToolsVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<Reference Include="CommandLine, Version=1.9.71.2, Culture=neutral, PublicKeyToken=de6f01bd326f8c32, processorArchitecture=MSIL">
<HintPath>..\packages\CommandLineParser.1.9.71\lib\net45\CommandLine.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\OpenDBDiff\Properties\AssemblyVersionInfo.cs">
<Link>Properties\AssemblyVersionInfo.cs</Link>
</Compile>
<Compile Include="CommandlineOptions.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OpenDBDiff.Schema.SQLServer.Generates\OpenDBDiff.Schema.SQLServer.Generates.csproj">
<Project>{32ac9af6-db93-4354-b69f-6dbc65c70867}</Project>
<Name>DBDiff.Schema.SQLServer.Generates</Name>
</ProjectReference>
<ProjectReference Include="..\OpenDBDiff.Schema.SQLServer2005\OpenDBDiff.Schema.SQLServer.csproj">
<Project>{EF2F571E-A7AD-40BE-8500-50A039159FC1}</Project>
<Name>DBDiff.Schema.SQLServer</Name>
</ProjectReference>
<ProjectReference Include="..\OpenDBDiff.Schema\OpenDBDiff.Schema.csproj">
<Project>{406558A0-1B98-4D0E-B8B6-2013700B065A}</Project>
<Name>DBDiff.Schema</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="..\.editorconfig">
<Link>.editorconfig</Link>
</None>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

116
OpenDBDiffCmd/Program.cs Normal file
View File

@@ -0,0 +1,116 @@
using OpenDBDiff.Schema.SQLServer.Generates.Generates;
using OpenDBDiff.Schema.SQLServer.Generates.Model;
using OpenDBDiff.Schema.SQLServer.Generates.Options;
using System;
using System.Data.SqlClient;
using System.Diagnostics;
using System.IO;
namespace OpenDBDiff.OCDB
{
public class Program
{
private static SqlOption SqlFilter = new SqlOption();
protected Program() { }
private static int Main(string[] args)
{
bool completedSuccessfully = false;
var options = new CommandlineOptions();
if (CommandLine.Parser.Default.ParseArguments(args, options))
{
try
{
completedSuccessfully = Work(options);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
if (Debugger.IsAttached)
{
Console.WriteLine("Press any key to continue...");
Console.ReadKey(false);
}
return completedSuccessfully ? 0 : 1;
}
private static Boolean TestConnection(string connectionString1)
{
using (SqlConnection connection = new SqlConnection())
{
connection.ConnectionString = connectionString1;
connection.Open();
connection.Close();
return true;
}
}
private static bool Work(CommandlineOptions options)
{
try
{
Database origin;
Database destination;
if (TestConnection(options.Before)
&& TestConnection(options.After))
{
Generate sql = new Generate();
sql.ConnectionString = options.Before;
Console.WriteLine("Reading first database...");
sql.Options = SqlFilter;
origin = sql.Process();
sql.ConnectionString = options.After;
Console.WriteLine("Reading second database...");
destination = sql.Process();
Console.WriteLine("Comparing databases schemas...");
origin = Generate.Compare(origin, destination);
// temporary work-around: run twice just like GUI
origin.ToSqlDiff(new System.Collections.Generic.List<Schema.Model.ISchemaBase>());
Console.WriteLine("Generating SQL file...");
var script = origin.ToSqlDiff(new System.Collections.Generic.List<Schema.Model.ISchemaBase>()).ToSQL();
if (!string.IsNullOrWhiteSpace(options.OutputFile))
{
Console.WriteLine("Writing action script to {0}", options.OutputFile);
SaveFile(options.OutputFile, script);
}
else
{
Console.WriteLine();
Console.WriteLine(script);
Console.WriteLine();
}
return true;
}
}
catch (Exception ex)
{
string newIssueUri = System.Configuration.ConfigurationManager.AppSettings["OpenDBDiff.NewIssueUri"];
if (string.IsNullOrEmpty(newIssueUri))
newIssueUri = "https://github.com/OpenDBDiff/OpenDBDiff/issues/new";
Console.WriteLine($"{ex.Message}\r\n{ex.StackTrace}\r\n\r\nPlease report this issue at {newIssueUri}.");
Console.WriteLine();
}
return false;
}
private static void SaveFile(string filenmame, string sql)
{
if (!String.IsNullOrEmpty(filenmame))
{
StreamWriter writer = new StreamWriter(filenmame, false);
writer.Write(sql);
writer.Close();
}
}
}
}

View File

@@ -0,0 +1,22 @@
using System.Reflection;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("OpenDBDiff Console")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("OpenDBDiff Console")]
[assembly: AssemblyCopyright("OpenDBDiff")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("30c9b799-3cd9-4c83-9141-dc7782005ec1")]

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="CommandLineParser" version="1.9.71" targetFramework="net452" />
</packages>