Skip to content

About

EasyDBMigrator - making SQL and PostgreSQL database migrations and integration testing easier

Topics

Resources

Security policy

Stars

2 stars

Watchers

2 watching

Forks

Latest commit

 

History

447 Commits

Folders and files

Repository files navigation

EasyDBMigrator - making database migrations and integration testing easier

The latest news and roadmap

4.1.x (the latest release)

  • add support for .net 10

4.0.x

  • add support for .net 9 and removed the not supported .net versions
  • is AOT compatible

Note: from version 4.0.2 on EasyDBMigrator will not use the Fluent Assertions package for internal testing. The reason is that Fluent Assertions is a commercial product now. EasyDBMigrator will only use non-commercial open source software.

Note: EasyDBMigrator is tested with MSTest on Microsoft.Testing.Platform. This is an internal testing choice only - it puts no constraint on the test framework you use in your own project.

3.0.x

  • add support for .net 8
  • monthly updates of all packages for stability and security

2.0.x

  • add support for .net 7
  • monthly update of all packages for stability and security

Info

Actions (jobs)

Build debug Build release Package and release to NuGet CodeQL

Code statistics

codecov

More info

NuGet version NuGet downloads

What is EasyDBMigrator?

EasyDBMigrator is an open-source database migration framework. It strongly favors simplicity and ease of use for automatic CI/CD strategies, integration testing scenarios and easy integration in your own code.

What do we want to accomplish?

  1. Make it easy to integrate Microsoft SQL migrations in your CI/CD flows
  2. Make it easy to integrate PostgreSQL migrations in your CI/CD flows
  3. Make it easy to perform manual Microsoft SQL migrations
  4. Make it easy to perform manual PostgreSQL migrations
  5. Make it easy to integrate this package into your own code/tool
  6. Provide examples of how to write unit and integration tests (feel free to give me code feedback or for a good discussion on testing)

Get started with EasyDBMigrator

Using EasyDBMigrator for integration testing

The example below uses MSTest, which is what EasyDBMigrator itself is tested with. EasyDBMigrator only depends on ILogger, so any test framework works just as well.

[TestClass]
public class DatabaseTests
{
    // MSTest injects this; it gives you the per-test cancellation token.
    public TestContext TestContext { get; set; }

    [TestMethod]
    [TestCategory("IntegrationTest")]
    public async Task RunMigrations()
    {
        // Make sure you use the correct naming in your scripts, like:
        // 20210926_001_AddEquipmentTable.sql --> scripts are ordered by date
        // and then per sequence number. In this case, '001' is the sequence
        // number. Make sure to set the BUILD-ACTION property of every
        // migration SQL script to EMBEDDED RESOURCE.
        const string databaseName = "WorkoutIntegrationTests";

        // Make sure that the 'Database = xxxx;' parameter is excluded in the
        // connection-string.
        const string connectionString =
            "some fancy connectionstring without database param";

        MigrationConfiguration config = new(connectionString: connectionString
            , databaseName: databaseName);

        // For writing the logging output from EasyDBMigrator to the test
        // output window.
        ILogger<DbMigrator> logger = LoggerFactory
            .Create(builder => builder.AddDebug())
            .CreateLogger<DbMigrator>();

        Mock<IDateTimeHelper> dateTimeHelperMock = new();

        // Can also use the PostgreSqlConnector to connect to PostgreSQL
        // instead of Microsoft SQL Server.
        DbMigrator migrator = DbMigrator.CreateForLocalIntegrationTesting(
              migrationConfiguration: config
            , logger: logger
            , dataTimeHelperMock: dateTimeHelperMock.Object
            , databaseConnector: new MicrosoftSqlConnector());

        bool succeededDeletingDatabase =
            await migrator.TryDeleteDatabaseIfExistAsync(
                  migrationConfiguration: config
                , cancellationToken: TestContext.CancellationToken);
        Assert.IsTrue(succeededDeletingDatabase);

        bool succeededRunningMigrations =
            await migrator.TryApplyMigrationsAsync(
                  typeOfClassWhereScriptsAreLocated:
                      typeof(HereTheSqlServerScriptsCanBeFound)
                , migrationConfiguration: config
                , cancellationToken: TestContext.CancellationToken);
        Assert.IsTrue(succeededRunningMigrations);

        // Download the code if you want to see more examples of integration
        // testing with EasyDBMigrator.
    }
}

Alternatives

License

Free to use

About

EasyDBMigrator - making SQL and PostgreSQL database migrations and integration testing easier

Topics

Resources

Security policy

Stars

2 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages