Changeset 405057187903…
Parent eabffc86b1eb…
by Daniel Pupek
Changes to 22 files · Browse files at 405057187903 Showing diff from parent eabffc86b1eb Diff from another changeset...
|
@@ -0,0 +1,24 @@ + Database migrator - v@(Model.Version.Major).@(Model.Version.Minor).@(Model.Version.Revision)
+
+usage:
+Migrator.Console.exe provider connectionString
+ migrationsAssembly [options]
+
+provider The database provider
+ (SqlServer, MySql, Postgre)
+connectionString Connection string to the
+ database
+migrationAssembly Path to the assembly
+ containing the migrations
+
+Options:
+-to=<version> Migrates to specified version
+-up Migrates up a version
+-down Migrates down a version
+-list List migrations
+-trace Show debug informations
+-h, -help, -? Prints this message
+
+Reamarks:
+-up, -down, and -to options are mutually
+exclusive
\ No newline at end of file |
@@ -9,7 +9,7 @@ <OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Migrator.Console</RootNamespace>
- <AssemblyName>Migrator.Console</AssemblyName>
+ <AssemblyName>migrator-cli</AssemblyName>
<SccProjectName>
</SccProjectName>
<SccLocalPath>
@@ -44,8 +44,14 @@ <WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
+ <Reference Include="RazorEngine">
+ <HintPath>..\..\packages\RazorEngine.3.3.0\lib\net40\RazorEngine.dll</HintPath>
+ </Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
+ <Reference Include="System.Web.Razor">
+ <HintPath>..\..\packages\Microsoft.AspNet.Razor.2.0.30506.0\lib\net40\System.Web.Razor.dll</HintPath>
+ </Reference>
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
@@ -62,6 +68,10 @@ <None Include="app.config">
<SubType>Designer</SubType>
</None>
+ <None Include="packages.config" />
+ </ItemGroup>
+ <ItemGroup>
+ <EmbeddedResource Include="HelpText.txt" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>
\ No newline at end of file |
|
|
@@ -15,6 +15,7 @@ using System.Collections.Generic;
using System.Collections;
using System.Runtime.InteropServices;
+using RazorEngine;
namespace Migrator.MigratorConsole
{
@@ -27,15 +28,14 @@ private string _provider;
private string _connectionString;
private string _migrationsAssembly;
- private bool _list = false;
+ private bool ListMigrations = false;
private bool _trace = false;
private string _dumpTo;
private int _migrateTo = -1;
private bool _migrateUp = false;
private bool _migrateDown = false;
- private bool allParamsSpecified = true;
-
+
/// <summary>
/// Builds a new console
/// </summary>
@@ -51,7 +51,7 @@ catch (ArgumentException ex)
{
Console.Out.Write(ex.Message);
- allParamsSpecified = false;
+
}
}
@@ -61,16 +61,18 @@ /// <returns>-1 if error, else 0</returns>
public int Run()
{
- if (!allParamsSpecified)
- return 1;
try
{
- if (_list)
- List();
- else if (_dumpTo != null)
- Dump();
- else
- Migrate();
+ if (ShowHelp)
+ {
+ PrintUsage();
+ }
+ else if (ListMigrations)
+ List();
+ else if (_dumpTo != null)
+ Dump();
+ else
+ Migrate();
}
catch (ArgumentException aex)
{
@@ -128,6 +130,9 @@ }
}
+ /// <summary>
+ ///
+ /// </summary>
public void Dump()
{
CheckArguments();
@@ -143,23 +148,13 @@ public void PrintUsage()
{
int tab = 17;
- Version ver = Assembly.GetExecutingAssembly().GetName().Version;
+ var executingAssembly = Assembly.GetExecutingAssembly();
+ Version ver = executingAssembly.GetName().Version;
- Console.WriteLine("Database migrator - v{0}.{1}.{2}", ver.Major, ver.Minor, ver.Revision);
- Console.WriteLine();
- Console.WriteLine("usage:\nMigrator.Console.exe provider connectionString migrationsAssembly [options]");
- Console.WriteLine();
- Console.WriteLine("\t{0} {1}", "provider".PadRight(tab), "The database provider (SqlServer, MySql, Postgre)");
- Console.WriteLine("\t{0} {1}", "connectionString".PadRight(tab), "Connection string to the database");
- Console.WriteLine("\t{0} {1}", "migrationAssembly".PadRight(tab), "Path to the assembly containing the migrations");
- Console.WriteLine("Options:");
- Console.WriteLine("\t-{0}{1}", "to=<version>".PadRight(tab), "Migrats to specified version");
- Console.WriteLine("\t-{0}{1}", "up".PadRight(tab), "Migrates up a version");
- Console.WriteLine("\t-{0}{1}", "down".PadRight(tab), "Migrates down a version");
- Console.WriteLine("\t-{0}{1}", "list".PadRight(tab), "List migrations");
- Console.WriteLine("\t-{0}{1}", "trace".PadRight(tab), "Show debug informations");
- Console.WriteLine();
- Console.WriteLine("-up, -down, and -to options are mutually exclusive");
+
+ var text = new StreamReader(executingAssembly.GetManifestResourceStream("Migrator.Console.HelpText.txt")).ReadToEnd();
+ Console.Write(Razor.Parse(text, new {Version=ver}, "helpText"));
+
}
#region Private helper methods
@@ -199,33 +194,20 @@
}
- private ArrayList GetGeneralMigrations()
- {
- ArrayList migrations = new ArrayList();
-
- foreach (Type t in GetAssembly().GetTypes())
- {
- MigrationAttribute attrib = (MigrationAttribute)
- Attribute.GetCustomAttribute(t, typeof(MigrationAttribute));
- if (attrib != null && typeof(Migration).IsAssignableFrom(t))
- {
- if (!attrib.Ignore)
- {
- migrations.Add(t);
- }
- }
- }
-
- migrations.Sort(new MigrationTypeComparer(true));
- return migrations;
- }
+
private void CheckArguments()
{
- if (_connectionString == null)
- throw new ArgumentException("Connection string missing", "connectionString");
- if (_migrationsAssembly == null)
- throw new ArgumentException("Migrations assembly missing", "migrationsAssembly");
+ List<String> messages = new List<String>();
+ if (!ListMigrations && !ShowHelp)
+ {
+ if (!(_migrateUp ^ _migrateDown ^ _migrateTo > 0) && !(_migrateTo < 0)) messages.Add("You must specify only one up, down, or to command.");
+ if (_provider == null) messages.Add("Provider not specified (SqlServer, MySql, Postgre).");
+ if (_connectionString == null) messages.Add("Connection string not specified.");
+ if (_migrationsAssembly == null) messages.Add("Migration assembly not specified");
+ if (messages.Count > 0)
+ throw new ArgumentException("\n\n" + String.Join(" \n", messages.ToArray()) + "\n\n");
+ }
}
private Migrator GetMigrator()
@@ -243,8 +225,12 @@ {
if (argv[i].ToLower().Equals("-list"))
{
- _list = true;
+ ListMigrations = true;
}
+ else if (argv[i].ToLower().Equals("-?") || argv[i].ToLower().Equals("-h") || argv[i].ToLower().Equals("-help"))
+ {
+ ShowHelp = true;
+ }
else if (argv[i].ToLower().Equals("-trace"))
{
_trace = true;
@@ -269,17 +255,14 @@ if (i == 2) _migrationsAssembly = argv[i];
}
}
- List<String> messages = new List<String>();
- if (!_list && argv.Length > 0)
- {
- if (!(_migrateUp ^ _migrateDown ^ _migrateTo > 0) && !(_migrateTo < 0)) messages.Add("You must specify only one up, down, or to command.");
- if (_provider == null) messages.Add("Provider not specified (SqlServer, MySql, Postgre).");
- if (_connectionString == null) messages.Add("Connection string not specified.");
- if (_migrationsAssembly == null) messages.Add("Migration assembly not specified");
- if (messages.Count > 0)
- throw new ArgumentException("\n\n" + String.Join(" \n", messages.ToArray()) + "\n\n");
- }
+
}
- #endregion
+
+ /// <summary>
+ /// If true then the user would like to see help
+ /// </summary>
+ public bool ShowHelp { get; set; }
+
+ #endregion
}
}
|
|
@@ -0,0 +1,5 @@ + <?xml version="1.0" encoding="utf-8"?>
+<packages>
+ <package id="Microsoft.AspNet.Razor" version="2.0.30506.0" targetFramework="net40" />
+ <package id="RazorEngine" version="3.3.0" targetFramework="net40" />
+</packages>
\ No newline at end of file |
@@ -10,25 +10,30 @@ #endregion
using System;
using System.Collections;
+using System.Collections.Generic;
namespace Migrator
{
/// <summary>
/// Comparer of Migration by their version attribute.
/// </summary>
- public class MigrationTypeComparer : IComparer
+ public class MigrationTypeComparer : IComparer<Type>
{
private bool _ascending = true;
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="ascending"></param>
public MigrationTypeComparer(bool ascending)
{
_ascending = ascending;
}
- public int Compare(object x, object y)
+ public int Compare(Type x, Type y)
{
- MigrationAttribute attribOfX = (MigrationAttribute) Attribute.GetCustomAttribute((Type) x, typeof(MigrationAttribute));
- MigrationAttribute attribOfY = (MigrationAttribute) Attribute.GetCustomAttribute((Type) y, typeof(MigrationAttribute));
+ var attribOfX = (MigrationAttribute) Attribute.GetCustomAttribute( x, typeof(MigrationAttribute));
+ var attribOfY = (MigrationAttribute) Attribute.GetCustomAttribute( y, typeof(MigrationAttribute));
if (_ascending)
return attribOfX.Version - attribOfY.Version;
|
|
|
@@ -32,7 +32,7 @@ {
#region Fields
private TransformationProvider _provider;
- private IEnumerable<Type> _migrationsTypes = new List<Type>();
+ private List<Type> _migrationsTypes = new List<Type>();
private ILogger _logger = new NullLogger();
private log4net.ILog _log4netlogger = log4net.LogManager.GetLogger("Migrator");
private Dictionary<string, string> _parameters;
@@ -103,56 +103,55 @@ : this(CreateProvider(provider, connectionString), Assembly.GetExecutingAssembly(), new Log4NetLogger())
{ }
- /// <summary>
- ///
- /// </summary>
- /// <param name="provider"></param>
- /// <param name="migrationAssembly"></param>
- /// <param name="logger"></param>
- public Migrator(TransformationProvider provider, Assembly migrationAssembly, ILogger logger)
- {
- _provider = provider;
- _logger = logger;
- _provider.Logger = _logger;
- ConfigMigrationSettings(migrationAssembly);
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="provider"></param>
+ /// <param name="migrationAssembly"></param>
+ /// <param name="logger"></param>
+ public Migrator(TransformationProvider provider, Assembly migrationAssembly, ILogger logger)
+ {
+ _provider = provider;
+ _logger = logger;
+ _provider.Logger = _logger;
+ ConfigMigrationSettings(migrationAssembly);
- if (provider == null)
- throw new ArgumentNullException("provider");
+ if (provider == null)
+ throw new ArgumentNullException("provider");
- if (migrationAssembly == null)
- {
- _logger.Exception("Migration assembly not provided.", new ArgumentNullException("migrationAssembly"));
- throw new Exception("Assembly not found");
- }
+ if (migrationAssembly == null)
+ {
+ _logger.Exception("Migration assembly not provided.", new ArgumentNullException("migrationAssembly"));
+ throw new Exception("Assembly not found");
+ }
- if (migrationAssembly != null)
- _logger.Log("Performing migrations for {0}", migrationAssembly.FullName);
- // add all providers to the "all providers" list
- if (this._additionalProviders != null)
- {
- foreach (TransformationProvider p in this._additionalProviders.Values)
- {
- this._allProviders.Add(p);
- }
- }
- this._allProviders.Add(_provider);
+ _logger.Log("Performing migrations for {0}", migrationAssembly.FullName);
+ // add all providers to the "all providers" list
+ if (this._additionalProviders != null)
+ {
+ foreach (TransformationProvider p in this._additionalProviders.Values)
+ {
+ this._allProviders.Add(p);
+ }
+ }
+ this._allProviders.Add(_provider);
- // only load the migrations for the given assembly
- if (migrationAssembly != null)
- {
- _migrationsTypes.AddRange(GetMigrationTypes(migrationAssembly));
- this.BeginMigration = GetBeginMigration(migrationAssembly);
- this.EndMigration = GetEndMigration(migrationAssembly);
- }
- CheckForDuplicatedVersion();
- }
+ // only load the migrations for the given assembly
-
+ _migrationsTypes = GetMigrationTypes(migrationAssembly).ToList();
- /// <summary>
+ this.BeginMigration = GetBeginMigration(migrationAssembly);
+ this.EndMigration = GetEndMigration(migrationAssembly);
+
+ CheckForDuplicatedVersion();
+ }
+
+
+
+ /// <summary>
/// Extracts settings from the assembly
/// </summary>
/// <param name="migratingAssembly"></param>
@@ -192,9 +191,14 @@ {
get
{
- if (_migrationsTypes.Count == 0)
+ if (!MigrationsTypes.Any())
return 0;
- return GetMigrationVersion((Type)_migrationsTypes[_migrationsTypes.Count - 1]);
+
+ var migrations = from m in MigrationsTypes
+ orderby GetMigrationVersion(m) descending
+ select GetMigrationVersion(m);
+
+ return migrations.First();
}
}
@@ -212,14 +216,14 @@ /// </summary>
public int LatestVersion
{
- get { return _provider.CurrentVersion; }
+ get { return _provider.GetLatestVersion(_provider.AssemblyId); }
}
/// <summary>
/// Returns registered migration <see cref="System.Type">types</see>.
/// </summary>
- public IEnumerable<Type> MigrationsTypes
+ public List<Type> MigrationsTypes
{
get { return _migrationsTypes; }
}
@@ -344,9 +348,9 @@ /// </summary>
/// <param name="asm">The <c>Assembly</c> to browse.</param>
/// <returns>The migrations collection</returns>
- public static ArrayList GetMigrationTypes(Assembly asm)
+ public static IEnumerable<Type> GetMigrationTypes(Assembly asm)
{
- ArrayList migrations = new ArrayList();
+ var migrations = new List<Type>();
foreach (Type t in asm.GetTypes())
{
@@ -380,7 +384,9 @@ /// <param name="toVersion">Version that you wish the database to be at the end of the migration</param>
public void MigrateTo(int toVersion)
{
- int originalVersion = this.LatestVersion;
+ GetReady();
+
+ int originalVersion = this.LatestVersion;
int executingMigrationVersion = this.LatestVersion;
// check for cases where migration is unnecessary or impossible
@@ -415,7 +421,7 @@ else
migratedVersions = InternalMigrateDownTo(toVersion);
- _provider.CreateSchemaInfoTable();
+ _provider.CreateMigrationTrackingTable();
this.CommitTransactions();
this._logger.Finished(originalVersion, this.LatestVersion);
@@ -446,8 +452,6 @@ {
var currentMigration = migrations.Dequeue();
var version = GetMigrationVersion(currentMigration.GetType());
-
- GetReady();
this._logger.MigrateDown(version, GetMigrationDescription(currentMigration.GetType()));
currentMigration.Down();
@@ -499,11 +503,11 @@
var queue = new Queue<Migration>();
- foreach (var mtype in MigrationsTypes)
+ foreach (var mtype in MigrationsTypes.OrderBy(GetMigrationVersion))
{
var version = GetMigrationVersion(mtype);
- if (version <= toVersion && !HasMigrationRun(version))
+ if (version <= toVersion && !_provider.HasMigrationRun(version))
{
queue.Enqueue(GetMigration(version));
}
@@ -523,11 +527,11 @@
var queue = new Queue<Migration>();
- foreach (var mtype in MigrationsTypes)
+ foreach (var mtype in MigrationsTypes.OrderByDescending(GetMigrationVersion))
{
var version = GetMigrationVersion(mtype);
- if (version >= toVersion && HasMigrationRun(version))
+ if (version >= toVersion && _provider.HasMigrationRun(version))
{
queue.Enqueue(GetMigration(version));
}
@@ -537,11 +541,7 @@ return queue;
}
- private bool HasMigrationRun(int version)
- {
- _provider.ExecuteQuery("Select Top 1 From ")
- throw new NotImplementedException();
- }
+
/// <summary>
/// Migrate Up to the next version, if it exists
@@ -549,11 +549,18 @@ public void MigrateUp()
{
GetReady();
+
+ if (this.LatestVersion < this.LastVersion)
+ {
+ // Find the next version
+ var nextVersion = GetMigrationVersion(MigrationsTypes.Where(m=>GetMigrationVersion(m) > LatestVersion).OrderBy(GetMigrationVersion).First());
- if (this.LatestVersion < this.LastVersion)
- this.MigrateTo(this.LatestVersion + 1);
- else
- this.MigrateTo(this.LatestVersion);
+ this.MigrateTo(nextVersion);
+ }
+ else
+ {
+ this.MigrateTo(this.LatestVersion);
+ }
}
/// <summary>
@@ -563,10 +570,14 @@ {
GetReady();
- if (this.LatestVersion > 0)
- this.MigrateTo(this.LatestVersion - 1);
- else
- this.MigrateTo(this.LatestVersion);
+ if (this.LatestVersion > 0)
+ {
+ // Find the next version
+ var nextVersion = GetMigrationVersion(MigrationsTypes.Where(m => GetMigrationVersion(m) < LatestVersion).OrderByDescending(GetMigrationVersion).First());
+ this.MigrateTo(nextVersion);
+ }
+ else
+ this.MigrateTo(this.LatestVersion);
}
/// <summary>
@@ -574,7 +585,6 @@ /// </summary>
public void MigrateToLastVersion()
{
- GetReady();
MigrateTo(LastVersion);
}
@@ -638,19 +648,13 @@ /// <returns></returns>
private void GetReady()
{
- if (MigrationsTypes.Count < 1)
+ if (!MigrationsTypes.Any())
{
_logger.Exception("Migration assembly not provided.", new ArgumentNullException("migrationAssembly"));
throw new Exception("No migrations found");
}
- //// Enshure that the Schema Info table is created
- //GuidAttribute guid = AssemblyGuid;
- //if (guid != null)
- // _provider.CreateSchemaInfoTable(guid.Value);
- //else
- // _provider.CreateSchemaInfoTable();
-
+
// Print a list of loaded Migrations
_logger.Trace("Loaded migrations:");
foreach (Type t in _migrationsTypes)
@@ -663,7 +667,7 @@ private Type GetMigrationType(int version)
{
// since the list is sorted and contiguous getting an item is simple:
- return (Type)_migrationsTypes[version - 1];
+ return _migrationsTypes.FirstOrDefault(m => GetMigrationVersion(m) == version);
}
private Migration GetMigration(int version)
@@ -694,7 +698,7 @@ /// <exception cref="CheckForDuplicatedVersion">CheckForDuplicatedVersion</exception>
public void CheckForDuplicatedVersion()
{
- ArrayList versions = new ArrayList();
+ var versions = new List<int>();
foreach (Type t in _migrationsTypes)
{
@@ -704,15 +708,6 @@
versions.Add(version);
}
-
- // check that the versions of the migrations are contiguous from 1 to n:
- versions.Sort();
- if (versions.Count > 0)
- {
- int maxVersion = (int)versions[versions.Count - 1];
- if (versions.Count != maxVersion)
- throw new ArgumentOutOfRangeException(String.Format("There are {0} Migrations but the highest version is {1}. The Migrations are not contiguous.", versions.Count, maxVersion));
- }
}
#endregion
}
|
|
@@ -551,7 +551,7 @@ /// already existed but the AssemblyId column is missing
/// </remarks>
/// <param name="assemblyId"></param>
- public virtual void CreateSchemaInfoTable()
+ public virtual void CreateMigrationTrackingTable()
{
EnsureHasConnection();
@@ -565,7 +565,6 @@ // We have what we needed
ExecuteNonQuery("DELETE from {0} WHERE AssemblyId = {1}", OldSchemaInfoTable, AssemblyId);
-
}
// create the Schema Info table to store the latest migration version
@@ -582,31 +581,19 @@
for (var i = 1; i <= oldVersion; i++)
{
- this.RecordMigration(i, AssemblyId); // bring over any previous verion
+ this.RecordMigration(i); // bring over any previous verion
}
}
}
- /// <summary>
- /// Get the current version of the database.
- /// This determines if the migrator should migrate up or down
- /// in the migration numbers.
- /// </summary>
- /// <remark>
- /// This value should not be modified inside a migration.
- /// </remark>
- public virtual int CurrentVersion
- {
- get { return GetLatestVersion(AssemblyId); }
-
- }
+
/// <summary>
/// Get the version from the SchemaInfo Table
/// </summary>
/// <returns>The current version</returns>
- protected virtual int GetLatestVersion(String assemblyId)
+ public virtual int GetLatestVersion(String assemblyId)
{
if (assemblyId == null) return 0; // No schema info.
if (!TableExists(MigrationsTrackingTable)) return 0;
@@ -614,23 +601,55 @@ return (int)ExecuteScalar(String.Format("SELECT Top 1 Version FROM {1} WHERE AssemblyId='{0}' Order By Version Desc", assemblyId, MigrationsTrackingTable));
}
+ /// <summary>
+ /// Record the current version in the Migration Tracking Table
+ /// USING UTCNOW
+ /// </summary>
+ /// <param name="version">the new version to set</param>
+ /// <param name="date"></param>
+ protected virtual void RecordMigration(int version)
+ {
+ RecordMigration(version, DateTime.UtcNow);
+ }
+
/// <summary>
- /// Record the current version in the Migration Tracking Table
+ /// Record the current version in the Migration Tracking Table
+ /// USING THE GIVEN DATE
/// </summary>
/// <param name="version">the new version to set</param>
- /// <param name="assemblyId"></param>
/// <param name="date"></param>
- protected virtual void RecordMigration(int version, String assemblyId, DateTime date = DateTime.UtcNow)
+ protected virtual void RecordMigration(int version, DateTime date)
{
- if (assemblyId == null)
- throw new ArgumentException();
+ if (AssemblyId == null)
+ throw new NullReferenceException("AssemblyId cannot be null.");
+
+ CreateMigrationTrackingTable();
- if (!TableExists(MigrationsTrackingTable))
- CreateSchemaInfoTable();
- // TODO: needs to do an update if required
- ExecuteNonQuery(string.Format("INSERT INTO {1} (Version, AssemblyId, UtcDateMigratedColumn) VALUES ({2}, '{0}', '{3}')", assemblyId, MigrationsTrackingTable, version, date));
+ if (HasMigrationRun(version))
+ {
+ ExecuteNonQuery(
+ "UPDATE {1} Set UtcDateMigratedColumn = '{3}' WHERE AssemblyId = '{0}' AND Version = {2}",
+ AssemblyId, MigrationsTrackingTable, version, date);
+ }
+ else
+ {
+
+ ExecuteNonQuery(
+ "INSERT INTO {1} (Version, AssemblyId, UtcDateMigratedColumn) VALUES ({2}, '{0}', '{3}')",
+ AssemblyId, MigrationsTrackingTable, version, date);
+ }
}
-
+
+ /// <summary>
+ /// Determins if a migration has been run already
+ /// </summary>
+ /// <param name="version"></param>
+ /// <returns></returns>
+ public bool HasMigrationRun(int version)
+ {
+ var reader = ExecuteQuery("Select Top 1 Version From {0} WHERE Version = {1} AND AssemblyId = '{2}'", MigrationsTrackingTable, version, AssemblyId);
+ return reader.Read();
+ }
#endregion
@@ -700,7 +719,18 @@ return cmd.ExecuteReader();
}
- /// <summary>
+ /// <summary>
+ /// Execute an SQL query returning results.
+ /// </summary>
+ /// <param name="sql">The SQL command.</param>
+ /// <param name="format"></param>
+ /// <returns>A data iterator, <see cref="System.Data.IDataReader">IDataReader</see>.</returns>
+ public virtual IDataReader ExecuteQuery(string format, params object[] args)
+ {
+ return ExecuteQuery(String.Format(format, args));
+ }
+
+ /// <summary>
/// Execute an SQL query returning the first result cast to type T.
/// </summary>
/// <param name="sql">The SQL command.</param>
|
|
|
Change 1 of 1
|
||
---|---|---|
|
@@ -0,0 +1,16 @@ + <?xml version="1.0"?>
+<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
+ <metadata>
+ <id>Microsoft.AspNet.Razor</id>
+ <version>2.0.30506.0</version>
+ <title>Microsoft ASP.NET Razor 2</title>
+ <authors>Microsoft</authors>
+ <owners>Microsoft</owners>
+ <licenseUrl>http://www.microsoft.com/web/webpi/eula/webpages_2_eula_enu.htm</licenseUrl>
+ <projectUrl>http://www.asp.net/web-pages</projectUrl>
+ <requireLicenseAcceptance>true</requireLicenseAcceptance>
+ <description>This package contains the runtime assemblies for ASP.NET Web Pages. ASP.NET Web Pages and the new Razor syntax provide a fast, terse, clean and lightweight way to combine server code with HTML to create dynamic web content.</description>
+ <language>en-US</language>
+ <tags>Microsoft AspNet WebPages AspNetWebPages Razor</tags>
+ </metadata>
+</package>
\ No newline at end of file |
|
|
|
||
---|---|---|
This file's diff was not loaded because this changeset is very large. Load changes Loading... |
|
|
|
@@ -0,0 +1,18 @@ + <?xml version="1.0"?>
+<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
+ <metadata>
+ <id>RazorEngine</id>
+ <version>3.3.0</version>
+ <title>RazorEngine</title>
+ <authors>Matthew Abbott, Ben Dornis</authors>
+ <owners>Matthew Abbott, Ben Dornis</owners>
+ <requireLicenseAcceptance>false</requireLicenseAcceptance>
+ <description>Simple templating using Razor syntax.</description>
+ <releaseNotes />
+ <copyright />
+ <language />
+ <dependencies>
+ <dependency id="Microsoft.AspNet.Razor" version="2.0.30506.0" />
+ </dependencies>
+ </metadata>
+</package>
\ No newline at end of file |
This file's diff was not loaded because this changeset is very large. Load changes Loading... |
|
|
|
|
|
@@ -0,0 +1,4 @@ + <?xml version="1.0" encoding="utf-8"?>
+<repositories>
+ <repository path="..\app\console\packages.config" />
+</repositories>
\ No newline at end of file |
@@ -10,6 +10,7 @@ #endregion
using System;
using System.Collections;
+using System.Collections.Generic;
using NUnit.Framework;
namespace Migrator.Tests
@@ -26,13 +27,9 @@ [Test]
public void SortAscending()
{
- ArrayList list = new ArrayList();
-
- list.Add(_types[1]);
- list.Add(_types[0]);
- list.Add(_types[2]);
-
- list.Sort(new MigrationTypeComparer(true));
+ var list = new List<Type> {_types[1], _types[0], _types[2]};
+
+ list.Sort(new MigrationTypeComparer(true));
for (int i = 0; i < 3; i++) {
Assert.AreSame(_types[i], list[i]);
@@ -42,7 +39,7 @@ [Test]
public void SortDescending()
{
- ArrayList list = new ArrayList();
+ var list = new List<Type>();
list.Add(_types[1]);
list.Add(_types[0]);
|
@@ -70,7 +70,6 @@ <Compile Include="Providers\PostgreSQLTransformationProviderTest.cs" />
<Compile Include="Providers\SqlServerTransformationProviderTest.cs" />
<Compile Include="Providers\TransformationProviderBase.cs" />
- <Compile Include="Providers\TransformationProviderTestAdapter.cs" />
<Compile Include="Tools\SchemaDumperTest.cs" />
</ItemGroup>
<ItemGroup>
|
@@ -31,7 +31,7 @@ [SetUp]
public void SetUp()
{
- _provider = new TransformationProviderTestAdapter();
+ _provider = new SqlServerTransformationProvider("");
_migrator = new Migrator(_provider, typeof(FirstMigration).Assembly, true);
_upCalled.Clear();
_downCalled.Clear();
@@ -141,8 +141,8 @@ private void SetUpCurrentVersion(int version)
{
if(_provider == null)
- _provider = new TransformationProviderTestAdapter();
- (_provider as TransformationProviderTestAdapter).CurrentVersionBackDoor = version;
+ _provider = new SqlServerTransformationProvider("");
+
}
#endregion
}
|
@@ -154,17 +154,17 @@ Assert.IsFalse(_provider.TableExists("SchemaInfo"));
// Check that a "get" call works on the first run.
- Assert.AreEqual(0, _provider.CurrentVersion);
+ Assert.AreEqual(0, _provider.GetLatestVersion(_provider.AssemblyId));
// Check that a "set" called after the first run works.
// _provider.CurrentVersion = 1;
Assert.IsTrue(_provider.TableExists("SchemaInfo"), "No SchemaInfo table created"); // Setting a version should have caused the table to be created.
- Assert.AreEqual(1, _provider.CurrentVersion);
+ Assert.AreEqual(1, _provider.GetLatestVersion(_provider.AssemblyId));
_provider.RemoveTable("SchemaInfo");
// Check that a "set" call works on the first run.
//_provider.CurrentVersion = 1;
- Assert.AreEqual(1, _provider.CurrentVersion);
+ Assert.AreEqual(1, _provider.GetLatestVersion(_provider.AssemblyId));
Assert.IsTrue(_provider.TableExists("SchemaInfo"), "No SchemaInfo table created");
}
@@ -176,7 +176,7 @@ public void CommitTwice()
{
_provider.Commit();
- Assert.AreEqual(0, _provider.CurrentVersion);
+ Assert.AreEqual(0, _provider.GetLatestVersion(_provider.AssemblyId));
_provider.Commit();
}
|
|
|
@@ -1,167 +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 System.Linq;
-using NUnit.Framework;
-
-using Migrator.Loggers;
-using System.Collections.Generic;
-
-namespace Migrator.Providers.Tests
-{
-
- public class TransformationProviderTestAdapter : TransformationProvider
- {
- private int _currentVersion = 0;
- private string _assemblyId = "TestAssemblyId";
- private List<Table> _tables = new List<Table>();
- private Dictionary<String, int> _schemaRecords = new Dictionary<String, int>();
-
- public TransformationProviderTestAdapter() : base() { this.AssemblyId = _assemblyId; }
-
- #region SchemaTable Management
- public override void CreateSchemaInfoTable() { }
- /// <summary>
- /// Get the current version of the database.
- /// This determines if the migrator should migrate up or down
- /// in the migration numbers.
- /// </summary>
- /// <remark>
- /// This value should not be modified inside a migration.
- /// </remark>
- public override int CurrentVersion
- {
- get { return GetLatestVersion(_assemblyId); }
- }
-
- /// <summary>
- /// Get the version from the SchemaInfo Table
- /// </summary>
- /// <returns>The current version</returns>
- protected override int GetLatestVersion(String assemblyId)
- {
- if (assemblyId == null) return 0; // No schema info.
- if (!_schemaRecords.ContainsKey(assemblyId)) return 0;
- return _schemaRecords[assemblyId];
- }
-
- /// <summary>
- /// Set the current version in the SchemaInfo Table
- /// </summary>
- /// <param name="version">the new version to set</param>
- protected override void RecordMigration(int version, String assemblyId)
- {
- if (assemblyId == null)
- throw new ArgumentException();
-
- _schemaRecords[assemblyId] = version;
- }
-
-
-
- #endregion
-
- public override void RemoveTable(string tableName)
- {
- if (TableExists(tableName))
- _tables.Remove(GetTable(tableName));
- }
-
- public override void RenameTable(string tableName, string newName)
- {
- if (TableExists(tableName))
- GetTable(tableName).Name = newName;
- }
-
- public override Table GetTable(string tableName)
- {
- return (from table in _tables where table.Name.Equals(tableName) select table).FirstOrDefault();
- }
-
- public override string[] GetTables()
- {
- return new string[] { };
- }
-
- public override bool TableExists(string tableName)
- {
- return (from table in _tables where table.Name.Equals(tableName) select table).Count() == 1;
- }
-
- public override void AddColumn(string tableName, string column, Type type, int size, ColumnProperties property, object defaultValue)
- {
- }
-
- public override void AlterColumn(string tableName, string column, Type type, int size)
- {
- }
-
- public override void AlterColumn(string tableName, string column, Type dataType, int size, ColumnProperties props, object defaultValue)
- {
- }
-
- public override bool ColumnExists(string tableName, string column)
- {
- return GetTable(tableName).Column[column] != null;
- }
-
- public override void RemoveColumn(string tableName, string column)
- {
- var table = GetTable(tableName);
- table.Columns.Remove(table.Column[column]);
- }
-
- public override void RenameColumn(string tableName, string column, string newName)
- {
- GetTable(tableName).Column[column].Name = newName;
- }
-
- public override void AddPrimaryKey(string name, string tableName, params string[] columns)
- {
- }
-
- public override void AddForeignKey(string name, string foreignKeyTable, string[] foreignKeyColumns, string entityTableName, string[] primaryKeyColumns)
- {
- GetTable(foreignKeyTable).ForeignKeys.Add(new ForeignKey(name, foreignKeyColumns, entityTableName, primaryKeyColumns));
- }
-
- public override void RemoveForeignKey(string name, string tableName)
- {
- var table = GetTable(tableName);
- table.ForeignKeys.Remove(table.ForeignKey[name]);
- }
-
- public override void AddUniqueConstraint(string constraint, string tableName, params string[] columns)
- {
- }
-
- public override void RemoveConstraint(string constraint, string tableName)
- {
- }
-
- public override bool ConstraintExists(string name, string tableName)
- {
- return true;
- }
-
- public override int Insert(string tableName, string[] columns, params object[] values)
- {
- return 0;
- }
-
- public int CurrentVersionBackDoor
- {
- get { return GetLatestVersion(AssemblyId); ; }
- set { RecordMigration(value, AssemblyId); }
- }
- }
-}
|
Loading...