Skip to content

Commit

Permalink
Fixed broken tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rdagumampan committed May 26, 2020
1 parent a94bc0e commit 50167ba
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 51 deletions.
2 changes: 1 addition & 1 deletion yuniql-cli/CommandLineService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public int RunInfoOption(InfoOption opts)
//get all exsiting db versions
var migrationService = _migrationServiceFactory.Create(opts.Platform);
migrationService.Initialize(opts.ConnectionString, opts.CommandTimeout);
var versions = migrationService.GetAllVersions(opts.Schema, opts.Table);
var versions = migrationService.GetAllVersions(opts.MetaSchema, opts.MetaTable);

var results = new StringBuilder();
results.AppendLine($"Version\t\tCreated\t\t\t\tCreatedBy");
Expand Down
10 changes: 5 additions & 5 deletions yuniql-cli/InfoOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ namespace Yuniql.CLI
[Verb("info", HelpText = "Shows all the migrations applied to target database.")]
public class InfoOption : BasePlatformOption
{
//yuniql <command> --schema "yuniql"
[Option("schema", Required = false, HelpText = "Schema name for schema versions table.")]
public string Schema { get; set; }
//yuniql <command> --meta-schema "yuniql"
[Option("meta-schema", Required = false, HelpText = "Schema name for schema versions table.")]
public string MetaSchema { get; set; }

//yuniql <command> --table "__yuniqlschemaversions"
[Option("table", Required = false, HelpText = "Table name for schema versions table.")]
public string Table { get; set; }
[Option("meta-table", Required = false, HelpText = "Table name for schema versions table.")]
public string MetaTable { get; set; }
}
}
34 changes: 17 additions & 17 deletions yuniql-core/ConfigurationDataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ public void CreateDatabase(int? commandTimeout = null)
}

