Permalink
Browse files

Merge pull request #224 of Andorbal/213-split-migrations

* pr/n224_Andorbal:
  Split the Migration and AutoReverseMigration classes so that expressions that cannot be auto-reversed can be marked obsolete.
  • Loading branch information...
2 parents becd888 + 60117af commit 07ea06e20573b09825e86c756582638a99eaa257 @tommarien tommarien committed Jan 21, 2012
View
24 src/FluentMigrator/AutoReversingMigration.cs
@@ -16,12 +16,16 @@
//
#endregion
+using System;
using System.Linq;
+using FluentMigrator.Builders.Delete;
+using FluentMigrator.Builders.Execute;
+using FluentMigrator.Builders.Update;
using FluentMigrator.Infrastructure;
namespace FluentMigrator
{
- public abstract class AutoReversingMigration : Migration
+ public abstract class AutoReversingMigration : MigrationBase
{
public sealed override void Down()
{
@@ -32,5 +36,23 @@ public override void GetDownExpressions(IMigrationContext context)
GetUpExpressions(context);
context.Expressions = context.Expressions.Select(e => e.Reverse()).Reverse().ToList();
}
+
+ [Obsolete("Delete cannot auto-reversed and will no longer be available for auto-reversing migrations.", false)]
+ public IDeleteExpressionRoot Delete
+ {
+ get { return new DeleteExpressionRoot(_context); }
+ }
+
+ [Obsolete("Execute cannot auto-reversed and will no longer be available for auto-reversing migrations.", false)]
+ public IExecuteExpressionRoot Execute
+ {
+ get { return new ExecuteExpressionRoot(_context); }
+ }
+
+ [Obsolete("Update cannot auto-reversed and will no longer be available for auto-reversing migrations.", false)]
+ public IUpdateExpressionRoot Update
+ {
+ get { return new UpdateExpressionRoot(_context); }
+ }
}
}
View
3 src/FluentMigrator/FluentMigrator.csproj
@@ -204,6 +204,7 @@
<Compile Include="Builders\Insert\InsertExpressionRoot.cs" />
<Compile Include="Expressions\UpdateDataExpression.cs" />
<Compile Include="ForwardOnlyMigration.cs" />
+ <Compile Include="MigrationBase.cs" />
<Compile Include="Model\ConstraintDefinition.cs" />
<Compile Include="Model\DeletionDataDefinition.cs" />
<Compile Include="Model\InsertionDataDefinition.cs" />
@@ -333,4 +334,4 @@
<Target Name="AfterBuild">
</Target>
-->
-</Project>
+</Project>
View
71 src/FluentMigrator/Migration.cs
@@ -16,96 +16,27 @@
//
#endregion
-using FluentMigrator.Builders.Alter;
-using FluentMigrator.Builders.Create;
using FluentMigrator.Builders.Delete;
-using FluentMigrator.Builders.IfDatabase;
-using FluentMigrator.Builders.Insert;
-using FluentMigrator.Builders.Rename;
-using FluentMigrator.Builders.Schema;
-using FluentMigrator.Infrastructure;
using FluentMigrator.Builders.Execute;
using FluentMigrator.Builders.Update;
namespace FluentMigrator
{
- public abstract class Migration : IMigration
+ public abstract class Migration : MigrationBase
{
- private IMigrationContext _context;
- private readonly object _mutex = new object();
-
- public abstract void Up();
- public abstract void Down();
-
- public void ApplyConventions(IMigrationContext context)
- {
- foreach (var expression in context.Expressions)
- expression.ApplyConventions(context.Conventions);
- }
-
- public virtual void GetUpExpressions(IMigrationContext context)
- {
- lock (_mutex)
- {
- _context = context;
- Up();
- _context = null;
- }
- }
-
- public virtual void GetDownExpressions(IMigrationContext context)
- {
- lock (_mutex)
- {
- _context = context;
- Down();
- _context = null;
- }
- }
-
- public IAlterExpressionRoot Alter
- {
- get { return new AlterExpressionRoot(_context); }
- }
-
- public ICreateExpressionRoot Create
- {
- get { return new CreateExpressionRoot(_context); }
- }
-
public IDeleteExpressionRoot Delete
{
get { return new DeleteExpressionRoot(_context); }
}
- public IRenameExpressionRoot Rename
- {
- get { return new RenameExpressionRoot(_context); }
- }
-
- public IInsertExpressionRoot Insert
- {
- get { return new InsertExpressionRoot(_context); }
- }
-
public IExecuteExpressionRoot Execute
{
get { return new ExecuteExpressionRoot(_context); }
}
- public ISchemaExpressionRoot Schema
- {
- get { return new SchemaExpressionRoot(_context); }
- }
-
public IUpdateExpressionRoot Update
{
get { return new UpdateExpressionRoot(_context); }
}
-
- public IIfDatabaseExpressionRoot IfDatabase(params string[] databaseType)
- {
- return new IfDatabaseExpressionRoot(_context, databaseType);
- }
}
}
View
93 src/FluentMigrator/MigrationBase.cs
@@ -0,0 +1,93 @@
+#region License
+//
+// Copyright (c) 2007-2009, Sean Chambers <schambers80@gmail.com>
+//
+// Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+#endregion
+
+using FluentMigrator.Builders.Alter;
+using FluentMigrator.Builders.Create;
+using FluentMigrator.Builders.IfDatabase;
+using FluentMigrator.Builders.Insert;
+using FluentMigrator.Builders.Rename;
+using FluentMigrator.Builders.Schema;
+using FluentMigrator.Infrastructure;
+
+namespace FluentMigrator
+{
+ public abstract class MigrationBase : IMigration
+ {
+ internal IMigrationContext _context;
+ private readonly object _mutex = new object();
+
+ public abstract void Up();
+ public abstract void Down();
+
+ public void ApplyConventions(IMigrationContext context)
+ {
+ foreach (var expression in context.Expressions)
+ expression.ApplyConventions(context.Conventions);
+ }
+
+ public virtual void GetUpExpressions(IMigrationContext context)
+ {
+ lock (_mutex)
+ {
+ _context = context;
+ Up();
+ _context = null;
+ }
+ }
+
+ public virtual void GetDownExpressions(IMigrationContext context)
+ {
+ lock (_mutex)
+ {
+ _context = context;
+ Down();
+ _context = null;
+ }
+ }
+
+ public IAlterExpressionRoot Alter
+ {
+ get { return new AlterExpressionRoot(_context); }
+ }
+
+ public ICreateExpressionRoot Create
+ {
+ get { return new CreateExpressionRoot(_context); }
+ }
+
+ public IRenameExpressionRoot Rename
+ {
+ get { return new RenameExpressionRoot(_context); }
+ }
+
+ public IInsertExpressionRoot Insert
+ {
+ get { return new InsertExpressionRoot(_context); }
+ }
+
+ public ISchemaExpressionRoot Schema
+ {
+ get { return new SchemaExpressionRoot(_context); }
+ }
+
+ public IIfDatabaseExpressionRoot IfDatabase(params string[] databaseType)
+ {
+ return new IfDatabaseExpressionRoot(_context, databaseType);
+ }
+ }
+}

0 comments on commit 07ea06e

Please sign in to comment.