added better db migration support than what Subsonic provides out of the box.

This commit is contained in:
kay.one 2011-05-23 17:34:57 -07:00
commit ce63f05512
91 changed files with 7218 additions and 48 deletions

View file

@ -0,0 +1,35 @@
K 25
svn:wc:ra_dav:version-url
V 54
/svn/!svn/ver/120/trunk/src/Migrator.Framework/Loggers
END
Logger.cs
K 25
svn:wc:ra_dav:version-url
V 64
/svn/!svn/ver/120/trunk/src/Migrator.Framework/Loggers/Logger.cs
END
ConsoleWriter.cs
K 25
svn:wc:ra_dav:version-url
V 70
/svn/!svn/ver/73/trunk/src/Migrator.Framework/Loggers/ConsoleWriter.cs
END
IAttachableLogger.cs
K 25
svn:wc:ra_dav:version-url
V 75
/svn/!svn/ver/120/trunk/src/Migrator.Framework/Loggers/IAttachableLogger.cs
END
SqlScriptFileLogger.cs
K 25
svn:wc:ra_dav:version-url
V 77
/svn/!svn/ver/120/trunk/src/Migrator.Framework/Loggers/SqlScriptFileLogger.cs
END
ILogWriter.cs
K 25
svn:wc:ra_dav:version-url
V 68
/svn/!svn/ver/120/trunk/src/Migrator.Framework/Loggers/ILogWriter.cs
END

View file

@ -0,0 +1,198 @@
10
dir
147
http://migratordotnet.googlecode.com/svn/trunk/src/Migrator.Framework/Loggers
http://migratordotnet.googlecode.com/svn
2008-09-11T21:48:32.631850Z
120
geofflane
8c3eb3c4-eb3a-0410-862c-73fa8ce6028b
Logger.cs
file
2011-05-23T18:17:16.585003Z
24718815685110ea98d3f4207a358907
2008-09-11T21:48:32.631850Z
120
geofflane
4456
ConsoleWriter.cs
file
2011-05-23T18:17:16.587003Z
32bbf60aa8f07bbc281ac3be2da2a214
2008-04-24T03:58:41.677562Z
43
dkode8
838
IAttachableLogger.cs
file
2011-05-23T18:17:16.587003Z
e0226db3d0d21f0b59d7593f76835e9f
2008-09-11T21:48:32.631850Z
120
geofflane
1114
SqlScriptFileLogger.cs
file
2011-05-23T18:17:16.589003Z
bb2a95971af988525878e60b8cdb21a7
2008-09-11T21:48:32.631850Z
120
geofflane
2527
ILogWriter.cs
file
2011-05-23T18:17:16.590003Z
53fd3ec26d0d191e9d4ae77530e5d928
2008-09-11T21:48:32.631850Z
120
geofflane
1088

View file

@ -0,0 +1,28 @@
#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;
namespace Migrator.Framework.Loggers
{
public class ConsoleWriter : ILogWriter
{
public void Write(string message, params object[] args)
{
Console.Write(message, args);
}
public void WriteLine(string message, params object[] args)
{
Console.WriteLine(message, args);
}
}
}

View file

@ -0,0 +1,33 @@
#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
namespace Migrator.Framework.Loggers
{
/// <summary>
/// ILogger interface.
/// Implicit in this interface is that the logger will delegate actual
/// logging to the <see cref="ILogWriter"/>(s) that have been attached
/// </summary>
public interface IAttachableLogger: ILogger
{
/// <summary>
/// Attach an <see cref="ILogWriter"/>
/// </summary>
/// <param name="writer"></param>
void Attach(ILogWriter writer);
/// <summary>
/// Detach an <see cref="ILogWriter"/>
/// </summary>
/// <param name="writer"></param>
void Detach(ILogWriter writer);
}
}

View file

@ -0,0 +1,33 @@
#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
namespace Migrator.Framework.Loggers
{
/// <summary>
/// Handles writing a message to the log medium (i.e. file, console)
/// </summary>
public interface ILogWriter
{
/// <summary>
/// Write this message
/// </summary>
/// <param name="message"></param>
/// <param name="args"></param>
void Write(string message, params object[] args);
/// <summary>
/// Write this message, as a line
/// </summary>
/// <param name="message"></param>
/// <param name="args"></param>
void WriteLine(string message, params object[] args);
}
}

