Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions yuniql-core/ConnectivityService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,34 @@ public ConnectivityService(IDataService dataService, ITraceService traceService)
this._connectionInfo = _dataService.GetConnectionInfo();
}

/// <summary>
/// Checks the database server informations
/// </summary>
/// <returns></returns>
public bool CheckDatabaseVersion()
{
try
{
using (var connection = _dataService.CreateConnection())
{
connection.Open();
var versionCommand = connection.CreateCommand();
versionCommand.CommandText = _dataService.GetSqlForGetDatabaseVersion();
var version = (string)versionCommand.ExecuteScalar();
_traceService.Info($"Database version: {version}");
}
return true;
}
catch (Exception ex)
{
_traceService.Error($"Sql/odbc connectivity to database {_connectionInfo.Database} on {_connectionInfo.DataSource} - Failed. Error message: {ex.Message}. " +
$"Suggested action: Check your connection string and verify that the user have sufficient permissions to access the database. " +
$"For sample connection strings, please find your platform at https://www.connectionstrings.com. " +
$"If you think this is a bug, please create an issue ticket here https://github.com/rdagumampan/yuniql/issues.");
return false;
}
}

/// <summary>
/// Checks if we can establish sql/odbc connectivity to database on target server/cluster
/// </summary>
Expand Down Expand Up @@ -157,6 +185,7 @@ public void CheckConnectivity()

CheckMasterConnectivity();
CheckDatabaseConnectivity();
CheckDatabaseVersion();
}
}
}
5 changes: 5 additions & 0 deletions yuniql-extensibility/IDataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ public interface IDataService
/// </summary>
public string GetSqlForUpsertVersion();

/// <summary>
/// Returns the SQL statement to use for getting the database verison.
/// </summary>
public string GetSqlForGetDatabaseVersion();

//TODO: Consider dropping this in next release
/// <summary>
/// Returns true if the version tracking table requires upgrade for this release
Expand Down
6 changes: 6 additions & 0 deletions yuniql-platforms/mysql/MySqlDataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,12 @@ ON DUPLICATE KEY UPDATE
failed_script_error = VALUES(failed_script_error);
";

///<inheritdoc/>
public string GetSqlForGetDatabaseVersion()
=> @"
SELECT VERSION();
";

///<inheritdoc/>
public string GetSqlForCheckRequireMetaSchemaUpgrade(string currentSchemaVersion)
//when table __yuniqldbversion exists, we need to upgrade from yuniql v1.0 to v1.1 version
Expand Down
3 changes: 3 additions & 0 deletions yuniql-platforms/mysql/Yuniql.MySql.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions yuniql-platforms/oracle/OracleDataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,12 @@ public string GetSqlForUpdateVersion()
public string GetSqlForUpsertVersion()
=> throw new NotSupportedException("Not supported in the target platform.");

///<inheritdoc/>
public string GetSqlForGetDatabaseVersion()
=> @"
SELECT version FROM v$instance;
";

///<inheritdoc/>
public string GetSqlForCheckRequireMetaSchemaUpgrade(string currentSchemaVersion)
//when table __yuniqldbversion exists, we need to upgrade from yuniql v1.0 to v1.1 version
Expand Down
3 changes: 3 additions & 0 deletions yuniql-platforms/oracle/Yuniql.Oracle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions yuniql-platforms/postgresql/PostgreSqlDataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,12 @@ public string GetSqlForUpdateVersion()
public string GetSqlForUpsertVersion()
=> throw new NotSupportedException("Not supported for the target platform");

///<inheritdoc/>
public string GetSqlForGetDatabaseVersion()
=> @"
SELECT VERSION();
";

///<inheritdoc/>
public string GetSqlForCheckRequireMetaSchemaUpgrade(string currentSchemaVersion)
//when table __yuniqldbversion exists, we need to upgrade from yuniql v1.0 to v1.1 version
Expand Down
3 changes: 3 additions & 0 deletions yuniql-platforms/postgresql/Yuniql.PostgreSql.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions yuniql-platforms/redshift/RedshiftDataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,12 @@ public string GetSqlForUpdateVersion()
public string GetSqlForUpsertVersion()
=> throw new NotSupportedException("Not supported for the target platform");

///<inheritdoc/>
public string GetSqlForGetDatabaseVersion()
=> @"
SELECT VERSION();
";

///<inheritdoc/>
public string GetSqlForCheckRequireMetaSchemaUpgrade(string currentSchemaVersion)
=> @"
Expand Down
3 changes: 3 additions & 0 deletions yuniql-platforms/redshift/Yuniql.Redshift.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions yuniql-platforms/snowflake/SnowflakeDataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,12 @@ public string GetSqlForUpdateVersion()
public string GetSqlForUpsertVersion()
=> throw new NotSupportedException("Not supported for the target platform");

///<inheritdoc/>
public string GetSqlForGetDatabaseVersion()
=> @"
SELECT CURRENT_VERSION();
";

///<inheritdoc/>
public string GetSqlForCheckRequireMetaSchemaUpgrade(string currentSchemaVersion)
=> @"
Expand Down
3 changes: 3 additions & 0 deletions yuniql-platforms/snowflake/Yuniql.Snowflake.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions yuniql-platforms/sqlserver/SqlServerDataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,12 @@ UPDATE [${YUNIQL_SCHEMA_NAME}].[${YUNIQL_TABLE_NAME}]
public string GetSqlForUpsertVersion()
=> throw new NotSupportedException("Not supported for the target platform");

///<inheritdoc/>
public string GetSqlForGetDatabaseVersion()
=> @"
SELECT @@VERSION;
";

///<inheritdoc/>
public string GetSqlForCheckRequireMetaSchemaUpgrade(string currentSchemaVersion)
//when table __yuniqldbversion exists, we need to upgrade from yuniql v1.0 to v1.1 version
Expand Down
3 changes: 3 additions & 0 deletions yuniql-platforms/sqlserver/Yuniql.SqlServer.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.