Changeset 957b10626f18…
Parent 62c445c1f06c…
by
Changes to 6 files · Browse files at 957b10626f18 Showing diff from parent 62c445c1f06c Diff from another changeset...
@@ -23,7 +23,7 @@ <OldToolsVersion>3.5</OldToolsVersion>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
- <TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
+ <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
@@ -1,3 +1,3 @@ <?xml version="1.0"?>
<configuration>
- <startup><supportedRuntime version="v2.0.50727"/></startup></configuration>
+ <startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
|
|
|
@@ -1,151 +0,0 @@ - #region License
-//The contents of this file are subject to the Mozilla Public License
-//Version 1.1 (the "License"); you may not use this file except in
-//compliance with the License. You may obtain a copy of the License at
-//http://www.mozilla.org/MPL/
-//Software distributed under the License is distributed on an "AS IS"
-//basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
-//License for the specific language governing rights and limitations
-//under the License.
-#endregion
-using System;
-
-using NAnt.Core;
-using log4net;
-
-using Migrator.Loggers;
-
-namespace Migrator.NAnt.Loggers
-{
- /// <summary>
- /// NAnt task logger for the migration mediator
- /// </summary>
- public class TaskLogger : ILogger
- {
- private int _widthFirstColumn = 5;
- private Task _task;
-
- public TaskLogger(Task task)
- {
- _task = task;
- }
-
- protected void LogInfo(string format, params object[] args)
- {
- _task.Log(Level.Info, format, args);
- }
-
- protected void LogError(string format, params object[] args)
- {
- _task.Log(Level.Error, format, args);
- }
-
- public void Started(int currentVersion, int finalVersion)
- {
- LogInfo("Current version : {0}", currentVersion);
- }
-
- public void MigrateUp(int version, string migrationName)
- {
- LogInfo("{0} {1}", version.ToString().PadLeft(_widthFirstColumn), migrationName);
- }
-
- public void MigrateDown(int version, string migrationName)
- {
- MigrateUp(version, migrationName);
- }
-
- public void Skipping(int version)
- {
- MigrateUp(version, "<Migration not found>");
- }
-
- public void RollingBack(int originalVersion)
- {
- LogInfo("Rolling back to migration {0}", originalVersion);
- }
-
- public void Exception(int version, string migrationName, Exception ex)
- {
- LogInfo("{0} Error in migration {1} : {2}", "".PadLeft(_widthFirstColumn), version, ex.Message);
- this.TraceException(ex);
- }
-
- public void Exception(string format, Exception ex, params object[] args)
- {
- try
- {
- LogInfo("{0} Exception thrown: {1}", "".PadLeft(_widthFirstColumn), EscapeFormatBraces(string.Format(format, args)));
- LogInfo("{0} Exception Mesage: {1}", "".PadLeft(_widthFirstColumn), args, ex.Message);
- this.TraceException(ex);
- }
- catch
- {
- return;
- }
- }
-
- private void TraceException(Exception ex)
- {
- LogError(ex.Message);
- LogError(ex.StackTrace);
- Exception iex = ex.InnerException;
- while (ex.InnerException != null)
- {
- LogError("Caused by: {0}", ex.InnerException);
- LogError(ex.InnerException.StackTrace);
- iex = iex.InnerException;
- }
- }
-
- public void Finished(int originalVersion, int currentVersion)
- {
- LogInfo("Migrated to version {0}", currentVersion);
- }
-
- public void Log(string format, params object[] args)
- {
- try
- {
- LogInfo("{0} {1}", "".PadLeft(_widthFirstColumn), EscapeFormatBraces(string.Format(format, args)));
- }
- catch
- {
- return;
- }
- }
-
- public void Warn(string format, params object[] args)
- {
- try
- {
- LogInfo("{0} [Warning] {1}", "".PadLeft(_widthFirstColumn), EscapeFormatBraces(string.Format(format, args)));
- }
- catch
- {
- return;
- }
- }
-
- public void Trace(string format, params object[] args)
- {
- try
- {
- _task.Log(Level.Debug, "{0} {1}", "".PadLeft(_widthFirstColumn), EscapeFormatBraces(string.Format(format, args)));
- }
- catch
- {
- return;
- }
- }
-
- public static String EscapeFormatBraces(string toEscape)
- {
- return toEscape.Replace("{", "{{").Replace("}", "}}");
-
- }
-
-
-
- }
-}
|
|
@@ -16,12 +16,10 @@ using NAnt.Core.Attributes;
using NAnt.Core.Util;
-using Migrator.NAnt.Loggers;
using System.Xml;
using System.Collections;
using System.Collections.Generic;
using NAnt.Core.Tasks;
-using Migrator.Providers;
using System.Diagnostics;
namespace Migrator.NAnt
@@ -122,74 +120,22 @@ {
Migrate();
}
+ private String GetConnectionString()
+ {
+ System.Xml.XmlDocument source = new System.Xml.XmlDocument();
+ source.Load(this.ConfigFile);
+ //Pulling a connection string out of the ActiveRecord config file
+ return (source.SelectSingleNode("//add[@key='connection.connection_string']/@value")).Value;
+
+ }
private void Migrate()
{
- // determin the default provider
- TransformationProvider defaultProvider;
- if (this.ConfigFile != null)
- {
- defaultProvider = Migrator.CreateProvider(this.ConfigFile);
- }
- else
- {
- if (this.ConnectionString == null || this.Provider == null)
- {
- this.Log(Level.Error, "Not enough information to make a DB connection.");
- return;
- }
-
- defaultProvider = Migrator.CreateProvider(this.Provider, this.ConnectionString);
- }
-
- // load any additional providers:
- Dictionary<string, TransformationProvider> additionalProviders = new Dictionary<string, TransformationProvider>();
- if (this.Providers != null && this.Providers.Count > 0)
- {
- foreach (ProviderTask providerTask in this.Providers)
- {
- additionalProviders.Add(providerTask.ProviderName, Migrator.CreateProvider(providerTask.ConfigFile));
- }
- }
- if (Executable != null)
- {
- CallMigratorExecutable(defaultProvider);
- }
- else
- {
- var migrator = new Migrator(defaultProvider, additionalProviders, Assembly.LoadFrom(this.MigrationsAssembly.FullName), new TaskLogger(this));
- migrator.Logger = new TaskLogger(this);
- migrator.MigrationParameters = PropertyTasksToGenericDisctionary(this._params);
-
- if (this.Up)
- {
- migrator.MigrateUp();
- }
- else if (this.Down)
- {
- migrator.MigrateDown();
- }
- else if (this._to > -1)
- {
- migrator.MigrateTo(this._to);
- }
- else
- {
- migrator.MigrateToLastVersion();
- }
- }
+ CallMigratorExecutable(this.Provider, GetConnectionString());
}
- private int CallMigratorExecutable(TransformationProvider defaultProvider)
+ private int CallMigratorExecutable(String provider, String connectionString)
{
- // Migrator.Console.exe SqlServer "Data Source=localhost;Initial Catalog=Nexport;User Id=;Password=;Integrated Security=True" Nexport.Models.dll -up
-
- // Defaults to SqlServer provider
- string provider = defaultProvider is MySqlTransformationProvider ? "MySql" :
- defaultProvider is PostgreSQLTransformationProvider ? "Postgre" :
- "SqlServer";
- String databaseConnection = defaultProvider.ConnectionString;
-
string assemblyLocation = this.MigrationsAssembly.FullName;
string command = "";
@@ -198,11 +144,11 @@ else if (this.Down)
command = "-down";
else if (this._to > -1)
- command = "-to="+this._to;
+ command = "-to=" + this._to;
else
command = "";
- string exeArgs = String.Format(" {0} \"{1}\" \"{2}\" {3}", provider, databaseConnection, assemblyLocation, command);
+ string exeArgs = String.Format(" {0} \"{1}\" \"{2}\" {3}", provider, connectionString, assemblyLocation, command);
ProcessStartInfo processStartInfo = new ProcessStartInfo();
Process migratorProcess = null;
@@ -227,7 +173,7 @@ var outLine = outReader.ReadToEnd();
Console.Out.Write(outLine);
var error = errorReader.ReadToEnd();
- if(error != null && error.Length > 0)
+ if (error != null && error.Length > 0)
Console.Out.Write("*** {0}", error);
}
migratorProcess.WaitForExit();
@@ -236,21 +182,17 @@ }
finally
{
- if(migratorProcess != null)
- migratorProcess.Close();
+ if (migratorProcess != null)
+ migratorProcess.Close();
}
return exitCode;
}
- public void OutputRecievedHandler (object sender, DataReceivedEventArgs e){
+ public void OutputRecievedHandler(object sender, DataReceivedEventArgs e)
+ {
Console.Out.Write(e.Data);
}
- private TransformationProvider GetProvider(ProviderTask providerTask)
- {
- return Migrator.CreateProvider(providerTask.ConfigFile);
- }
-
private Dictionary<string, string> PropertyTasksToGenericDisctionary(List<PropertyTask> propertyTasks)
{
Dictionary<string, string> result = new Dictionary<string, string>();
|
@@ -23,7 +23,7 @@ <OldToolsVersion>3.5</OldToolsVersion>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
- <TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
+ <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<TargetFrameworkProfile />
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
@@ -73,17 +73,10 @@ <Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
- <Compile Include="Loggers\TaskLogger.cs" />
<Compile Include="MigrateTask.cs" />
<Compile Include="ProviderTask.cs" />
</ItemGroup>
<ItemGroup>
- <ProjectReference Include="..\core\Migrator.csproj">
- <Project>{1FEE70A4-AAD7-4C60-BE60-3F7DC03A8C4D}</Project>
- <Name>Migrator</Name>
- </ProjectReference>
- </ItemGroup>
- <ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
|
@@ -6,7 +6,6 @@ using NAnt.Core.Attributes;
using NAnt.Core.Util;
-using Migrator.NAnt.Loggers;
namespace Migrator.NAnt
{
@@ -64,7 +63,7 @@
protected override void ExecuteTask()
{
-
+
}
}
}
|
Loading...