View file

@ -0,0 +1,169 @@
#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 System.Collections.Generic;
namespace Migrator.Framework.Loggers
{
/// <summary>
/// Text logger for the migration mediator
/// </summary>
public class Logger : IAttachableLogger
{
private readonly bool _trace;
private readonly List<ILogWriter> _writers = new List<ILogWriter>();
public Logger(bool trace)
{
_trace = trace;
}
public Logger(bool trace, params ILogWriter[] writers)
: this(trace)
{
_writers.AddRange(writers);
}
public void Attach(ILogWriter writer)
{
_writers.Add(writer);
}
public void Detach(ILogWriter writer)
{
_writers.Remove(writer);
}
public void Started(long currentVersion, long finalVersion)
{
WriteLine("Current version : {0}. Target version : {1}", currentVersion, finalVersion);
}
public void Started(List<long> currentVersions, long finalVersion)
{
WriteLine("Latest version applied : {0}. Target version : {1}", LatestVersion(currentVersions), finalVersion);
}
public void MigrateUp(long version, string migrationName)
{
WriteLine("Applying {0}: {1}", version.ToString(), migrationName);
}
public void MigrateDown(long version, string migrationName)
{
WriteLine("Removing {0}: {1}", version.ToString(), migrationName);
}
public void Skipping(long version)
{
WriteLine("{0} {1}", version.ToString(), "<Migration not found>");
}
public void RollingBack(long originalVersion)
{
WriteLine("Rolling back to migration {0}", originalVersion);
}
public void ApplyingDBChange(string sql)
{
Log(sql);
}
public void Exception(long version, string migrationName, Exception ex)
{
WriteLine("============ Error Detail ============");
WriteLine("Error in migration: {0}", version);
LogExceptionDetails(ex);
WriteLine("======================================");
}
public void Exception(string message, Exception ex)
{
WriteLine("============ Error Detail ============");
WriteLine("Error: {0}", message);
LogExceptionDetails(ex);
WriteLine("======================================");
}
private void LogExceptionDetails(Exception ex)
{
WriteLine("{0}", ex.Message);
WriteLine("{0}", ex.StackTrace);
Exception iex = ex.InnerException;
while (iex != null)
{
WriteLine("Caused by: {0}", iex);
WriteLine("{0}", ex.StackTrace);
iex = iex.InnerException;
}
}
public void Finished(long originalVersion, long currentVersion)
{
WriteLine("Migrated to version {0}", currentVersion);
}
public void Finished(List<long> originalVersions, long currentVersion)
{
WriteLine("Migrated to version {0}", currentVersion);
}
public void Log(string format, params object[] args)
{
WriteLine(format, args);
}
public void Warn(string format, params object[] args)
{
Write("Warning! : ");
WriteLine(format, args);
}
public void Trace(string format, params object[] args)
{
if (_trace)
{
Log(format, args);
}
}
private void Write(string message, params object[] args)
{
foreach (ILogWriter writer in _writers)
{
writer.Write(message, args);
}
}
private void WriteLine(string message, params object[] args)
{
foreach (ILogWriter writer in _writers)
{
writer.WriteLine(message, args);
}
}
public static ILogger ConsoleLogger()
{
return new Logger(false, new ConsoleWriter());
}
private string LatestVersion(List<long> versions)
{
if (versions.Count > 0)
{
return versions[versions.Count - 1].ToString();
}
return "No migrations applied yet!";
}
}
}

View file

