/// <summary>
        /// Runs database migrations with Yuniql. Use this interface to run migrations targeting non-sqlserver platforms such as PostgreSql and MySql.
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="dataService">Implementation of <see cref="IDataService". See Yuniql.PostgreSql and Yuniql.MySql pacages./></param>
        /// <param name="bulkImportService">Implementation of <see cref="IBulkImportService". See Yuniql.PostgreSql and Yuniql.MySql pacages./></param>
        /// <param name="traceService">Your custom implementation of ITraceService interface</param>
        /// <param name="configuration">Desired configuration when yuniql runs. Set your workspace location, connection string, target version and other parameters.</param>
        /// <returns></returns>
        public static IWebHostBuilder UseYuniql(
            this IWebHostBuilder builder,
            IDataService dataService,
            IBulkImportService bulkImportService,
            ITraceService traceService,
            YuniqlConfiguration configuration
            )
        {
            var migrationServiceFactory = new MigrationServiceFactory(traceService);
            var migrationService        = migrationServiceFactory.Create(dataService, bulkImportService);

            migrationService.Initialize(configuration.ConnectionString);
            migrationService.Run(
                configuration.WorkspacePath,
                configuration.TargetVersion,
                autoCreateDatabase: configuration.AutoCreateDatabase,
                tokens: configuration.Tokens,
                verifyOnly: configuration.VerifyOnly,
                bulkSeparator: configuration.BulkSeparator,
                metaSchemaName: configuration.MetaSchemaName,
                metaTableName: configuration.MetaTableName,
                commandTimeout: configuration.CommandTimeout,
                bulkBatchSize: configuration.BulkBatchSize,
                appliedByTool: configuration.ApplyByTool,
                appliedByToolVersion: configuration.ApplyByToolVersion,
                environmentCode: configuration.Environment);

            return(builder);
        }
Example #2
0
        /// <summary>
        /// Runs database migrations with Yuniql. Use this interface to run migrations targeting non-sqlserver platforms such as PostgreSql and MySql.
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="dataService">Implementation of <see cref="IDataService". See Yuniql.PostgreSql and Yuniql.MySql pacages./></param>
        /// <param name="bulkImportService">Implementation of <see cref="IBulkImportService". See Yuniql.PostgreSql and Yuniql.MySql pacages./></param>
        /// <param name="traceService">Your custom implementation of ITraceService interface</param>
        /// <param name="configuration">Desired configuration when yuniql runs. Set your workspace location, connection string, target version and other parameters.</param>
        /// <returns></returns>
        public static IWebHostBuilder UseYuniql(
            this IWebHostBuilder builder,
            IDataService dataService,
            IBulkImportService bulkImportService,
            ITraceService traceService,
            Configuration configuration
            )
        {
            var migrationServiceFactory = new MigrationServiceFactory(traceService);
            var migrationService        = migrationServiceFactory.Create(dataService, bulkImportService);

            migrationService.Initialize(configuration.ConnectionString);
            migrationService.Run(
                configuration.WorkspacePath,
                targetVersion: configuration.TargetVersion,
                autoCreateDatabase: configuration.AutoCreateDatabase,
                tokens: configuration.Tokens,
                verifyOnly: configuration.VerifyOnly,
                bulkSeparator: configuration.BulkSeparator,
                metaSchemaName: configuration.MetaSchemaName,
                metaTableName: configuration.MetaTableName,
                commandTimeout: configuration.CommandTimeout,
                bulkBatchSize: configuration.BulkBatchSize,
                appliedByTool: configuration.AppliedByTool,
                appliedByToolVersion: configuration.AppliedByToolVersion,
                environmentCode: configuration.Environment,
                resumeFromFailure: configuration.ContinueAfterFailure.HasValue && configuration.ContinueAfterFailure.Value ? NonTransactionalResolvingOption.ContinueAfterFailure : (NonTransactionalResolvingOption?)null,
                noTransaction: configuration.NoTransaction
                );

            return(builder);
        }
