Skip to content

EasyDBMigrator - making database migrations and integration testing easier with legacy systems

License

Notifications You must be signed in to change notification settings

Retrodad0001/EasyDbMigrator

Repository files navigation

The Latest news and Roadmap

3.0.x (the latest release)

  • add support for .net 8 and .NET 9 (when stable version is out)
  • 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:

Action (jobs):

Build

Build

Build

Build

Code statistics:

codecov

More info:

NuGet Nuget

EasyDBMigrator - making database migrations and integration testing easier

What is EasyDBMigrator?

EasyDBMigrator is an open-source database migration framework. It strongly favors simplicity and ease of use for automatic CI/CD strategies and local integration testing scenarios and easy integration in its 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 Postgre SQL migrations in your CI/CD flows
  3. Make it easy to perform manual Microsoft SQL migrations
  4. Make it easy to perform manual Postgre SQL 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:

    private async Task RunMigrations()
    {
        //Make sure you use the correct naming in your scripts, like:
        // 20210926_001_AddEquipmentTable.sql --> script 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 MigrationConfiguration(connectionString: connectionstring, databaseName: databaseName);

        //for writing the logging output from EasyDBMigrator to the test explorer output window
        var logger = XUnitLoghelper.CreateLogger<DatabaseTests>(_testOutputHelper);
        Mock<IDataTimeHelper> datetimeHelperMock = new Mock<IDataTimeHelper>();

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

        bool succeededDeletingDatabase = await migrator.TryDeleteDatabaseIfExistAsync(migrationConfiguration: config
                , cancellationToken: token);
            _ = succeededDeletingDatabase.Should().BeTrue();

        bool succeededRunningMigrations = await migrator.TryApplyMigrationsAsync(typeOfClassWhereScriptsAreLocated: typeof(HereTheSQLServerScriptsCanBeFound)
                , migrationConfiguration: config
                , cancellationToken: token);
            _ = succeededRunningMigrations.Should().BeTrue();
        
        //download the code if you want to see examples of integration testing with easyDbMigrator
    }

FAQ

Alternatives

https://github.com/chucknorris/roundhouse

https://github.com/erikbra/grate

https://github.com/fluentmigrator/fluentmigrator

License

Free to use

About

EasyDBMigrator - making database migrations and integration testing easier with legacy systems

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages