diff --git a/yuniql-core/ConnectivityService.cs b/yuniql-core/ConnectivityService.cs index 68ace97..8698255 100644 --- a/yuniql-core/ConnectivityService.cs +++ b/yuniql-core/ConnectivityService.cs @@ -24,6 +24,34 @@ public ConnectivityService(IDataService dataService, ITraceService traceService) this._connectionInfo = _dataService.GetConnectionInfo(); } + /// + /// Checks the database server informations + /// + /// + 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; + } + } + /// /// Checks if we can establish sql/odbc connectivity to database on target server/cluster /// @@ -157,6 +185,7 @@ public void CheckConnectivity() CheckMasterConnectivity(); CheckDatabaseConnectivity(); + CheckDatabaseVersion(); } } } diff --git a/yuniql-extensibility/IDataService.cs b/yuniql-extensibility/IDataService.cs index 09adca6..8d4a681 100644 --- a/yuniql-extensibility/IDataService.cs +++ b/yuniql-extensibility/IDataService.cs @@ -150,6 +150,11 @@ public interface IDataService /// public string GetSqlForUpsertVersion(); + /// + /// Returns the SQL statement to use for getting the database verison. + /// + public string GetSqlForGetDatabaseVersion(); + //TODO: Consider dropping this in next release /// /// Returns true if the version tracking table requires upgrade for this release diff --git a/yuniql-platforms/mysql/MySqlDataService.cs b/yuniql-platforms/mysql/MySqlDataService.cs index 054dd2c..2203671 100644 --- a/yuniql-platforms/mysql/MySqlDataService.cs +++ b/yuniql-platforms/mysql/MySqlDataService.cs @@ -186,6 +186,12 @@ ON DUPLICATE KEY UPDATE failed_script_error = VALUES(failed_script_error); "; + /// + public string GetSqlForGetDatabaseVersion() + => @" +SELECT VERSION(); + "; + /// public string GetSqlForCheckRequireMetaSchemaUpgrade(string currentSchemaVersion) //when table __yuniqldbversion exists, we need to upgrade from yuniql v1.0 to v1.1 version diff --git a/yuniql-platforms/mysql/Yuniql.MySql.xml b/yuniql-platforms/mysql/Yuniql.MySql.xml index 2aeedb7..d4ad9a9 100644 --- a/yuniql-platforms/mysql/Yuniql.MySql.xml +++ b/yuniql-platforms/mysql/Yuniql.MySql.xml @@ -97,6 +97,9 @@ + + + diff --git a/yuniql-platforms/oracle/OracleDataService.cs b/yuniql-platforms/oracle/OracleDataService.cs index 50a9ab4..4ea674f 100644 --- a/yuniql-platforms/oracle/OracleDataService.cs +++ b/yuniql-platforms/oracle/OracleDataService.cs @@ -231,6 +231,12 @@ public string GetSqlForUpdateVersion() public string GetSqlForUpsertVersion() => throw new NotSupportedException("Not supported in the target platform."); + /// + public string GetSqlForGetDatabaseVersion() + => @" +SELECT version FROM v$instance; + "; + /// public string GetSqlForCheckRequireMetaSchemaUpgrade(string currentSchemaVersion) //when table __yuniqldbversion exists, we need to upgrade from yuniql v1.0 to v1.1 version diff --git a/yuniql-platforms/oracle/Yuniql.Oracle.xml b/yuniql-platforms/oracle/Yuniql.Oracle.xml index 5a011e0..0c5decf 100644 --- a/yuniql-platforms/oracle/Yuniql.Oracle.xml +++ b/yuniql-platforms/oracle/Yuniql.Oracle.xml @@ -114,6 +114,9 @@ + + + diff --git a/yuniql-platforms/postgresql/PostgreSqlDataService.cs b/yuniql-platforms/postgresql/PostgreSqlDataService.cs index 910f08d..0424611 100644 --- a/yuniql-platforms/postgresql/PostgreSqlDataService.cs +++ b/yuniql-platforms/postgresql/PostgreSqlDataService.cs @@ -190,6 +190,12 @@ public string GetSqlForUpdateVersion() public string GetSqlForUpsertVersion() => throw new NotSupportedException("Not supported for the target platform"); + /// + public string GetSqlForGetDatabaseVersion() + => @" +SELECT VERSION(); + "; + /// public string GetSqlForCheckRequireMetaSchemaUpgrade(string currentSchemaVersion) //when table __yuniqldbversion exists, we need to upgrade from yuniql v1.0 to v1.1 version diff --git a/yuniql-platforms/postgresql/Yuniql.PostgreSql.xml b/yuniql-platforms/postgresql/Yuniql.PostgreSql.xml index fa54edb..a48e5a0 100644 --- a/yuniql-platforms/postgresql/Yuniql.PostgreSql.xml +++ b/yuniql-platforms/postgresql/Yuniql.PostgreSql.xml @@ -97,6 +97,9 @@ + + + diff --git a/yuniql-platforms/redshift/RedshiftDataService.cs b/yuniql-platforms/redshift/RedshiftDataService.cs index a70df60..5d2b68a 100644 --- a/yuniql-platforms/redshift/RedshiftDataService.cs +++ b/yuniql-platforms/redshift/RedshiftDataService.cs @@ -192,6 +192,12 @@ public string GetSqlForUpdateVersion() public string GetSqlForUpsertVersion() => throw new NotSupportedException("Not supported for the target platform"); + /// + public string GetSqlForGetDatabaseVersion() + => @" +SELECT VERSION(); + "; + /// public string GetSqlForCheckRequireMetaSchemaUpgrade(string currentSchemaVersion) => @" diff --git a/yuniql-platforms/redshift/Yuniql.Redshift.xml b/yuniql-platforms/redshift/Yuniql.Redshift.xml index 4575e84..6dcb95c 100644 --- a/yuniql-platforms/redshift/Yuniql.Redshift.xml +++ b/yuniql-platforms/redshift/Yuniql.Redshift.xml @@ -85,6 +85,9 @@ + + + diff --git a/yuniql-platforms/snowflake/SnowflakeDataService.cs b/yuniql-platforms/snowflake/SnowflakeDataService.cs index 5ed1227..a0cf207 100644 --- a/yuniql-platforms/snowflake/SnowflakeDataService.cs +++ b/yuniql-platforms/snowflake/SnowflakeDataService.cs @@ -225,6 +225,12 @@ public string GetSqlForUpdateVersion() public string GetSqlForUpsertVersion() => throw new NotSupportedException("Not supported for the target platform"); + /// + public string GetSqlForGetDatabaseVersion() + => @" +SELECT CURRENT_VERSION(); + "; + /// public string GetSqlForCheckRequireMetaSchemaUpgrade(string currentSchemaVersion) => @" diff --git a/yuniql-platforms/snowflake/Yuniql.Snowflake.xml b/yuniql-platforms/snowflake/Yuniql.Snowflake.xml index e0c1508..a8fe9ba 100644 --- a/yuniql-platforms/snowflake/Yuniql.Snowflake.xml +++ b/yuniql-platforms/snowflake/Yuniql.Snowflake.xml @@ -85,6 +85,9 @@ + + + diff --git a/yuniql-platforms/sqlserver/SqlServerDataService.cs b/yuniql-platforms/sqlserver/SqlServerDataService.cs index f0a020f..540d643 100644 --- a/yuniql-platforms/sqlserver/SqlServerDataService.cs +++ b/yuniql-platforms/sqlserver/SqlServerDataService.cs @@ -187,6 +187,12 @@ UPDATE [${YUNIQL_SCHEMA_NAME}].[${YUNIQL_TABLE_NAME}] public string GetSqlForUpsertVersion() => throw new NotSupportedException("Not supported for the target platform"); + /// + public string GetSqlForGetDatabaseVersion() + => @" +SELECT @@VERSION; + "; + /// public string GetSqlForCheckRequireMetaSchemaUpgrade(string currentSchemaVersion) //when table __yuniqldbversion exists, we need to upgrade from yuniql v1.0 to v1.1 version diff --git a/yuniql-platforms/sqlserver/Yuniql.SqlServer.xml b/yuniql-platforms/sqlserver/Yuniql.SqlServer.xml index b9ddcf9..c966f2d 100644 --- a/yuniql-platforms/sqlserver/Yuniql.SqlServer.xml +++ b/yuniql-platforms/sqlserver/Yuniql.SqlServer.xml @@ -97,6 +97,9 @@ + + +