Commit 3060a6b
Changed files (8)
product
application
application.tests
product/application/data/SqlDatabaseGateway.cs
@@ -0,0 +1,29 @@
+using System.Data;
+using System.Linq;
+using simple.migrations.utility;
+
+namespace simple.migrations.Data
+{
+ public class SqlDatabaseGateway : DatabaseGateway
+ {
+ DatabaseCommandFactory command_factory;
+
+ public SqlDatabaseGateway(DatabaseCommandFactory command_factory)
+ {
+ this.command_factory = command_factory;
+ }
+
+ public void run(SqlFile file)
+ {
+ using (var command = command_factory.create())
+ {
+ if (command.run("select * from migration_scripts")
+ .Rows
+ .Cast<DataRow>()
+ .Any(x => !file.is_greater_than(x["version"].convert_to<int>()))) return;
+
+ command.run(file);
+ }
+ }
+ }
+}
\ No newline at end of file
product/application/data/SqlFile.cs
@@ -4,7 +4,7 @@ using simple.migrations.utility;
namespace simple.migrations.Data
{
- public class SqlFile : IEquatable<SqlFile>
+ public class SqlFile : IEquatable<SqlFile>, IComparable<SqlFile>
{
public virtual string path { get; set; }
@@ -28,6 +28,11 @@ namespace simple.migrations.Data
return new FileInfo(path).Name;
}
+ public virtual int CompareTo(SqlFile other)
+ {
+ return version().CompareTo(other.version());
+ }
+
static public implicit operator SqlFile(string file_path)
{
return new SqlFile {path = file_path.ToLower()};
product/application/data/SqlServerDatabaseGateway.cs
@@ -1,30 +0,0 @@
-using System;
-using System.Data;
-using System.Globalization;
-
-namespace simple.migrations.Data
-{
- public class SqlServerDatabaseGateway : DatabaseGateway
- {
- DatabaseCommandFactory command_factory;
-
- public SqlServerDatabaseGateway(DatabaseCommandFactory command_factory)
- {
- this.command_factory = command_factory;
- }
-
- public void run(SqlFile file)
- {
- using (var command = command_factory.create())
- {
- foreach (DataRow row in command.run("select * from migration_scripts").Rows)
- {
- var version = (int) Convert.ChangeType(row["version"], typeof (int), CultureInfo.InvariantCulture);
- if (!file.is_greater_than(version)) return;
-
- command.run(file);
- }
- }
- }
- }
-}
\ No newline at end of file
product/application/application.csproj
@@ -57,7 +57,7 @@
<Compile Include="data\DatabaseGateway.cs" />
<Compile Include="data\DatabaseGatewayFactory.cs" />
<Compile Include="data\SqlFile.cs" />
- <Compile Include="data\SqlServerDatabaseGateway.cs" />
+ <Compile Include="data\SqlDatabaseGateway.cs" />
<Compile Include="HelpCommand.cs" />
<Compile Include="io\FileSystem.cs" />
<Compile Include="io\WindowsFileSystem.cs" />
product/application.tests/data/SqlServerDatabaseGatewaySpecs.cs → product/application.tests/data/SqlDatabaseGatewaySpecs.cs
@@ -8,9 +8,9 @@ using tests.helpers;
namespace tests.data
{
- public class SqlServerDatabaseGatewaySpecs
+ public class SqlDatabaseGatewaySpecs
{
- public abstract class concern : observations_for_a_sut_with_a_contract<DatabaseGateway, SqlServerDatabaseGateway>
+ public abstract class concern : observations_for_a_sut_with_a_contract<DatabaseGateway, SqlDatabaseGateway>
{
context c = () =>
{
@@ -37,7 +37,7 @@ namespace tests.data
static protected DatabaseCommand command;
}
- [Concern(typeof (SqlServerDatabaseGateway))]
+ [Concern(typeof (SqlDatabaseGateway))]
public class when_attempting_to_run_a_migration_script_that_has_already_been_run_against_the_database : concern
{
because b = () =>
@@ -51,7 +51,7 @@ namespace tests.data
};
}
- [Concern(typeof (SqlServerDatabaseGateway))]
+ [Concern(typeof (SqlDatabaseGateway))]
public class when_running_a_bunch_of_migrations_scripts_against_a_database : concern
{
because b = () =>
product/application.tests/data/SqlFileSpecs.cs
@@ -28,5 +28,33 @@ namespace tests.data
sut.is_greater_than(99).should_be_false();
};
}
+
+ [Concern(typeof (SqlFile))]
+ public class when_comparing_one_migration_file_to_another : concern
+ {
+ context c = () =>
+ {
+ first_script = "c:/tmp/0001_blah_blah.sql";
+ second_script = "c:/tmp/0002_another_one.sql";
+ };
+
+ it should_be_able_to_tell_when_one_file_is_greater_than_the_other = () =>
+ {
+ second_script.CompareTo(first_script).should_be_greater_than(0);
+ };
+
+ it should_be_able_to_tell_when_one_file_is_less_than_the_other = () =>
+ {
+ first_script.CompareTo(second_script).should_be_less_than(0);
+ };
+
+ it should_be_able_to_tell_when_two_files_are_the_same = () =>
+ {
+ first_script.CompareTo(first_script).should_be_equal_to(0);
+ };
+
+ static SqlFile first_script;
+ static SqlFile second_script;
+ }
}
}
\ No newline at end of file
product/application.tests/application.tests.csproj
@@ -73,7 +73,7 @@
<Compile Include="ConsoleArgumentsSpecs.cs" />
<Compile Include="ConsoleSpecs.cs" />
<Compile Include="data\SqlFileSpecs.cs" />
- <Compile Include="data\SqlServerDatabaseGatewaySpecs.cs" />
+ <Compile Include="data\SqlDatabaseGatewaySpecs.cs" />
<Compile Include="EmptyTestFixture.cs" />
<Compile Include="helpers\RhinoStubbingExtensions.cs" />
<Compile Include="io\WindowsFileSystemSpecs.cs" />
product/application.tests/RunMigrationsCommandSpecs.cs
@@ -16,7 +16,7 @@ namespace tests
context c = () =>
{
file_system = the_dependency<FileSystem>();
- database_gateway_factory=the_dependency<DatabaseGatewayFactory>();
+ database_gateway_factory = the_dependency<DatabaseGatewayFactory>();
};
static protected FileSystem file_system;
@@ -77,7 +77,7 @@ namespace tests
gateway = an<DatabaseGateway>();
database_gateway_factory
- .is_told_to(x => x.gateway_to("blah=blah;","System.Data.SqlClient"))
+ .is_told_to(x => x.gateway_to("blah=blah;", "System.Data.SqlClient"))
.it_will_return(gateway);
file_system
.is_told_to(x => x.all_sql_files_from("c:\\tmp"))