@ -0,0 +1,93 @@
using System;
using System.Collections.Generic;
using System.IO;
namespace Migrator.Framework.Loggers
{
public class SqlScriptFileLogger : ILogger, IDisposable
{
private readonly ILogger _innerLogger;
private TextWriter _streamWriter;
public SqlScriptFileLogger(ILogger logger, TextWriter streamWriter)
{
_innerLogger = logger;
_streamWriter = streamWriter;
}
#region IDisposable Members
public void Dispose()
{
if (_streamWriter != null)
{
_streamWriter.Dispose();
_streamWriter = null;
}
}
#endregion
public void Log(string format, params object[] args)
{
_innerLogger.Log(format, args);
}
public void Warn(string format, params object[] args)
{
_innerLogger.Warn(format, args);
}
public void Trace(string format, params object[] args)
{
_innerLogger.Trace(format, args);
}
public void ApplyingDBChange(string sql)
{
_innerLogger.ApplyingDBChange(sql);
_streamWriter.WriteLine(sql);
}
public void Started(List<long> appliedVersions, long finalVersion)
{
_innerLogger.Started(appliedVersions, finalVersion);
}
public void MigrateUp(long version, string migrationName)
{
_innerLogger.MigrateUp(version, migrationName);
}
public void MigrateDown(long version, string migrationName)
{
_innerLogger.MigrateDown(version, migrationName);
}
public void Skipping(long version)
{
_innerLogger.Skipping(version);
}
public void RollingBack(long originalVersion)
{
_innerLogger.RollingBack(originalVersion);
}
public void Exception(long version, string migrationName, Exception ex)
{
_innerLogger.Exception(version, migrationName, ex);
}
public void Exception(string message, Exception ex)
{
_innerLogger.Exception(message, ex);
}
public void Finished(List<long> appliedVersions, long currentVersion)
{
_innerLogger.Finished(appliedVersions, currentVersion);
_streamWriter.Close();
}
}
}

View file

@ -0,0 +1,28 @@
#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;
namespace Migrator.Framework.Loggers
{
public class ConsoleWriter : ILogWriter
{
public void Write(string message, params object[] args)
{
Console.Write(message, args);
}
public void WriteLine(string message, params object[] args)
{
Console.WriteLine(message, args);
}
}
}

View file

@ -0,0 +1,33 @@
#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
namespace Migrator.Framework.Loggers
{
/// <summary>
/// ILogger interface.
/// Implicit in this interface is that the logger will delegate actual
/// logging to the <see cref="ILogWriter"/>(s) that have been attached
/// </summary>
public interface IAttachableLogger: ILogger
{
/// <summary>
/// Attach an <see cref="ILogWriter"/>
/// </summary>
/// <param name="writer"></param>
void Attach(ILogWriter writer);
/// <summary>
/// Detach an <see cref="ILogWriter"/>
/// </summary>
/// <param name="writer"></param>
void Detach(ILogWriter writer);
}
}

View file

@ -0,0 +1,33 @@
#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
namespace Migrator.Framework.Loggers
{
/// <summary>
/// Handles writing a message to the log medium (i.e. file, console)
/// </summary>
public interface ILogWriter
{
/// <summary>
/// Write this message
/// </summary>
/// <param name="message"></param>
/// <param name="args"></param>
void Write(string message, params object[] args);
/// <summary>
/// Write this message, as a line
/// </summary>
/// <param name="message"></param>
/// <param name="args"></param>
void WriteLine(string message, params object[] args);
}
}

View file

