Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
1,249 additions
and
1,249 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
using System.Reflection; | ||
|
||
namespace FluentMigrator.Runner | ||
{ | ||
public interface IMigrationRunner | ||
{ | ||
IMigrationProcessor Processor { get; } | ||
Assembly MigrationAssembly { get; } | ||
void Up(IMigration migration); | ||
void MigrateUp(); | ||
void MigrateUp(long version); | ||
void Rollback(int steps); | ||
void RollbackToVersion(long version); | ||
void MigrateDown(long version); | ||
void ValidateVersionOrder(); | ||
} | ||
using System.Reflection; | ||
|
||
namespace FluentMigrator.Runner | ||
{ | ||
public interface IMigrationRunner | ||
{ | ||
IMigrationProcessor Processor { get; } | ||
Assembly MigrationAssembly { get; } | ||
void Up(IMigration migration); | ||
void MigrateUp(); | ||
void MigrateUp(long version); | ||
void Rollback(int steps); | ||
void RollbackToVersion(long version); | ||
void MigrateDown(long version); | ||
void ValidateVersionOrder(); | ||
} | ||
} |
214 changes: 107 additions & 107 deletions
214
src/FluentMigrator.Runner/Initialization/TaskExecutor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,108 +1,108 @@ | ||
#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 System; | ||
using FluentMigrator.Runner.Initialization.AssemblyLoader; | ||
using FluentMigrator.Runner.Processors; | ||
|
||
namespace FluentMigrator.Runner.Initialization | ||
{ | ||
public class TaskExecutor | ||
{ | ||
protected IMigrationRunner Runner { get; set; } | ||
private IRunnerContext RunnerContext { get; set; } | ||
|
||
public TaskExecutor(IRunnerContext runnerContext) | ||
{ | ||
if (runnerContext == null) | ||
throw new ArgumentNullException("runnerContext", "RunnerContext cannot be null"); | ||
|
||
RunnerContext = runnerContext; | ||
} | ||
|
||
protected virtual void Initialize() | ||
{ | ||
var assembly = AssemblyLoaderFactory.GetAssemblyLoader(RunnerContext.Target).Load(); | ||
|
||
var processor = InitializeProcessor(assembly.Location); | ||
|
||
Runner = new MigrationRunner(assembly, RunnerContext, processor); | ||
} | ||
|
||
public void Execute() | ||
{ | ||
Initialize(); | ||
|
||
switch (RunnerContext.Task) | ||
{ | ||
case null: | ||
case "": | ||
case "migrate": | ||
case "migrate:up": | ||
if (RunnerContext.Version != 0) | ||
Runner.MigrateUp(RunnerContext.Version); | ||
else | ||
Runner.MigrateUp(); | ||
break; | ||
case "rollback": | ||
if (RunnerContext.Steps == 0) | ||
RunnerContext.Steps = 1; | ||
Runner.Rollback(RunnerContext.Steps); | ||
break; | ||
case "rollback:toversion": | ||
Runner.RollbackToVersion(RunnerContext.Version); | ||
break; | ||
case "rollback:all": | ||
Runner.RollbackToVersion(0); | ||
break; | ||
case "migrate:down": | ||
Runner.MigrateDown(RunnerContext.Version); | ||
break; | ||
case "validateversionorder": | ||
Runner.ValidateVersionOrder(); | ||
break; | ||
} | ||
|
||
RunnerContext.Announcer.Say("Task completed."); | ||
} | ||
|
||
private IMigrationProcessor InitializeProcessor(string assemblyLocation) | ||
{ | ||
var manager = new ConnectionStringManager(new NetConfigManager(), RunnerContext.Announcer, RunnerContext.Connection, RunnerContext.ConnectionStringConfigPath, assemblyLocation, RunnerContext.Database); | ||
|
||
manager.LoadConnectionString(); | ||
|
||
if (RunnerContext.Timeout == 0) | ||
{ | ||
RunnerContext.Timeout = 30; // Set default timeout for command | ||
} | ||
|
||
var processorFactory = ProcessorFactory.GetFactory(RunnerContext.Database); | ||
if (processorFactory == null) | ||
throw new ProcessorFactoryNotFoundException(string.Format("The provider or dbtype parameter is incorrect. Available choices are {0}: ", ProcessorFactory.ListAvailableProcessorTypes())); | ||
|
||
var processor = processorFactory.Create(manager.ConnectionString, RunnerContext.Announcer, new ProcessorOptions | ||
{ | ||
PreviewOnly = RunnerContext.PreviewOnly, | ||
Timeout = RunnerContext.Timeout | ||
}); | ||
|
||
return processor; | ||
} | ||
} | ||
#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 System; | ||
using FluentMigrator.Runner.Initialization.AssemblyLoader; | ||
using FluentMigrator.Runner.Processors; | ||
|
||
namespace FluentMigrator.Runner.Initialization | ||
{ | ||
public class TaskExecutor | ||
{ | ||
protected IMigrationRunner Runner { get; set; } | ||
private IRunnerContext RunnerContext { get; set; } | ||
|
||
public TaskExecutor(IRunnerContext runnerContext) | ||
{ | ||
if (runnerContext == null) | ||
throw new ArgumentNullException("runnerContext", "RunnerContext cannot be null"); | ||
|
||
RunnerContext = runnerContext; | ||
} | ||
|
||
protected virtual void Initialize() | ||
{ | ||
var assembly = AssemblyLoaderFactory.GetAssemblyLoader(RunnerContext.Target).Load(); | ||
|
||
var processor = InitializeProcessor(assembly.Location); | ||
|
||
Runner = new MigrationRunner(assembly, RunnerContext, processor); | ||
} | ||
|
||
public void Execute() | ||
{ | ||
Initialize(); | ||
|
||
switch (RunnerContext.Task) | ||
{ | ||
case null: | ||
case "": | ||
case "migrate": | ||
case "migrate:up": | ||
if (RunnerContext.Version != 0) | ||
Runner.MigrateUp(RunnerContext.Version); | ||
else | ||
Runner.MigrateUp(); | ||
break; | ||
case "rollback": | ||
if (RunnerContext.Steps == 0) | ||
RunnerContext.Steps = 1; | ||
Runner.Rollback(RunnerContext.Steps); | ||
break; | ||
case "rollback:toversion": | ||
Runner.RollbackToVersion(RunnerContext.Version); | ||
break; | ||
case "rollback:all": | ||
Runner.RollbackToVersion(0); | ||
break; | ||
case "migrate:down": | ||
Runner.MigrateDown(RunnerContext.Version); | ||
break; | ||
case "validateversionorder": | ||
Runner.ValidateVersionOrder(); | ||
break; | ||
} | ||
|
||
RunnerContext.Announcer.Say("Task completed."); | ||
} | ||
|
||
private IMigrationProcessor InitializeProcessor(string assemblyLocation) | ||
{ | ||
var manager = new ConnectionStringManager(new NetConfigManager(), RunnerContext.Announcer, RunnerContext.Connection, RunnerContext.ConnectionStringConfigPath, assemblyLocation, RunnerContext.Database); | ||
|
||
manager.LoadConnectionString(); | ||
|
||
if (RunnerContext.Timeout == 0) | ||
{ | ||
RunnerContext.Timeout = 30; // Set default timeout for command | ||
} | ||
|
||
var processorFactory = ProcessorFactory.GetFactory(RunnerContext.Database); | ||
if (processorFactory == null) | ||
throw new ProcessorFactoryNotFoundException(string.Format("The provider or dbtype parameter is incorrect. Available choices are {0}: ", ProcessorFactory.ListAvailableProcessorTypes())); | ||
|
||
var processor = processorFactory.Create(manager.ConnectionString, RunnerContext.Announcer, new ProcessorOptions | ||
{ | ||
PreviewOnly = RunnerContext.PreviewOnly, | ||
Timeout = RunnerContext.Timeout | ||
}); | ||
|
||
return processor; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.