Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Simple.Migrations.IntegrationTests/Mssql/MssqlTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public class MssqlTests : TestsBase

protected override bool SupportConcurrentMigrators => true;

protected override DbConnection CreateConnection() => new SqlConnection(ConnectionStrings.MSSQL);
protected override IDbConnection CreateConnection() => new SqlConnection(ConnectionStrings.MSSQL);

protected override IDatabaseProvider<DbConnection> CreateDatabaseProvider() => new MssqlDatabaseProvider(this.CreateConnection());
protected override IDatabaseProvider<IDbConnection> CreateDatabaseProvider() => new MssqlDatabaseProvider(this.CreateConnection());

protected override void Clean()
{
Expand Down
5 changes: 3 additions & 2 deletions src/Simple.Migrations.IntegrationTests/Mysql/MysqlTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
using System.Threading.Tasks;
Expand All @@ -15,9 +16,9 @@ public class MysqlTests : TestsBase
{
protected override IMigrationStringsProvider MigrationStringsProvider { get; } = new MysqlStringsProvider();

protected override DbConnection CreateConnection() => new MySqlConnection(ConnectionStrings.MySQL);
protected override IDbConnection CreateConnection() => new MySqlConnection(ConnectionStrings.MySQL);

protected override IDatabaseProvider<DbConnection> CreateDatabaseProvider() => new MysqlDatabaseProvider(this.CreateConnection());
protected override IDatabaseProvider<IDbConnection> CreateDatabaseProvider() => new MysqlDatabaseProvider(this.CreateConnection());

protected override bool SupportConcurrentMigrators => true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Simple.Migrations.IntegrationTests.Postgresql
[TestFixture]
public class PostgresqlTests : TestsBase
{
protected override IDatabaseProvider<DbConnection> CreateDatabaseProvider() => new PostgresqlDatabaseProvider(this.CreateConnection());
protected override IDatabaseProvider<IDbConnection> CreateDatabaseProvider() => new PostgresqlDatabaseProvider(this.CreateConnection());

protected override IMigrationStringsProvider MigrationStringsProvider { get; } = new PostgresqlStringsProvider();

Expand All @@ -33,6 +33,6 @@ protected override void Clean()

private NpgsqlConnection CreatePgConnection() => new NpgsqlConnection(ConnectionStrings.PostgreSQL);

protected override DbConnection CreateConnection() => this.CreatePgConnection();
protected override IDbConnection CreateConnection() => this.CreatePgConnection();
}
}
4 changes: 2 additions & 2 deletions src/Simple.Migrations.IntegrationTests/Sqlite/SqliteTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Simple.Migrations.IntegrationTests.Sqlite
[TestFixture]
public class SqliteTests : TestsBase
{
protected override IDatabaseProvider<DbConnection> CreateDatabaseProvider() => new SqliteDatabaseProvider(this.CreateConnection());
protected override IDatabaseProvider<IDbConnection> CreateDatabaseProvider() => new SqliteDatabaseProvider(this.CreateConnection());

protected override IMigrationStringsProvider MigrationStringsProvider { get; } = new SqliteStringsProvider();

Expand All @@ -29,6 +29,6 @@ protected override void Clean()
File.Delete(db);
}

protected override DbConnection CreateConnection() => new SqliteConnection(ConnectionStrings.SQLite);
protected override IDbConnection CreateConnection() => new SqliteConnection(ConnectionStrings.SQLite);
}
}
4 changes: 2 additions & 2 deletions src/Simple.Migrations.IntegrationTests/TestsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ namespace Simple.Migrations.IntegrationTests
{
public abstract class TestsBase
{
protected abstract DbConnection CreateConnection();
protected abstract IDatabaseProvider<DbConnection> CreateDatabaseProvider();
protected abstract IDbConnection CreateConnection();
protected abstract IDatabaseProvider<IDbConnection> CreateDatabaseProvider();
protected abstract IMigrationStringsProvider MigrationStringsProvider { get; }
protected abstract void Clean();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
// public string SetVersionSql = "Set Version SQL";
// public override string GetSetVersionSql() => this.SetVersionSql;

// public override DbConnection BeginOperation()
// public override IDbConnection BeginOperation()
// {
// throw new NotImplementedException();
// }
Expand Down
7 changes: 4 additions & 3 deletions src/Simple.Migrations.UnitTests/MockDatabaseProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
using System.Threading.Tasks;
using SimpleMigrations;
using System.Data.Common;
using System.Data;

namespace Simple.Migrations.UnitTests
{
public abstract class MockDatabaseProvider : IDatabaseProvider<DbConnection>
public abstract class MockDatabaseProvider : IDatabaseProvider<IDbConnection>
{
public long CurrentVersion;
public DbConnection Connection;
public IDbConnection Connection;

public DbConnection BeginOperation()
public IDbConnection BeginOperation()
{
return this.Connection;
}
Expand Down
8 changes: 4 additions & 4 deletions src/Simple.Migrations.UnitTests/SimpleMigratorLoadTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,18 @@ protected override void Up() { }

private Mock<DbConnection> connection;
private Mock<IMigrationProvider> migrationProvider;
private Mock<IDatabaseProvider<DbConnection>> databaseProvider;
private Mock<IDatabaseProvider<IDbConnection>> databaseProvider;

private SimpleMigrator<DbConnection, Migration> migrator;
private SimpleMigrator<IDbConnection, Migration> migrator;

[SetUp]
public void SetUp()
{
this.connection = new Mock<DbConnection>();
this.migrationProvider = new Mock<IMigrationProvider>();
this.databaseProvider = new Mock<IDatabaseProvider<DbConnection>>();
this.databaseProvider = new Mock<IDatabaseProvider<IDbConnection>>();

this.migrator = new SimpleMigrator<DbConnection, Migration>(this.migrationProvider.Object, this.databaseProvider.Object);
this.migrator = new SimpleMigrator<IDbConnection, Migration>(this.migrationProvider.Object, this.databaseProvider.Object);
}

[Test]
Expand Down
7 changes: 4 additions & 3 deletions src/Simple.Migrations.UnitTests/SimpleMigratorMigrateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using SimpleMigrations;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
using System.Reflection;
Expand All @@ -21,7 +22,7 @@ private class Migration1 : Migration
public static Exception Exception;
public static Action<Migration1> Callback;

public new DbConnection Connection => base.Connection;
public new IDbConnection Connection => base.Connection;
public new IMigrationLogger Logger => base.Logger;

public static void Reset()
Expand Down Expand Up @@ -75,7 +76,7 @@ public static void Reset()

private List<MigrationData> migrations;

private SimpleMigrator<DbConnection, Migration> migrator;
private SimpleMigrator<IDbConnection, Migration> migrator;

[SetUp]
public void SetUp()
Expand All @@ -96,7 +97,7 @@ public void SetUp()

this.logger = new Mock<ILogger>();

this.migrator = new SimpleMigrator<DbConnection, Migration>(this.migrationProvider.Object, this.databaseProvider.Object, this.logger.Object);
this.migrator = new SimpleMigrator<IDbConnection, Migration>(this.migrationProvider.Object, this.databaseProvider.Object, this.logger.Object);

this.migrations = new List<MigrationData>()
{
Expand Down
11 changes: 6 additions & 5 deletions src/Simple.Migrations/DatabaseProvider/DatabaseProviderBase.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Data;
using System.Data.Common;

namespace SimpleMigrations.DatabaseProvider
Expand Down Expand Up @@ -34,7 +35,7 @@ namespace SimpleMigrations.DatabaseProvider
/// The subclasses <see cref="DatabaseProviderBaseWithAdvisoryLock"/> and <see cref="DatabaseProviderBaseWithVersionTableLock"/>
/// encapsulate these concepts.
/// </remarks>
public abstract class DatabaseProviderBase : IDatabaseProvider<DbConnection>
public abstract class DatabaseProviderBase : IDatabaseProvider<IDbConnection>
{
/// <summary>
/// Table name used to store version info. Defaults to 'VersionInfo'
Expand Down Expand Up @@ -68,7 +69,7 @@ public abstract class DatabaseProviderBase : IDatabaseProvider<DbConnection>
/// <param name="connection">Connection to use</param>
/// <param name="transaction">Transaction to use</param>
/// <returns>The current version, or 0</returns>
protected virtual long EnsurePrerequisitesCreatedAndGetCurrentVersion(DbConnection connection, DbTransaction transaction)
protected virtual long EnsurePrerequisitesCreatedAndGetCurrentVersion(IDbConnection connection, IDbTransaction transaction)
{
var createSchemaSql = this.GetCreateSchemaTableSql();
if (!string.IsNullOrEmpty(createSchemaSql))
Expand Down Expand Up @@ -97,7 +98,7 @@ protected virtual long EnsurePrerequisitesCreatedAndGetCurrentVersion(DbConnecti
/// and return the connection for the migrations to use.
/// </summary>
/// <returns>Connection for the migrations to use</returns>
public abstract DbConnection BeginOperation();
public abstract IDbConnection BeginOperation();

/// <summary>
/// Cleans up any connections and/or transactions and/or locks created by <see cref="BeginOperation"/>
Expand Down Expand Up @@ -130,7 +131,7 @@ protected virtual long EnsurePrerequisitesCreatedAndGetCurrentVersion(DbConnecti
/// <param name="connection">Connection to use</param>
/// <param name="transaction">transaction to use, may be null</param>
/// <returns>The current database schema version, or 0</returns>
protected virtual long GetCurrentVersion(DbConnection connection, DbTransaction transaction)
protected virtual long GetCurrentVersion(IDbConnection connection, IDbTransaction transaction)
{
long version = 0;
using (var command = connection.CreateCommand())
Expand Down Expand Up @@ -176,7 +177,7 @@ protected virtual long GetCurrentVersion(DbConnection connection, DbTransaction
/// <param name="newDescription">The description of the migration which was applied</param>
/// <param name="connection">Connection to use</param>
/// <param name="transaction">Transaction to use, may be null</param>
protected virtual void UpdateVersion(long oldVersion, long newVersion, string newDescription, DbConnection connection, DbTransaction transaction)
protected virtual void UpdateVersion(long oldVersion, long newVersion, string newDescription, IDbConnection connection, IDbTransaction transaction)
{
if (this.MaxDescriptionLength > 0 && newDescription.Length > this.MaxDescriptionLength)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public abstract class DatabaseProviderBaseWithAdvisoryLock : DatabaseProviderBas
/// <summary>
/// Gets the connection used for all database operations
/// </summary>
protected DbConnection Connection { get; }
protected IDbConnection Connection { get; }

/// <summary>
/// Gets or sets the timeout when acquiring the advisory lock
Expand All @@ -27,7 +27,7 @@ public abstract class DatabaseProviderBaseWithAdvisoryLock : DatabaseProviderBas
/// Initialises a new instance of the <see cref="DatabaseProviderBaseWithAdvisoryLock"/> class
/// </summary>
/// <param name="connection">Database connection to use for all operations</param>
public DatabaseProviderBaseWithAdvisoryLock(DbConnection connection)
public DatabaseProviderBaseWithAdvisoryLock(IDbConnection connection)
{
this.Connection = connection;
if (this.Connection.State != ConnectionState.Open)
Expand Down Expand Up @@ -63,7 +63,7 @@ public override long EnsurePrerequisitesCreatedAndGetCurrentVersion()
/// is invoked, before any migrations are run. This invokes <see cref="AcquireAdvisoryLock"/> to acquire the advisory lock.
/// </summary>
/// <returns>Connection for the migrations to use</returns>
public override DbConnection BeginOperation()
public override IDbConnection BeginOperation()
{
this.AcquireAdvisoryLock();
return this.Connection;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Data;
using System.Data.Common;

namespace SimpleMigrations.DatabaseProvider
Expand All @@ -25,23 +26,23 @@ public abstract class DatabaseProviderBaseWithVersionTableLock : DatabaseProvide
/// <remarks>
/// This is set by <see cref="BeginOperation"/>, and cleated by <see cref="EndOperation"/>.
/// </remarks>
protected DbConnection VersionTableConnection { get; set; }
protected IDbConnection VersionTableConnection { get; set; }

/// <summary>
/// Gets or sets the transaction on the <see cref="VersionTableConnection"/> used to lock it.
/// </summary>
/// <remarks>
/// This is set by <see cref="BeginOperation"/>, and cleated by <see cref="EndOperation"/>.
/// </remarks>
protected DbTransaction VersionTableLockTransaction { get; set; }
protected IDbTransaction VersionTableLockTransaction { get; set; }

/// <summary>
/// Gets or sets the connection to be used by migrations.
/// </summary>
/// <remarks>
/// This is set by <see cref="BeginOperation"/>, and cleated by <see cref="EndOperation"/>.
/// </remarks>
protected DbConnection MigrationsConnection { get; set; }
protected IDbConnection MigrationsConnection { get; set; }

/// <summary>
/// Initialises a new instance of the <see cref="DatabaseProviderBaseWithVersionTableLock"/> class
Expand Down Expand Up @@ -78,7 +79,7 @@ public override long EnsurePrerequisitesCreatedAndGetCurrentVersion()
/// <see cref="MigrationsConnection"/>, and invokes <see cref="AcquireVersionTableLock"/> to acquire the VersionInfo table lock.
/// </summary>
/// <returns>Connection for the migrations to use</returns>
public override DbConnection BeginOperation()
public override IDbConnection BeginOperation()
{
this.VersionTableConnection = this.ConnectionFactory();
this.VersionTableConnection.Open();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public string LockName
/// Initialises a new instance of the <see cref="MssqlDatabaseProvider"/> class
/// </summary>
/// <param name="connection">Connection to use to run migrations. The caller is responsible for closing this.</param>
public MssqlDatabaseProvider(DbConnection connection)
public MssqlDatabaseProvider(IDbConnection connection)
: base(connection)
{
this.MaxDescriptionLength = 256;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Data;
using System.Data.Common;

namespace SimpleMigrations.DatabaseProvider
Expand Down Expand Up @@ -30,7 +31,7 @@ public string LockName
/// Initialises a new instance of the <see cref="MysqlDatabaseProvider"/> class
/// </summary>
/// <param name="connection">Connection to use to run migrations. The caller is responsible for closing this.</param>
public MysqlDatabaseProvider(DbConnection connection)
public MysqlDatabaseProvider(IDbConnection connection)
: base(connection)
{
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Data;
using System.Data.Common;

namespace SimpleMigrations.DatabaseProvider
Expand Down Expand Up @@ -37,7 +38,7 @@ public class PostgresqlDatabaseProvider : DatabaseProviderBaseWithAdvisoryLock
/// Initialises a new instance of the <see cref="PostgresqlDatabaseProvider"/> class
/// </summary>
/// <param name="connection">Connection to use to run migrations. The caller is responsible for closing this.</param>
public PostgresqlDatabaseProvider(DbConnection connection)
public PostgresqlDatabaseProvider(IDbConnection connection)
: base(connection)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class SqliteDatabaseProvider : DatabaseProviderBaseWithAdvisoryLock
/// Initialises a new instance of the <see cref="SqliteDatabaseProvider"/> class
/// </summary>
/// <param name="connection">Connection to use to run migrations. The caller is responsible for closing this.</param>
public SqliteDatabaseProvider(DbConnection connection)
public SqliteDatabaseProvider(IDbConnection connection)
: base(connection)
{
}
Expand Down
10 changes: 5 additions & 5 deletions src/Simple.Migrations/Migration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace SimpleMigrations
/// Base class, intended to be used by all migrations (although you may implement <see cref="IMigration{TDatabase}"/> directly if you wish).
/// Migrations MUST apply the <see cref="MigrationAttribute"/> attribute
/// </summary>
public abstract class Migration : IMigration<DbConnection>
public abstract class Migration : IMigration<IDbConnection>
{
/// <summary>
/// Gets or sets a value indicating whether calls to <see cref="Execute(string, int?)"/> should be run inside of a transaction.
Expand All @@ -21,7 +21,7 @@ public abstract class Migration : IMigration<DbConnection>
/// <summary>
/// Gets or sets the database to be used by this migration
/// </summary>
protected DbConnection Connection { get; private set; }
protected IDbConnection Connection { get; private set; }

/// <summary>
/// Gets or sets the logger to be used by this migration
Expand All @@ -34,7 +34,7 @@ public abstract class Migration : IMigration<DbConnection>
/// <remarks>
/// This is set only if <see cref="UseTransaction"/> is true.
/// </remarks>
protected DbTransaction Transaction { get; private set; }
protected IDbTransaction Transaction { get; private set; }

// Up and Down should really be 'protected', but in the name of backwards compatibility...

Expand Down Expand Up @@ -79,7 +79,7 @@ protected virtual void Execute(string sql, int? commandTimeout = null)
/// A <see cref="DbCommand"/> which is configured with the <see cref="DbCommand.CommandText"/>, <see cref="DbCommand.Transaction"/>,
/// and <see cref="DbCommand.CommandTimeout"/> properties set.
/// </returns>
protected virtual DbCommand CreateCommand(string sql, int? commandTimeout)
protected virtual IDbCommand CreateCommand(string sql, int? commandTimeout)
{
if (this.Connection == null)
throw new InvalidOperationException("this.Connection has not yet been set. This should have been set by Execute(DbConnection, IMigrationLogger, MigrationDirection)");
Expand All @@ -94,7 +94,7 @@ protected virtual DbCommand CreateCommand(string sql, int? commandTimeout)
return command;
}

void IMigration<DbConnection>.RunMigration(MigrationRunData<DbConnection> data)
void IMigration<IDbConnection>.RunMigration(MigrationRunData<IDbConnection> data)
{
this.Connection = data.Connection;
this.Logger = data.Logger;
Expand Down
Loading