public int RunListOption(ListOption opts) { try { var platform = _configurationService.GetValueOrDefault(opts.Platform, ENVIRONMENT_VARIABLE.YUNIQL_PLATFORM, defaultValue: SUPPORTED_DATABASES.SQLSERVER); var configuration = Configuration.Instance; configuration.Workspace = opts.Workspace; configuration.IsDebug = opts.IsDebug; configuration.Platform = platform; configuration.ConnectionString = opts.ConnectionString; configuration.CommandTimeout = opts.CommandTimeout; configuration.MetaSchemaName = opts.MetaSchema; configuration.MetaTableName = opts.MetaTable; //get all exsiting db versions var migrationService = _migrationServiceFactory.Create(configuration.Platform); var versions = migrationService.GetAllVersions(configuration.MetaSchemaName, configuration.MetaTableName); //TODO: add duration var versionPrettyPrint = new TablePrinter("SchemaVersion", "AppliedOnUtc", "Status", "AppliedByUser", "AppliedByTool", "Duration"); versions.ForEach(v => versionPrettyPrint.AddRow(v.Version, v.AppliedOnUtc.ToString("u"), v.Status, v.AppliedByUser, $"{v.AppliedByTool} {v.AppliedByToolVersion}", $"{v.DurationMs} ms / {v.DurationMs/1000} s")); versionPrettyPrint.Print(); var failedVersion = versions.LastOrDefault(v => v.Status == Status.Failed); if (null != failedVersion) { var failedVersionMessage = $"Previous run was not successful, see details below:{Environment.NewLine}" + $"Last failed version: {failedVersion.Version}{Environment.NewLine}" + $"Last failed script: {failedVersion.FailedScriptPath}{Environment.NewLine}" + $"Last error message: {failedVersion.FailedScriptError}{Environment.NewLine}" + $"Suggested action: Fix the failed script and run manually outside of yuniql." + @$ "After that, try to issue " "yuniql run" " command again with " "--continue-after-failure" " parameter.{Environment.NewLine}"; _traceService.Warn(failedVersionMessage); } _traceService.Success($"Listed all schema versions applied to database on {configuration.Workspace} workspace.{Environment.NewLine}" + $"For platforms not supporting full transactional DDL operations (ex. MySql, Snowflake, CockroachDB), unsuccessful migrations will show the status as Failed and you can look for FailedScriptPath and FailedScriptError in the schema version tracking table."); return(0); } catch (Exception ex) { return(OnException(ex, "Failed to execute list function", opts.IsDebug)); } }
public int RunListOption(ListOption opts) { try { //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); } //get all exsiting db versions var migrationService = _migrationServiceFactory.Create(opts.Platform); migrationService.Initialize(opts.ConnectionString, opts.CommandTimeout); var versions = migrationService.GetAllVersions(opts.MetaSchema, opts.MetaTable); var versionPrettyPrint = new TablePrinter("SchemaVersion", "AppliedOnUtc", "Status", "AppliedByUser", "AppliedByTool"); versions.ForEach(v => versionPrettyPrint.AddRow(v.Version, v.AppliedOnUtc.ToString("u"), v.Status, v.AppliedByUser, $"{v.AppliedByTool} {v.AppliedByToolVersion}")); versionPrettyPrint.Print(); _traceService.Success($"Listed all schema versions applied to database on {opts.Path} workspace.{Environment.NewLine}" + $"For platforms not supporting full transactional DDL operations (ex. MySql, CockroachDB, Snowflake), unsuccessful migrations will show the status as Failed and you can look for LastFailedScript and LastScriptError in the schema version tracking table."); return(0); } catch (Exception ex) { return(OnException(ex, "Failed to execute info function", opts.Debug, _traceService)); } }