Example #3
0
        /// <summary>
        /// Runs database migrations with Yuniql. Use this interface to run migrations targeting non-sqlserver platforms such as PostgreSql and MySql.
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="dataService">Implementation of <see cref="IDataService". See Yuniql.PostgreSql and Yuniql.MySql pacages./></param>
        /// <param name="bulkImportService">Implementation of <see cref="IBulkImportService". See Yuniql.PostgreSql and Yuniql.MySql pacages./></param>
        /// <param name="traceService">Your custom implementation of ITraceService interface</param>
        /// <param name="configuration">Desired configuration when yuniql runs. Set your workspace location, connection string, target version and other parameters.</param>
        /// <returns></returns>
        public static IHostBuilder UseYuniql(
            this IHostBuilder builder,
            IDataService dataService,
            IBulkImportService bulkImportService,
            ITraceService traceService,
            YuniqlConfiguration configuration
            )
        {
            var migrationServiceFactory = new MigrationServiceFactory(traceService);
            var migrationService        = migrationServiceFactory.Create(dataService, bulkImportService);

            migrationService.Initialize(configuration.ConnectionString);
            migrationService.Run(
                configuration.WorkspacePath,
                configuration.TargetVersion,
                configuration.AutoCreateDatabase,
                configuration.Tokens,
                configuration.VerifyOnly,
                configuration.Delimiter,
                configuration.BatchSize,
                configuration.CommandTimeout,
                configuration.ApplyByTool,
                configuration.ApplyByToolVersion,
                configuration.Environment);

            return(builder);
        }
Example #4
0
        /// <summary>
        /// Runs database migrations with Yuniql. This uses your specific implementation of ITraceService interface.
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="traceService">Your custom implementation of ITraceService interface</param>
        /// <param name="configuration">Desired configuration when yuniql runs. Set your workspace location, connection string, target version and other parameters.</param>
        /// <returns></returns>
        public static IApplicationBuilder UseYuniql(
            this IApplicationBuilder builder,
            ITraceService traceService,
            Configuration configuration
            )
        {
            ConfigurationHelper.Initialize(configuration);

            var migrationServiceFactory = new MigrationServiceFactory(traceService);
            var migrationService        = migrationServiceFactory.Create();

            migrationService.Run();

            return(builder);
        }
Example #5
0
        /// <summary>
        /// Runs database migrations with Yuniql. Use this interface to run migrations targeting non-sqlserver platforms such as PostgreSql and MySql.
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="dataService">Implementation of <see cref="IDataService". See Yuniql.PostgreSql and Yuniql.MySql pacages./></param>
        /// <param name="bulkImportService">Implementation of <see cref="IBulkImportService". See Yuniql.PostgreSql and Yuniql.MySql pacages./></param>
        /// <param name="traceService">Your custom implementation of ITraceService interface</param>
        /// <param name="configuration">Desired configuration when yuniql runs. Set your workspace location, connection string, target version and other parameters.</param>
        /// <returns></returns>
        public static IHostBuilder UseYuniql(
            this IHostBuilder builder,
            IDataService dataService,
            IBulkImportService bulkImportService,
            ITraceService traceService,
            Configuration configuration
            )
        {
            ConfigurationHelper.Initialize(configuration);

            var migrationServiceFactory = new MigrationServiceFactory(traceService);
            var migrationService        = migrationServiceFactory.Create(dataService, bulkImportService);

            migrationService.Run();

            return(builder);
        }