///<inheritdoc/>
public void CreateSchema(string schemaName, int? commandTimeout = null)
public void CreateSchema(string metaSchemaName, int? commandTimeout = null)
{
var tokens = new List<KeyValuePair<string, string>> {
new KeyValuePair<string, string>(RESERVED_TOKENS.YUNIQL_SCHEMA_NAME, schemaName),
new KeyValuePair<string, string>(RESERVED_TOKENS.YUNIQL_SCHEMA_NAME, metaSchemaName),
};
var sqlStatement = _tokenReplacementService.Replace(tokens, _dataService.GetSqlForCreateSchema());
using (var connection = _dataService.CreateConnection())
Expand All @@ -93,11 +93,11 @@ public void CreateSchema(string schemaName, int? commandTimeout = null)

///<inheritdoc/>
public bool IsDatabaseConfigured(
string schemaName = null,
string tableName = null,
string metaSchemaName = null,
string metaTableName = null,
int? commandTimeout = null)
{
var sqlStatement = GetPreparedSqlStatement(_dataService.GetSqlForCheckIfDatabaseConfigured(), schemaName, tableName);
var sqlStatement = GetPreparedSqlStatement(_dataService.GetSqlForCheckIfDatabaseConfigured(), metaSchemaName, metaTableName);
using (var connection = _dataService.CreateConnection())
{
return connection.QuerySingleBool(
Expand All @@ -110,11 +110,11 @@ public bool IsDatabaseConfigured(

///<inheritdoc/>
public void ConfigureDatabase(
string schemaName = null,
string tableName = null,
string metaSchemaName = null,
string metaTableName = null,
int? commandTimeout = null)
{
var sqlStatement = GetPreparedSqlStatement(_dataService.GetSqlForConfigureDatabase(), schemaName, tableName);
var sqlStatement = GetPreparedSqlStatement(_dataService.GetSqlForConfigureDatabase(), metaSchemaName, metaTableName);
using (var connection = _dataService.CreateConnection())
{
connection.ExecuteNonQuery(
Expand All @@ -127,24 +127,24 @@ public void ConfigureDatabase(

///<inheritdoc/>
public bool UpdateDatabaseConfiguration(
string schemaName = null,
string tableName = null,
string metaSchemaName = null,
string metaTableName = null,
int? commandTimeout = null)
{
using (var connection = _dataService.CreateConnection())
{
connection.KeepOpen();
return _dataService.UpdateDatabaseConfiguration(connection, _traceService, schemaName, tableName);
return _dataService.UpdateDatabaseConfiguration(connection, _traceService, metaSchemaName, metaTableName);
}
}

///<inheritdoc/>
public string GetCurrentVersion(
string schemaName = null,
string tableName = null,
string metaSchemaName = null,
string metaTableName = null,
int? commandTimeout = null)
{
var sqlStatement = GetPreparedSqlStatement(_dataService.GetSqlForGetCurrentVersion(), schemaName, tableName);
var sqlStatement = GetPreparedSqlStatement(_dataService.GetSqlForGetCurrentVersion(), metaSchemaName, metaTableName);
using (var connection = _dataService.CreateConnection())
{
return connection.QuerySingleString(
Expand All @@ -157,11 +157,11 @@ public string GetCurrentVersion(

///<inheritdoc/>
public List<DbVersion> GetAllAppliedVersions(
string schemaName = null,
string tableName = null,
string metaSchemaName = null,
string metaTableName = null,
int? commandTimeout = null)
{
return this.GetAllVersions(schemaName, tableName, commandTimeout)
return this.GetAllVersions(metaSchemaName, metaTableName, commandTimeout)
.Where(x => x.Status == Status.Successful).ToList();
}

Expand Down
36 changes: 18 additions & 18 deletions yuniql-core/IConfigurationDataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,59 +25,59 @@ public interface IConfigurationDataService
/// <summary>
/// Returns true when migration version tracking table is already created.
/// </summary>
/// <param name="schemaName">Schema name for schema versions table. When empty, uses the default schema in the target data platform. </param>
/// <param name="tableName">Table name for schema versions table. When empty, uses __yuniqldbversion.</param>
/// <param name="metaSchemaName">Schema name for schema versions table. When empty, uses the default schema in the target data platform. </param>
/// <param name="metaTableName">Table name for schema versions table. When empty, uses __yuniqldbversion.</param>
/// <param name="commandTimeout">Command timeout in seconds.</param>
/// <returns>Returns true when version tracking table is already created.</returns>
bool IsDatabaseConfigured(string schemaName, string tableName, int? commandTimeout = null);
bool IsDatabaseConfigured(string metaSchemaName, string metaTableName, int? commandTimeout = null);

/// <summary>
/// Creates schema in target databases.
/// </summary>
/// <param name="schemaName">Schema name for schema versions table. When empty, uses the default schema in the target data platform. </param>
/// <param name="metaSchemaName">Schema name for schema versions table. When empty, uses the default schema in the target data platform. </param>
/// <param name="commandTimeout">Command timeout in seconds.</param>
void CreateSchema(string schemaName, int? commandTimeout = null);
void CreateSchema(string metaSchemaName, int? commandTimeout = null);

/// <summary>
/// Creates migration version tracking table in the target database.
/// </summary>
/// <param name="schemaName">Schema name for schema versions table. When empty, uses the default schema in the target data platform. </param>
/// <param name="tableName">Table name for schema versions table. When empty, uses __yuniqldbversion.</param>
/// <param name="metaSchemaName">Schema name for schema versions table. When empty, uses the default schema in the target data platform. </param>
/// <param name="metaTableName">Table name for schema versions table. When empty, uses __yuniqldbversion.</param>
/// <param name="commandTimeout">Command timeout in seconds.</param>
void ConfigureDatabase(string schemaName, string tableName, int? commandTimeout = null);
void ConfigureDatabase(string metaSchemaName, string metaTableName, int? commandTimeout = null);

/// <summary>
/// Updates migration version tracking table in the target database..
/// </summary>
/// <returns>True if target database was updated, otherwise returns false</returns>
bool UpdateDatabaseConfiguration(string schemaName, string tableName, int? commandTimeout = null);
bool UpdateDatabaseConfiguration(string metaSchemaName, string metaTableName, int? commandTimeout = null);

/// <summary>
/// Returns the latest version applied in the target database.
/// </summary>
/// <param name="schemaName">Schema name for schema versions table. When empty, uses the default schema in the target data platform. </param>
/// <param name="tableName">Table name for schema versions table. When empty, uses __yuniqldbversion.</param>
/// <param name="metaSchemaName">Schema name for schema versions table. When empty, uses the default schema in the target data platform. </param>
/// <param name="metaTableName">Table name for schema versions table. When empty, uses __yuniqldbversion.</param>
/// <param name="commandTimeout">Command timeout in seconds.</param>
/// <returns>Returns the latest version applied in the target database.</returns>
string GetCurrentVersion(string schemaName, string tableName, int? commandTimeout = null);
string GetCurrentVersion(string metaSchemaName, string metaTableName, int? commandTimeout = null);

/// <summary>
/// Returns all versions applied in the target database.
/// </summary>
/// <param name="schemaName">Schema name for schema versions table. When empty, uses the default schema in the target data platform. </param>
/// <param name="tableName">Table name for schema versions table. When empty, uses __yuniqldbversion.</param>
/// <param name="metaSchemaName">Schema name for schema versions table. When empty, uses the default schema in the target data platform. </param>
/// <param name="metaTableName">Table name for schema versions table. When empty, uses __yuniqldbversion.</param>
/// <param name="commandTimeout">Command timeout in seconds.</param>
/// <returns>All versions applied in the target database.</returns>
public List<DbVersion> GetAllAppliedVersions(string schemaName, string tableName, int? commandTimeout = null);
public List<DbVersion> GetAllAppliedVersions(string metaSchemaName, string metaTableName, int? commandTimeout = null);

/// <summary>
/// Returns all versions applied in the target database.
/// </summary>
/// <param name="schemaName">Schema name for schema versions table. When empty, uses the default schema in the target data platform. </param>
/// <param name="tableName">Table name for schema versions table. When empty, uses __yuniqldbversion.</param>
/// <param name="metaSchemaName">Schema name for schema versions table. When empty, uses the default schema in the target data platform. </param>
/// <param name="metaTableName">Table name for schema versions table. When empty, uses __yuniqldbversion.</param>
/// <param name="commandTimeout">Command timeout in seconds.</param>
/// <returns>All versions applied in the target database.</returns>
List<DbVersion> GetAllVersions(string schemaName, string tableName, int? commandTimeout = null);
List<DbVersion> GetAllVersions(string metaSchemaName, string metaTableName, int? commandTimeout = null);


/// <summary>
Expand Down
12 changes: 6 additions & 6 deletions yuniql-core/MigrationServiceBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,16 @@ public virtual void Initialize(
}

/// <inheritdoc />
public virtual string GetCurrentVersion(string schemaName = null, string tableName = null)
public virtual string GetCurrentVersion(string metaSchemaName = null, string metaTableName = null)
{
return _configurationDataService.GetCurrentVersion(schemaName, tableName);
return _configurationDataService.GetCurrentVersion(metaSchemaName, metaTableName);
}

/// <inheritdoc />
//TODO: Move this to MigrationServiceBase
public virtual List<DbVersion> GetAllVersions(string schemaName = null, string tableName = null)
public virtual List<DbVersion> GetAllVersions(string metaSchemaName = null, string metaTableName = null)
{
return _configurationDataService.GetAllAppliedVersions(schemaName, tableName);
return _configurationDataService.GetAllAppliedVersions(metaSchemaName, metaTableName);
}

/// <inheritdoc />
Expand All @@ -82,10 +82,10 @@ public abstract void Run(
);

/// <inheritdoc />
public virtual bool IsTargetDatabaseLatest(string targetVersion, string schemaName = null, string tableName = null)
public virtual bool IsTargetDatabaseLatest(string targetVersion, string metaSchemaName = null, string metaTableName = null)
{
//get the current version stored in database
var remoteCurrentVersion = _configurationDataService.GetCurrentVersion(schemaName, tableName);
var remoteCurrentVersion = _configurationDataService.GetCurrentVersion(metaSchemaName, metaTableName);
if (string.IsNullOrEmpty(remoteCurrentVersion)) return false;

//compare version applied in db vs versions available locally
Expand Down
8 changes: 4 additions & 4 deletions yuniql-tests/platform-tests/Cli/CliTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ public void Test_Cli_verify_With_Custom_Schema(string command, string arguments)
SetupWorkspaceWithSampleDb();

//act & assert
var result = _executionService.Run("run", _testConfiguration.WorkspacePath, _testConfiguration.ConnectionString, _testConfiguration.Platform, "-a -t v0.00 --schema \"my_schema\" --table \"my_versions\" ");
var result = _executionService.Run("run", _testConfiguration.WorkspacePath, _testConfiguration.ConnectionString, _testConfiguration.Platform, "-a -t v0.00 --meta-schema \"my_schema\" --meta-table \"my_versions\" ");
result.Contains($"Failed to execute run").ShouldBeFalse();

//act & assert
result = _executionService.Run(command, _testConfiguration.WorkspacePath, _testConfiguration.ConnectionString, _testConfiguration.Platform, "--schema \"my_schema\" --table \"my_versions\" " +arguments);
result = _executionService.Run(command, _testConfiguration.WorkspacePath, _testConfiguration.ConnectionString, _testConfiguration.Platform, "--meta-schema \"my_schema\" --meta-table \"my_versions\" " + arguments);
result.Contains($"Failed to execute {command}").ShouldBeFalse();
}

Expand Down Expand Up @@ -162,11 +162,11 @@ public void Test_Cli_info_With_Custom_Schema(string command, string arguments)
SetupWorkspaceWithSampleDb();

//act & assert
var result = _executionService.Run("run", _testConfiguration.WorkspacePath, _testConfiguration.ConnectionString, _testConfiguration.Platform, "-a --schema \"my_schema\" --table \"my_versions\" -d");
var result = _executionService.Run("run", _testConfiguration.WorkspacePath, _testConfiguration.ConnectionString, _testConfiguration.Platform, "-a --meta-schema \"my_schema\" --meta-table \"my_versions\" -d");
result.Contains($"Failed to execute run").ShouldBeFalse();

//act & assert
result = _executionService.Run(command, _testConfiguration.WorkspacePath, _testConfiguration.ConnectionString, _testConfiguration.Platform, "--schema \"my_schema\" --table \"my_versions\" " + arguments);
result = _executionService.Run(command, _testConfiguration.WorkspacePath, _testConfiguration.ConnectionString, _testConfiguration.Platform, "--meta-schema \"my_schema\" --meta-table \"my_versions\" " + arguments);
result.Contains($"Failed to execute {command}").ShouldBeFalse();
}

Expand Down

0 comments on commit 50167ba

Please sign in to comment.