Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions yuniql-cli/CommandLineService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ namespace Yuniql.CLI
{
public class CommandLineService : ICommandLineService
{
private IMigrationServiceFactory _migrationServiceFactory;
private Core.Factories.IMigrationServiceFactory _migrationServiceFactory;
private readonly ILocalVersionService _localVersionService;
private readonly IEnvironmentService _environmentService;
private ITraceService _traceService;

public CommandLineService(
IMigrationServiceFactory migrationServiceFactory,
Core.Factories.IMigrationServiceFactory migrationServiceFactory,
ILocalVersionService localVersionService,
IEnvironmentService environmentService,
ITraceService traceService)
Expand Down Expand Up @@ -123,7 +123,7 @@ public int RunMigration(RunOption opts)
var toolName = "yuniql-cli";
var toolVersion = this.GetType().Assembly.GetName().Version.ToString();

var migrationService = _migrationServiceFactory.Create(opts.Platform);
var migrationService = _migrationServiceFactory.Create(opts.Platform, opts.PluginsPath);
migrationService.Initialize(opts.ConnectionString, opts.CommandTimeout);
migrationService.Run(
opts.Path,
Expand Down
174 changes: 87 additions & 87 deletions yuniql-cli/MigrationServiceFactory.cs
Original file line number Diff line number Diff line change
@@ -1,97 +1,97 @@
using System;
using Yuniql.Core;
using Yuniql.Extensibility;
using Yuniql.MySql;
using Yuniql.PostgreSql;
using Yuniql.SqlServer;
//using System;
//using Yuniql.Core;
//using Yuniql.Extensibility;
//using Yuniql.MySql;
//using Yuniql.PostgreSql;
//using Yuniql.SqlServer;

namespace Yuniql.CLI
{
public class MigrationServiceFactory : IMigrationServiceFactory
{
private readonly ITraceService _traceService;
//namespace Yuniql.CLI
//{
// public class MigrationServiceFactory : IMigrationServiceFactory
// {
// private readonly ITraceService _traceService;

public MigrationServiceFactory(
ITraceService traceService)
{
this._traceService = traceService;
}
// public MigrationServiceFactory(
// ITraceService traceService)
// {
// this._traceService = traceService;
// }

public IMigrationService Create(string platform)
{
switch (platform.ToLower())
{
case SUPPORTED_DATABASES.SQLSERVER:
{
var dataService = new SqlServerDataService(_traceService);
var bulkImportService = new SqlServerBulkImportService(_traceService);
return dataService.IsAtomicDDLSupported
? CreateTransactionalMigrationService(dataService, bulkImportService)
: CreateNonTransactionalMigrationService(dataService, bulkImportService);
}
case SUPPORTED_DATABASES.POSTGRESQL:
{
var dataService = new PostgreSqlDataService(_traceService);
var bulkImportService = new PostgreSqlBulkImportService(_traceService);
return dataService.IsAtomicDDLSupported
? CreateTransactionalMigrationService(dataService, bulkImportService)
: CreateNonTransactionalMigrationService(dataService, bulkImportService);
}
case SUPPORTED_DATABASES.MYSQL:
{
var dataService = new MySqlDataService(_traceService);
var bulkImportService = new MySqlBulkImportService(_traceService);
return dataService.IsAtomicDDLSupported
? CreateTransactionalMigrationService(dataService, bulkImportService)
: CreateNonTransactionalMigrationService(dataService, bulkImportService);
}
default:
throw new NotSupportedException($"The target database platform {platform} is not supported or plugins location was not correctly configured. " +
$"See WIKI for supported database platforms and usage guide.");
}
}
// public IMigrationService Create(string platform)
// {
// switch (platform.ToLower())
// {
// case SUPPORTED_DATABASES.SQLSERVER:
// {
// var dataService = new SqlServerDataService(_traceService);
// var bulkImportService = new SqlServerBulkImportService(_traceService);
// return dataService.IsAtomicDDLSupported
// ? CreateTransactionalMigrationService(dataService, bulkImportService)
// : CreateNonTransactionalMigrationService(dataService, bulkImportService);
// }
// case SUPPORTED_DATABASES.POSTGRESQL:
// {
// var dataService = new PostgreSqlDataService(_traceService);
// var bulkImportService = new PostgreSqlBulkImportService(_traceService);
// return dataService.IsAtomicDDLSupported
// ? CreateTransactionalMigrationService(dataService, bulkImportService)
// : CreateNonTransactionalMigrationService(dataService, bulkImportService);
// }
// case SUPPORTED_DATABASES.MYSQL:
// {
// var dataService = new MySqlDataService(_traceService);
// var bulkImportService = new MySqlBulkImportService(_traceService);
// return dataService.IsAtomicDDLSupported
// ? CreateTransactionalMigrationService(dataService, bulkImportService)
// : CreateNonTransactionalMigrationService(dataService, bulkImportService);
// }
// default:
// throw new NotSupportedException($"The target database platform {platform} is not supported or plugins location was not correctly configured. " +
// $"See WIKI for supported database platforms and usage guide.");
// }
// }

private IMigrationService CreateTransactionalMigrationService(IDataService dataService, IBulkImportService bulkImportService)
{
var localVersionService = new LocalVersionService(_traceService);
var tokenReplacementService = new TokenReplacementService(_traceService);
var directoryService = new DirectoryService();
var fileService = new FileService();
// private IMigrationService CreateTransactionalMigrationService(IDataService dataService, IBulkImportService bulkImportService)
// {
// var localVersionService = new LocalVersionService(_traceService);
// var tokenReplacementService = new TokenReplacementService(_traceService);
// var directoryService = new DirectoryService();
// var fileService = new FileService();

var configurationService = new ConfigurationDataService(dataService, _traceService, tokenReplacementService);
// var configurationService = new ConfigurationDataService(dataService, _traceService, tokenReplacementService);

var migrationService = new MigrationService(
localVersionService,
dataService,
bulkImportService,
configurationService,
tokenReplacementService,
directoryService,
fileService,
_traceService);
return migrationService;
}
// var migrationService = new MigrationService(
// localVersionService,
// dataService,
// bulkImportService,
// configurationService,
// tokenReplacementService,
// directoryService,
// fileService,
// _traceService);
// return migrationService;
// }

private IMigrationService CreateNonTransactionalMigrationService(IDataService dataService, IBulkImportService bulkImportService)
{
var localVersionService = new LocalVersionService(_traceService);
var tokenReplacementService = new TokenReplacementService(_traceService);
var directoryService = new DirectoryService();
var fileService = new FileService();
// private IMigrationService CreateNonTransactionalMigrationService(IDataService dataService, IBulkImportService bulkImportService)
// {
// var localVersionService = new LocalVersionService(_traceService);
// var tokenReplacementService = new TokenReplacementService(_traceService);
// var directoryService = new DirectoryService();
// var fileService = new FileService();

var configurationService = new ConfigurationDataService(dataService, _traceService, tokenReplacementService);
// var configurationService = new ConfigurationDataService(dataService, _traceService, tokenReplacementService);

var migrationService = new NonTransactionalMigrationService(
localVersionService,
dataService,
bulkImportService,
configurationService,
tokenReplacementService,
directoryService,
fileService,
_traceService);
return migrationService;
}
}
}
// var migrationService = new NonTransactionalMigrationService(
// localVersionService,
// dataService,
// bulkImportService,
// configurationService,
// tokenReplacementService,
// directoryService,
// fileService,
// _traceService);
// return migrationService;
// }
// }
//}

3 changes: 2 additions & 1 deletion yuniql-cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public static int Main(string[] args)
var environmentService = new EnvironmentService();
var traceService = new FileTraceService();
var localVersionService = new LocalVersionService(traceService);
var migrationServiceFactory = new CLI.MigrationServiceFactory(traceService);
//var migrationServiceFactory = new CLI.MigrationServiceFactory(traceService);
var migrationServiceFactory = new Core.Factories.MigrationServiceFactory(traceService);
var commandLineService = new CommandLineService(migrationServiceFactory, localVersionService, environmentService, traceService);

var resultCode = Parser.Default.ParseArguments<
Expand Down
3 changes: 0 additions & 3 deletions yuniql-cli/Yuniql.CLI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@
<ItemGroup>
<ProjectReference Include="..\yuniql-core\Yuniql.Core.csproj" />
<ProjectReference Include="..\yuniql-extensibility\Yuniql.Extensibility.csproj" />
<ProjectReference Include="..\yuniql-platforms\mysql\Yuniql.MySql.csproj" />
<ProjectReference Include="..\yuniql-platforms\postgresql\Yuniql.PostgreSql.csproj" />
<ProjectReference Include="..\yuniql-platforms\sqlserver\Yuniql.SqlServer.csproj" />
</ItemGroup>

</Project>
72 changes: 72 additions & 0 deletions yuniql-core/Factories/FullTypeNameEntry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

namespace Yuniql.Core.Factories {
///<inheritdoc/>
public struct FullTypeNameEntry {

///<inheritdoc/>
public readonly string AssemblyName;

///<inheritdoc/>
public readonly string TypeName;

///<inheritdoc/>
public FullTypeNameEntry(string fullTypeName) {
if (string.IsNullOrWhiteSpace(fullTypeName)) throw new MissingTypeNameException();

var nameParts = fullTypeName.Split(',');
if (nameParts.Length != 2) throw new InvalidTypeNameFormatException(fullTypeName, nameParts.Length);

AssemblyName = nameParts[0].Trim();
TypeName = nameParts[1].Trim();
}
}

///<inheritdoc/>
public class MissingTypeNameException : ArgumentException {

///<inheritdoc/>
public MissingTypeNameException()
: base("TypeName should not be null or empty"){

}
}

///<inheritdoc/>
public class InvalidTypeNameFormatException : ArgumentException {

///<inheritdoc/>
public InvalidTypeNameFormatException(string typeName, int segmentCount)
: base($"Expected segment for {typeName} is 2 but actual is {segmentCount}") {
}
}


///<inheritdoc/>
public class TypeLoadFailedException : ArgumentException {
///<inheritdoc/>
public TypeLoadFailedException(string typeName, string assemblyName)
: base($"Type {typeName} not found in assembly {assemblyName}") {

}

///<inheritdoc/>
public TypeLoadFailedException(string typeName, string assemblyName, string message)
: base($"Type {typeName} not found in assembly {assemblyName}. Details: {message}") {

}
}

///<inheritdoc/>
public class AssemblyLoadFailedException : ArgumentException {

///<inheritdoc/>
public AssemblyLoadFailedException(string assemblyName, string errorDetails)
: base($"Assembly {assemblyName} not found. Details {errorDetails}") {

}
}
}
8 changes: 8 additions & 0 deletions yuniql-core/Factories/IMigrationServiceFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Yuniql.Core.Factories {

///<inheritdoc/>
public interface IMigrationServiceFactory {
///<inheritdoc/>
IMigrationService Create(string platform, string pluginsPath = "");
}
}
Loading