Changeset 87a50ce52a32…
Parent eeb1f70b4867…
by
Changes to 6 files · Browse files at 87a50ce52a32 Showing diff from parent eeb1f70b4867 Diff from another changeset...
|
@@ -0,0 +1,10 @@ + syntax: glob
+app/console/bin/
+app/console/obj
+app/core/bin
+app/core/obj
+app/nant/bin
+app/nant/obj
+test/bin
+test/obj
+*.suo
|
@@ -230,10 +230,11 @@
private Migrator GetMigrator()
{
- GuidAttribute guidAttribute = (GuidAttribute)Attribute.GetCustomAttribute(GetAssembly(), typeof(GuidAttribute));
+ Assembly migAssem = GetAssembly();
+ GuidAttribute guidAttribute = (GuidAttribute)Attribute.GetCustomAttribute(migAssem, typeof(GuidAttribute));
// This is done incase we are scanning a 4.0 dll, the console is compiled against 4.0 so it can do all the assembly scanning
var logger = new Loggers.ConsoleLogger(_trace);
- return new Migrator(_provider, _connectionString, GetGeneralMigrations(), GetBeginMigration(), GetEndMigration(), guidAttribute, logger);
+ return new Migrator(_provider, _connectionString, migAssem, logger);
}
private void ParseArguments(string[] argv)
|
@@ -1,10 +1,3 @@ - // Project: Migrator, File: Migrator.cs
-// Namespace: Migrator, Class: Migrator
-// Path: C:\sandboxes\NexPort.Build\ThirdParty\Migrator\app\core, Author: danielpupek
-// Code lines: 348, Size of file: 10.13 KB
-// Creation date: 4/2/2007 1:36 PM
-// Last modified: 4/3/2007 9:29 AM
-// Version: $Revision: 1.6 $
#region License
@@ -26,6 +19,7 @@using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using System.Collections.Generic;
+using System.Linq;
#endregion
@@ -120,6 +114,7 @@ _provider = provider;
_logger = logger;
_provider.Logger = _logger;
+ ConfigMigrationSettings(migrationAssembly);
if (provider == null)
throw new ArgumentNullException("provider");
@@ -155,39 +150,28 @@ CheckForDuplicatedVersion();
}
- /// <summary>
- /// /
- /// </summary>
- /// <param name="provider"></param>
- /// <param name="connectionString"></param>
- /// <param name="migrations"></param>
- /// <param name="beginMigration"></param>
- /// <param name="endMigration"></param>
- /// <param name="assemblyAttribute"></param>
- /// <param name="logger"></param>
- public Migrator(string provider, string connectionString, ArrayList migrations, Migration beginMigration, Migration endMigration, GuidAttribute assemblyAttribute, ILogger logger)
- : this(CreateProvider(provider, connectionString), migrations, beginMigration, endMigration, assemblyAttribute, logger)
- { }
+
- /// <summary>
- ///
- /// </summary>
- /// <param name="provider"></param>
- /// <param name="migrations"></param>
- /// <param name="beginMigration"></param>
- /// <param name="endMigration"></param>
- /// <param name="assemblyAttribute"></param>
- /// <param name="logger"></param>
- public Migrator(TransformationProvider provider, ArrayList migrations, Migration beginMigration, Migration endMigration, GuidAttribute assemblyAttribute, ILogger logger)
+ /// <summary>
+ /// Extracts settings from the assembly
+ /// </summary>
+ /// <param name="migratingAssembly"></param>
+ private void ConfigMigrationSettings(Assembly migratingAssembly)
{
- logger = logger ?? new Log4NetLogger();
- _provider = provider;
- _provider.AssemblyId = assemblyAttribute != null ? assemblyAttribute.Value : null;
- _logger = logger;
- _provider.Logger = _logger;
- BeginMigration = beginMigration ?? new NullMigration();
- EndMigration = endMigration ?? new NullMigration();
- MigrationsTypes.AddRange(migrations);
+ var attributes = migratingAssembly.GetCustomAttributes(typeof(MigratorSettingsAttribute), false).Cast<MigratorSettingsAttribute>().ToList();
+ if (attributes.Count() > 0)
+ {
+ MigratorSettingsAttribute settings = attributes[0];
+
+ if(!string.IsNullOrEmpty(settings.SchemaInfoTableName)) _provider.SetSchemaInfoTable(settings.SchemaInfoTableName);
+
+ var guid = migratingAssembly.GetCustomAttributes(typeof(GuidAttribute), false).Cast<GuidAttribute>().ToList();
+ if (guid.Count > 0)
+ {
+ _provider.AssemblyId = guid[0].Value;
+ }
+
+ }
}
#endregion
@@ -404,8 +388,12 @@ this._logger.Log(string.Format("Current Version is v.{0}, no migration necessary.", this.CurrentVersion));
return;
}
- else if ((this.CurrentVersion > toVersion && this.GetMigration(toVersion + 1) == null) ||
- (this.CurrentVersion < toVersion && this.GetMigration(toVersion) == null))
+ else if (
+ toVersion > 0 && (
+ (this.CurrentVersion > toVersion && this.GetMigration(toVersion + 1) == null) ||
+ (this.CurrentVersion < toVersion && this.GetMigration(toVersion) == null)
+ )
+ )
{
this._logger.Warn(string.Format("Cannot Migrate from version {0}, to {1}. Migration for version {1} does not exist", this.CurrentVersion, toVersion));
return;
|
@@ -81,6 +81,7 @@ <Compile Include="Mappers\AbstractMapper.cs" />
<Compile Include="Mappers\MySqlMapper.cs" />
<Compile Include="Mappers\SqlMapper.cs" />
+ <Compile Include="MigratorSettingsAttribute.cs" />
<Compile Include="PrimaryKey.cs" />
<Compile Include="Providers\SqlParser.cs" />
<Compile Include="Table.cs" />
|
|
@@ -0,0 +1,18 @@ + using System;
+using System.Collections.Generic;
+using System.Linq;
+
+namespace Migrator
+{
+ /// <summary>
+ /// When placed on an assembly with migrations the migrator will extract settings from this attribute.
+ /// </summary>
+ [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = false)]
+ public class MigratorSettingsAttribute : Attribute
+ {
+ public string SchemaInfoTableName;
+ public MigratorSettingsAttribute() : this(string.Empty) { }
+ public MigratorSettingsAttribute(string schemaInfoTableName) { SchemaInfoTableName = schemaInfoTableName; }
+
+ }
+}
|
@@ -37,7 +37,7 @@ /// </summary>
public abstract class TransformationProvider : IDisposable
{
- protected const string SCHEMA_INFO_TABLE = "SchemaInfo";
+ protected string SCHEMA_INFO_TABLE = "SchemaInfo";
protected const string VERSION_COLUMN = "Version";
protected const string ASSEMBLY_ID_COLUMN = "AssemblyId";
@@ -154,6 +154,16 @@ /// <param name="tableName">Table name</param>
/// <returns><c>true</c> if the table exists</returns>
public abstract bool TableExists(string tableName);
+
+ /// <summary>
+ /// Sets the name of the schema info table
+ /// </summary>
+ /// <param name="schemaInfoTableName"></param>
+ internal void SetSchemaInfoTable(string schemaInfoTableName)
+ {
+ SCHEMA_INFO_TABLE = schemaInfoTableName;
+ Logger.Log("Using schema info table of [{0}]", schemaInfoTableName);
+ }
#endregion
#region Columns
|
Loading...