Example #6
0
        static void Main(string[] args)
        {
            //docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=P@ssw0rd!" -p 1400:1433 -d mcr.microsoft.com/mssql/server:2017-latest
            var baseDirectory = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, @"..\..\..\"));
            var traceService  = new ConsoleTraceService {
                IsDebugEnabled = true
            };
            var configuration = new YuniqlConfiguration
            {
                WorkspacePath      = Path.Combine(baseDirectory, "_db"),
                ConnectionString   = "Server=localhost,1400;Database=yuniqldb;User Id=SA;Password=P@ssw0rd!",
                AutoCreateDatabase = true,
                Tokens             = new List <KeyValuePair <string, string> > {
                    new KeyValuePair <string, string>("VwColumnPrefix1", "Vw1"),
                    new KeyValuePair <string, string>("VwColumnPrefix2", "Vw2"),
                    new KeyValuePair <string, string>("VwColumnPrefix3", "Vw3"),
                    new KeyValuePair <string, string>("VwColumnPrefix4", "Vw4")
                }
            };

            var migrationServiceFactory = new MigrationServiceFactory(traceService);
            var migrationService        = migrationServiceFactory.Create();

            migrationService.Initialize(configuration.ConnectionString);
            migrationService.Run(
                configuration.WorkspacePath,
                configuration.TargetVersion,
                configuration.AutoCreateDatabase,
                configuration.Tokens,
                configuration.VerifyOnly,
                configuration.BulkSeparator);

            var requiredDbVersion = "v1.01";
            var currentDbVersion  = migrationService.GetCurrentVersion();

            if (currentDbVersion != requiredDbVersion)
            {
                throw new ApplicationException($"Startup failed. " +
                                               $"Application requires database version {requiredDbVersion} but current version is {currentDbVersion}." +
                                               $"Deploy the latest compatible schema version of database and run again.");
            }
        }
Example #7
0
        static void Main(string[] args)
        {
            //1. deploy new sql server on docker
            //$ docker run -dit -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=P@ssw0rd!" -p 1400:1433 -d mcr.microsoft.com/mssql/server:2017-latest

            //2. create custom trace message sinks
            var traceService = new ConsoleTraceService {
                IsDebugEnabled = true
            };

            //3. configure your migration run
            var configuration = new YuniqlConfiguration
            {
                WorkspacePath      = Path.Combine(Environment.CurrentDirectory, "_db"),
                ConnectionString   = "Server=localhost,1400;Database=yuniqldb;User Id=SA;Password=P@ssw0rd!",
                AutoCreateDatabase = true
            };

            //4. run migrations
            var migrationServiceFactory = new MigrationServiceFactory(traceService);
            var migrationService        = migrationServiceFactory.Create();

            migrationService.Initialize(configuration.ConnectionString);
            migrationService.Run(
                configuration.WorkspacePath,
                targetVersion: configuration.TargetVersion,
                autoCreateDatabase: configuration.AutoCreateDatabase
                );

            //5. validate for schema version compatibility
            var requiredDbVersion = "v0.00";
            var currentDbVersion  = migrationService.GetCurrentVersion();

            if (currentDbVersion != requiredDbVersion)
            {
                throw new ApplicationException($"Startup failed. " +
                                               $"Application requires database version {requiredDbVersion} but current version is {currentDbVersion}." +
                                               $"Deploy the latest compatible schema version of database and run again.");
            }
        }
Example #8
0
        static void Main(string[] args)
        {
            //1. deploy new sql server on docker
            //$ docker run -dit -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=P@ssw0rd!" -p 1400:1433 -d mcr.microsoft.com/mssql/server:2017-latest

            //2. create custom trace message sinks, this can be your own logger framework
            var traceService = new ConsoleTraceService {
                IsDebugEnabled = true
            };

            //3. configure your migration run
            var configuration = Configuration.Instance;

            configuration.Platform             = SUPPORTED_DATABASES.SQLSERVER;
            configuration.Workspace            = Path.Combine(Environment.CurrentDirectory, "_db");
            configuration.ConnectionString     = "Server=localhost,1400;Database=helloyuniql;User Id=SA;Password=P@ssw0rd!";
            configuration.IsAutoCreateDatabase = true;
            configuration.IsDebug = true;

            //4. run migrations
            var migrationServiceFactory = new MigrationServiceFactory(traceService);
            var migrationService        = migrationServiceFactory.Create();

            migrationService.Run();

            //5. alternatively, you can validate app for schema version compatibility
            var requiredDbVersion = "v0.00";
            var currentDbVersion  = migrationService.GetCurrentVersion();

            if (currentDbVersion != requiredDbVersion)
            {
                throw new ApplicationException($"Startup failed. " +
                                               $"Application requires database version {requiredDbVersion} but current version is {currentDbVersion}." +
                                               $"Deploy the latest compatible schema version of database and run again.");
            }
        }