Ejemplo n.º 1
0
        public int RunRunOption(RunOption opts)
        {
            try
            {
                //run the migration
                var configuration    = SetupRunConfiguration(opts, isVerifyOnly: false);
                var migrationService = _migrationServiceFactory.Create(configuration.Platform);
                migrationService.Run();

                _traceService.Success($"Schema migration completed successfuly on {configuration.Workspace}.");
                return(0);
            }
            catch (Exception ex)
            {
                return(OnException(ex, "Failed to execute run function", opts.IsDebug));
            }
        }
Ejemplo n.º 2
0
        public int RunMigration(RunOption opts)
        {
            try
            {
                //if no path provided, we default into current directory
                if (string.IsNullOrEmpty(opts.Path))
                {
                    var workingPath = _environmentService.GetCurrentDirectory();
                    opts.Path = workingPath;
                }
                _traceService.Info($"Started migration from {opts.Path}.");

                //if no target platform provided, we default into sqlserver
                if (string.IsNullOrEmpty(opts.Platform))
                {
                    opts.Platform = _environmentService.GetEnvironmentVariable(ENVIRONMENT_VARIABLE.YUNIQL_TARGET_PLATFORM);
                    if (string.IsNullOrEmpty(opts.Platform))
                    {
                        opts.Platform = SUPPORTED_DATABASES.SQLSERVER;
                    }
                }

                //if no connection string provided, we default into environment variable or throw exception
                if (string.IsNullOrEmpty(opts.ConnectionString))
                {
                    opts.ConnectionString = _environmentService.GetEnvironmentVariable(ENVIRONMENT_VARIABLE.YUNIQL_CONNECTION_STRING);
                }

                //if no target version specified, we capture the latest from local folder structure
                if (string.IsNullOrEmpty(opts.TargetVersion))
                {
                    opts.TargetVersion = _localVersionService.GetLatestVersion(opts.Path);
                    _traceService.Info($"No explicit target version requested. We'll use latest available locally {opts.TargetVersion} on {opts.Path}.");
                }

                //parse tokens
                var tokens = opts.Tokens
                             .Select(t => new KeyValuePair <string, string>(t.Split("=")[0], t.Split("=")[1]))
                             .ToList();

                //run the migration
                var toolName    = "yuniql-cli";
                var toolVersion = this.GetType().Assembly.GetName().Version.ToString();

                var migrationService = _migrationServiceFactory.Create(opts.Platform);
                migrationService.Initialize(opts.ConnectionString, opts.CommandTimeout);
                migrationService.Run(opts.Path,
                                     opts.TargetVersion,
                                     autoCreateDatabase: opts.AutoCreateDatabase,
                                     tokens: tokens,
                                     verifyOnly: false,
                                     bulkSeparator: opts.BulkSeparator,
                                     metaSchemaName: opts.MetaSchema,
                                     metaTableName: opts.MetaTable,
                                     commandTimeout: opts.CommandTimeout,
                                     bulkBatchSize: opts.BulkBatchSize,
                                     appliedByTool: toolName,
                                     appliedByToolVersion: toolVersion,
                                     environmentCode: opts.Environment,
                                     opts.ContinueAfterFailure
                    ? NonTransactionalResolvingOption.ContinueAfterFailure
                    : (NonTransactionalResolvingOption?)null,
                                     opts.NoTransaction,
                                     opts.RequiredClearedDraft);

                _traceService.Success($"Schema migration completed successfuly on {opts.Path}.");
                return(0);
            } catch (Exception ex)
            {
                return(OnException(ex, "Failed to execute run function", opts.Debug, _traceService));
            }
        }
Ejemplo n.º 3
0
        public int RunMigration(RunOption opts)
        {
            try
            {
                //if no path provided, we default into current directory
                if (string.IsNullOrEmpty(opts.Path))
                {
                    var workingPath = _environmentService.GetCurrentDirectory();
                    opts.Path = workingPath;
                }
                _traceService.Info($"Started migration from {opts.Path}.");

                //if no target platform provided, we default into sqlserver
                if (string.IsNullOrEmpty(opts.Platform))
                {
                    opts.Platform = _environmentService.GetEnvironmentVariable(ENVIRONMENT_VARIABLE.YUNIQL_TARGET_PLATFORM);
                    if (string.IsNullOrEmpty(opts.Platform))
                    {
                        opts.Platform = SUPPORTED_DATABASES.SQLSERVER;
                    }
                }

                //if no connection string provided, we default into environment variable or throw exception
                if (string.IsNullOrEmpty(opts.ConnectionString))
                {
                    opts.ConnectionString = _environmentService.GetEnvironmentVariable(ENVIRONMENT_VARIABLE.YUNIQL_CONNECTION_STRING);
                }

                //if no target version specified, we capture the latest from local folder structure
                if (string.IsNullOrEmpty(opts.TargetVersion))
                {
                    opts.TargetVersion = _localVersionService.GetLatestVersion(opts.Path);
                    _traceService.Info($"No explicit target version requested. We'll use latest available locally {opts.TargetVersion} on {opts.Path}.");
                }

                //parse tokens
                var tokens = opts.Tokens.Select(t => new KeyValuePair <string, string>(t.Split("=")[0], t.Split("=")[1])).ToList();

                //run the migration
                var toolName    = "yuniql-cli";
                var toolVersion = this.GetType().Assembly.GetName().Version.ToString();

                var migrationService = _migrationServiceFactory.Create(opts.Platform);
                migrationService.Initialize(opts.ConnectionString, opts.CommandTimeout);
                migrationService.Run(
                    opts.Path,
                    opts.TargetVersion,
                    autoCreateDatabase: opts.AutoCreateDatabase,
                    tokens: tokens,
                    verifyOnly: false,
                    delimiter: opts.Delimiter,
                    schemaName: opts.Schema,
                    tableName: opts.Table,
                    commandTimeout: opts.CommandTimeout,
                    batchSize: null,
                    appliedByTool: toolName,
                    appliedByToolVersion: toolVersion,
                    environmentCode: opts.Environment
                    );
            }
            catch (Exception ex)
            {
                _traceService.Error($"Failed to execute run function. {Environment.NewLine}{ex.ToString()}");
                return(1);
            }

            return(0);
        }