@ -0,0 +1,169 @@
#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 System.Collections.Generic;
namespace Migrator.Framework.Loggers
{
/// <summary>
/// Text logger for the migration mediator
/// </summary>
public class Logger : IAttachableLogger
{
private readonly bool _trace;
private readonly List<ILogWriter> _writers = new List<ILogWriter>();
public Logger(bool trace)
{
_trace = trace;
}
public Logger(bool trace, params ILogWriter[] writers)
: this(trace)
{
_writers.AddRange(writers);
}
public void Attach(ILogWriter writer)
{
_writers.Add(writer);
}
public void Detach(ILogWriter writer)
{
_writers.Remove(writer);
}
public void Started(long currentVersion, long finalVersion)
{
WriteLine("Current version : {0}. Target version : {1}", currentVersion, finalVersion);
}
public void Started(List<long> currentVersions, long finalVersion)
{
WriteLine("Latest version applied : {0}. Target version : {1}", LatestVersion(currentVersions), finalVersion);
}
public void MigrateUp(long version, string migrationName)
{
WriteLine("Applying {0}: {1}", version.ToString(), migrationName);
}
public void MigrateDown(long version, string migrationName)
{
WriteLine("Removing {0}: {1}", version.ToString(), migrationName);
}
public void Skipping(long version)
{
WriteLine("{0} {1}", version.ToString(), "<Migration not found>");
}
public void RollingBack(long originalVersion)
{
WriteLine("Rolling back to migration {0}", originalVersion);
}
public void ApplyingDBChange(string sql)
{
Log(sql);
}
public void Exception(long version, string migrationName, Exception ex)
{
WriteLine("============ Error Detail ============");
WriteLine("Error in migration: {0}", version);
LogExceptionDetails(ex);
WriteLine("======================================");
}
public void Exception(string message, Exception ex)
{
WriteLine("============ Error Detail ============");
WriteLine("Error: {0}", message);
LogExceptionDetails(ex);
WriteLine("======================================");
}
private void LogExceptionDetails(Exception ex)
{
WriteLine("{0}", ex.Message);
WriteLine("{0}", ex.StackTrace);
Exception iex = ex.InnerException;
while (iex != null)
{
WriteLine("Caused by: {0}", iex);
WriteLine("{0}", ex.StackTrace);
iex = iex.InnerException;
}
}
public void Finished(long originalVersion, long currentVersion)
{
WriteLine("Migrated to version {0}", currentVersion);
}
public void Finished(List<long> originalVersions, long currentVersion)
{
WriteLine("Migrated to version {0}", currentVersion);
}
public void Log(string format, params object[] args)
{
WriteLine(format, args);
}
public void Warn(string format, params object[] args)
{
Write("Warning! : ");
WriteLine(format, args);
}
public void Trace(string format, params object[] args)
{
if (_trace)
{
Log(format, args);
}
}
private void Write(string message, params object[] args)
{
foreach (ILogWriter writer in _writers)
{
writer.Write(message, args);
}
}
private void WriteLine(string message, params object[] args)
{
foreach (ILogWriter writer in _writers)
{
writer.WriteLine(message, args);
}
}
public static ILogger ConsoleLogger()
{
return new Logger(false, new ConsoleWriter());
}
private string LatestVersion(List<long> versions)
{
if (versions.Count > 0)
{
return versions[versions.Count - 1].ToString();
}
return "No migrations applied yet!";
}
}
}

View file

@ -0,0 +1,93 @@
using System;
using System.Collections.Generic;
using System.IO;
namespace Migrator.Framework.Loggers
{
public class SqlScriptFileLogger : ILogger, IDisposable
{
private readonly ILogger _innerLogger;
private TextWriter _streamWriter;
public SqlScriptFileLogger(ILogger logger, TextWriter streamWriter)
{
_innerLogger = logger;
_streamWriter = streamWriter;
}
#region IDisposable Members
public void Dispose()
{
if (_streamWriter != null)
{
_streamWriter.Dispose();
_streamWriter = null;
}
}
#endregion
public void Log(string format, params object[] args)
{
_innerLogger.Log(format, args);
}
public void Warn(string format, params object[] args)
{
_innerLogger.Warn(format, args);
}
public void Trace(string format, params object[] args)
{
_innerLogger.Trace(format, args);
}
public void ApplyingDBChange(string sql)
{
_innerLogger.ApplyingDBChange(sql);
_streamWriter.WriteLine(sql);
}
public void Started(List<long> appliedVersions, long finalVersion)
{
_innerLogger.Started(appliedVersions, finalVersion);
}
public void MigrateUp(long version, string migrationName)
{
_innerLogger.MigrateUp(version, migrationName);
}
public void MigrateDown(long version, string migrationName)
{
_innerLogger.MigrateDown(version, migrationName);
}
public void Skipping(long version)
{
_innerLogger.Skipping(version);
}
public void RollingBack(long originalVersion)
{
_innerLogger.RollingBack(originalVersion);
}
public void Exception(long version, string migrationName, Exception ex)
{
_innerLogger.Exception(version, migrationName, ex);
}
public void Exception(string message, Exception ex)
{
_innerLogger.Exception(message, ex);
}
public void Finished(List<long> appliedVersions, long currentVersion)
{
_innerLogger.Finished(appliedVersions, currentVersion);
_streamWriter.Close();
}
}
}