public async Task DropSchema(IDbBase dbBase, string schema) { try { await dbBase.ExecuteNonQueryAsync($"drop schema if exists {schema};"); } catch (Exception ex) { await _logsManager.ErrorAsync(new ErrorLogStructure(ex).WithErrorSource()); throw new OutputException( new Exception($"Cannot drop schema {schema}"), StatusCodes.Status500InternalServerError, MnemoxStatusCodes.CANNOT_DROP_SCHEMA); } }
public async Task CreateSchema(IDbBase dbBase, string schemaName) { try { await dbBase.ExecuteNonQueryAsync($"create schema if not exists {schemaName};"); } catch (Exception ex) { await _logsManager.ErrorAsync(new ErrorLogStructure(ex).WithErrorSource()); throw new OutputException( new Exception($"Cannot create schema {schemaName}"), StatusCodes.Status500InternalServerError, MnemoxStatusCodes.CANNOT_CREATE_SCHEMA); } }
public async Task RunNonQuery(IDbBase dbBase, string query) { try { await dbBase.ExecuteNonQueryAsync(query); } catch (Exception ex) { await _logsManager.ErrorAsync(new ErrorLogStructure(ex).WithErrorSource()); throw new OutputException( new Exception($"Cannot run query {query}"), StatusCodes.Status500InternalServerError, MnemoxStatusCodes.CANNOT_CREATE_EXTENSION); } }
public async Task CreateExtension(IDbBase dbBase, string extensionName, string schema) { try { await dbBase.ExecuteNonQueryAsync($"create extension if not exists {extensionName} schema {schema};"); } catch (Exception ex) { if (ex.Message.Contains("has already been loaded with another version")) { throw new OutputException( new Exception($"Cannot create extension {extensionName} in schema {schema}, PostgreSQL service had to be restarted"), StatusCodes.Status500InternalServerError, MnemoxStatusCodes.CANNOT_CREATE_EXTENSION); } await _logsManager.ErrorAsync(new ErrorLogStructure(ex).WithErrorSource()); throw new OutputException( new Exception($"Cannot create extension {extensionName} in schema {schema}"), StatusCodes.Status500InternalServerError, MnemoxStatusCodes.CANNOT_CREATE_EXTENSION); } }