mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-20 14:10:44 +00:00
Merged feature/webhooks into feature/workflows-support
This commit is contained in:
@ -111,7 +111,7 @@ public abstract class AbstractRDBMSAction
|
||||
**
|
||||
** That is, table.backendDetails.tableName if set -- else, table.name
|
||||
*******************************************************************************/
|
||||
protected String getTableName(QTableMetaData table)
|
||||
public static String getTableName(QTableMetaData table)
|
||||
{
|
||||
if(table.getBackendDetails() instanceof RDBMSTableBackendDetails details)
|
||||
{
|
||||
@ -130,7 +130,7 @@ public abstract class AbstractRDBMSAction
|
||||
**
|
||||
** That is, field.backendName if set -- else, field.name
|
||||
*******************************************************************************/
|
||||
protected String getColumnName(QFieldMetaData field)
|
||||
public static String getColumnName(QFieldMetaData field)
|
||||
{
|
||||
if(field.getBackendName() != null)
|
||||
{
|
||||
|
@ -0,0 +1,331 @@
|
||||
/*
|
||||
* QQQ - Low-code Application Framework for Engineers.
|
||||
* Copyright (C) 2021-2025. Kingsrook, LLC
|
||||
* 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States
|
||||
* contact@kingsrook.com
|
||||
* https://github.com/Kingsrook/
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.kingsrook.qqq.backend.module.rdbms.model.metadata;
|
||||
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DatabaseMetaData;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import com.kingsrook.qqq.backend.core.instances.QInstanceEnricher;
|
||||
import com.kingsrook.qqq.backend.core.instances.assessment.QInstanceAssessor;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.fields.QFieldMetaData;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.fields.QFieldType;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableMetaData;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.tables.UniqueKey;
|
||||
import com.kingsrook.qqq.backend.core.utils.CollectionUtils;
|
||||
import com.kingsrook.qqq.backend.core.utils.StringUtils;
|
||||
import com.kingsrook.qqq.backend.module.rdbms.actions.AbstractRDBMSAction;
|
||||
import com.kingsrook.qqq.backend.module.rdbms.jdbc.ConnectionManager;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
public class RDBMSBackendAssessor
|
||||
{
|
||||
private QInstanceAssessor assessor;
|
||||
private RDBMSBackendMetaData backendMetaData;
|
||||
private List<QTableMetaData> tables;
|
||||
|
||||
private Map<String, QFieldType> typeMap = new HashMap<>();
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
public RDBMSBackendAssessor(QInstanceAssessor assessor, RDBMSBackendMetaData backendMetaData, List<QTableMetaData> tables)
|
||||
{
|
||||
this.assessor = assessor;
|
||||
this.backendMetaData = backendMetaData;
|
||||
this.tables = tables;
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// these are types as returned by mysql //
|
||||
// let null in here mean unsupported QQQ type //
|
||||
////////////////////////////////////////////////
|
||||
typeMap.put("TEXT", QFieldType.TEXT);
|
||||
typeMap.put("BINARY", QFieldType.BLOB);
|
||||
typeMap.put("SET", null);
|
||||
typeMap.put("VARBINARY", QFieldType.BLOB);
|
||||
typeMap.put("MEDIUMBLOB", QFieldType.BLOB);
|
||||
typeMap.put("NUMERIC", QFieldType.INTEGER);
|
||||
typeMap.put("BIGINT UNSIGNED", QFieldType.INTEGER);
|
||||
typeMap.put("MEDIUMINT UNSIGNED", QFieldType.INTEGER);
|
||||
typeMap.put("SMALLINT UNSIGNED", QFieldType.INTEGER);
|
||||
typeMap.put("TINYINT UNSIGNED", QFieldType.INTEGER);
|
||||
typeMap.put("BIT", null);
|
||||
typeMap.put("FLOAT", null);
|
||||
typeMap.put("REAL", null);
|
||||
typeMap.put("VARCHAR", QFieldType.STRING);
|
||||
typeMap.put("BOOL", QFieldType.BOOLEAN);
|
||||
typeMap.put("YEAR", null);
|
||||
typeMap.put("TIME", QFieldType.TIME);
|
||||
typeMap.put("TIMESTAMP", QFieldType.DATE_TIME);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
public void assess()
|
||||
{
|
||||
try(Connection connection = new ConnectionManager().getConnection(backendMetaData))
|
||||
{
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// read data type ids (integers) to names, for field-type mapping //
|
||||
////////////////////////////////////////////////////////////////////
|
||||
DatabaseMetaData databaseMetaData;
|
||||
Map<Integer, String> dataTypeMap = new HashMap<>();
|
||||
try
|
||||
{
|
||||
databaseMetaData = connection.getMetaData();
|
||||
ResultSet typeInfoResultSet = databaseMetaData.getTypeInfo();
|
||||
while(typeInfoResultSet.next())
|
||||
{
|
||||
String name = typeInfoResultSet.getString("TYPE_NAME");
|
||||
Integer id = typeInfoResultSet.getInt("DATA_TYPE");
|
||||
dataTypeMap.put(id, name);
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
assessor.addError("Error loading metaData from RDBMS for backendName: " + backendMetaData.getName() + " - assessment cannot be completed.", e);
|
||||
return;
|
||||
}
|
||||
|
||||
///////////////////////////////////////
|
||||
// process each table in the backend //
|
||||
///////////////////////////////////////
|
||||
for(QTableMetaData table : tables)
|
||||
{
|
||||
String tableName = AbstractRDBMSAction.getTableName(table);
|
||||
|
||||
try
|
||||
{
|
||||
///////////////////////////////
|
||||
// check if the table exists //
|
||||
///////////////////////////////
|
||||
String databaseName = backendMetaData.getDatabaseName(); // these work for mysql - unclear about other vendors.
|
||||
String schemaName = null;
|
||||
try(ResultSet tableResultSet = databaseMetaData.getTables(databaseName, schemaName, tableName, null))
|
||||
{
|
||||
if(!tableResultSet.next())
|
||||
{
|
||||
assessor.addError("Table: " + table.getName() + " was not found in backend: " + backendMetaData.getName());
|
||||
assessor.addSuggestion(suggestCreateTable(table));
|
||||
continue;
|
||||
}
|
||||
|
||||
//////////////////////////////
|
||||
// read the table's columns //
|
||||
//////////////////////////////
|
||||
Map<String, QFieldMetaData> columnMap = new HashMap<>();
|
||||
String primaryKeyColumnName = null;
|
||||
try(ResultSet columnsResultSet = databaseMetaData.getColumns(databaseName, schemaName, tableName, null))
|
||||
{
|
||||
while(columnsResultSet.next())
|
||||
{
|
||||
String columnName = columnsResultSet.getString("COLUMN_NAME");
|
||||
String columnSize = columnsResultSet.getString("COLUMN_SIZE");
|
||||
Integer dataTypeId = columnsResultSet.getInt("DATA_TYPE");
|
||||
String isNullable = columnsResultSet.getString("IS_NULLABLE");
|
||||
String isAutoIncrement = columnsResultSet.getString("IS_AUTOINCREMENT");
|
||||
|
||||
String dataTypeName = dataTypeMap.get(dataTypeId);
|
||||
QFieldMetaData columnMetaData = new QFieldMetaData(columnName, typeMap.get(dataTypeName));
|
||||
columnMap.put(columnName, columnMetaData);
|
||||
|
||||
if("YES".equals(isAutoIncrement))
|
||||
{
|
||||
primaryKeyColumnName = columnName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////
|
||||
// diff the columns and fields //
|
||||
/////////////////////////////////
|
||||
for(QFieldMetaData column : columnMap.values())
|
||||
{
|
||||
boolean fieldExists = table.getFields().values().stream().anyMatch(f -> column.getName().equals(AbstractRDBMSAction.getColumnName(f)));
|
||||
if(!fieldExists)
|
||||
{
|
||||
assessor.addWarning("Table: " + table.getName() + " has a column which was not found in the metaData: " + column.getName());
|
||||
assessor.addSuggestion("// in QTableMetaData.withName(\"" + table.getName() + "\")\n"
|
||||
+ ".withField(new QFieldMetaData(\"" + column.getName() + "\", QFieldType." + column.getType() + ").withBackendName(\"" + column.getName() + "\")"); // todo - column_name to fieldName
|
||||
}
|
||||
}
|
||||
|
||||
for(QFieldMetaData field : table.getFields().values())
|
||||
{
|
||||
String columnName = AbstractRDBMSAction.getColumnName(field);
|
||||
boolean columnExists = columnMap.values().stream().anyMatch(c -> c.getName().equals(columnName));
|
||||
if(!columnExists)
|
||||
{
|
||||
assessor.addError("Table: " + table.getName() + " has a field which was not found in the database: " + field.getName());
|
||||
assessor.addSuggestion("/* For table [" + tableName + "] in backend [" + table.getBackendName() + " (database " + databaseName + ")]: */\n"
|
||||
+ "ALTER TABLE " + tableName + " ADD " + QInstanceEnricher.inferBackendName(columnName) + " " + getDatabaseTypeForField(table, field) + ";");
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////
|
||||
// read unique constraints from the database //
|
||||
///////////////////////////////////////////////
|
||||
Map<String, Set<String>> uniqueIndexMap = new HashMap<>();
|
||||
try(ResultSet indexInfoResultSet = databaseMetaData.getIndexInfo(databaseName, schemaName, tableName, true, true))
|
||||
{
|
||||
while(indexInfoResultSet.next())
|
||||
{
|
||||
String indexName = indexInfoResultSet.getString("INDEX_NAME");
|
||||
String columnName = indexInfoResultSet.getString("COLUMN_NAME");
|
||||
uniqueIndexMap.computeIfAbsent(indexName, k -> new HashSet<>());
|
||||
uniqueIndexMap.get(indexName).add(columnName);
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////
|
||||
// diff the unique keys //
|
||||
//////////////////////////
|
||||
for(UniqueKey uniqueKey : CollectionUtils.nonNullList(table.getUniqueKeys()))
|
||||
{
|
||||
Set<String> fieldNames = uniqueKey.getFieldNames().stream().map(fieldName -> AbstractRDBMSAction.getColumnName(table.getField(fieldName))).collect(Collectors.toSet());
|
||||
if(!uniqueIndexMap.containsValue(fieldNames))
|
||||
{
|
||||
assessor.addWarning("Table: " + table.getName() + " specifies a uniqueKey which was not found in the database: " + uniqueKey.getFieldNames());
|
||||
assessor.addSuggestion("/* For table [" + tableName + "] in backend [" + table.getBackendName() + " (database " + databaseName + ")]: */\n"
|
||||
+ "ALTER TABLE " + tableName + " ADD UNIQUE (" + StringUtils.join(", ", fieldNames) + ");");
|
||||
}
|
||||
}
|
||||
|
||||
for(Set<String> uniqueIndex : uniqueIndexMap.values())
|
||||
{
|
||||
//////////////////////////
|
||||
// skip the primary key //
|
||||
//////////////////////////
|
||||
if(uniqueIndex.size() == 1 && uniqueIndex.contains(primaryKeyColumnName))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
boolean foundInTableMetaData = false;
|
||||
for(UniqueKey uniqueKey : CollectionUtils.nonNullList(table.getUniqueKeys()))
|
||||
{
|
||||
Set<String> fieldNames = uniqueKey.getFieldNames().stream().map(fieldName -> AbstractRDBMSAction.getColumnName(table.getField(fieldName))).collect(Collectors.toSet());
|
||||
if(uniqueIndex.equals(fieldNames))
|
||||
{
|
||||
foundInTableMetaData = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!foundInTableMetaData)
|
||||
{
|
||||
assessor.addWarning("Table: " + table.getName() + " has a unique index which was not found in the metaData: " + uniqueIndex);
|
||||
assessor.addSuggestion("// in QTableMetaData.withName(\"" + table.getName() + "\")\n"
|
||||
+ ".withUniqueKey(new UniqueKey(\"" + StringUtils.join("\", \"", uniqueIndex) + "\"))");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
assessor.addError("Error assessing table: " + table.getName() + " in backend: " + backendMetaData.getName(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
assessor.addError("Error connecting to RDBMS for backendName: " + backendMetaData.getName(), e);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
private String suggestCreateTable(QTableMetaData table)
|
||||
{
|
||||
StringBuilder rs = new StringBuilder("/* For table [" + table.getName() + "] in backend [" + table.getBackendName() + " (database " + (backendMetaData.getDatabaseName()) + ")]: */\n");
|
||||
rs.append("CREATE TABLE ").append(AbstractRDBMSAction.getTableName(table)).append("\n");
|
||||
rs.append("(\n");
|
||||
|
||||
List<String> fields = new ArrayList<>();
|
||||
for(QFieldMetaData field : table.getFields().values())
|
||||
{
|
||||
fields.add(" " + AbstractRDBMSAction.getColumnName(field) + " " + getDatabaseTypeForField(table, field));
|
||||
}
|
||||
|
||||
rs.append(StringUtils.join(",\n", fields));
|
||||
|
||||
rs.append("\n);");
|
||||
return (rs.toString());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
private String getDatabaseTypeForField(QTableMetaData table, QFieldMetaData field)
|
||||
{
|
||||
return switch(field.getType())
|
||||
{
|
||||
case STRING ->
|
||||
{
|
||||
int n = Objects.requireNonNullElse(field.getMaxLength(), 250);
|
||||
yield ("VARCHAR(" + n + ")");
|
||||
}
|
||||
case INTEGER ->
|
||||
{
|
||||
String suffix = table.getPrimaryKeyField().equals(field.getName()) ? " AUTO_INCREMENT PRIMARY KEY" : "";
|
||||
yield ("INTEGER" + suffix);
|
||||
}
|
||||
case LONG ->
|
||||
{
|
||||
String suffix = table.getPrimaryKeyField().equals(field.getName()) ? " AUTO_INCREMENT PRIMARY KEY" : "";
|
||||
yield ("BIGINT" + suffix);
|
||||
}
|
||||
case DECIMAL -> "DECIMAL(10,2)";
|
||||
case BOOLEAN -> "BOOLEAN";
|
||||
case DATE -> "DATE";
|
||||
case TIME -> "TIME";
|
||||
case DATE_TIME -> "TIMESTAMP";
|
||||
case TEXT -> "TEXT";
|
||||
case HTML -> "TEXT";
|
||||
case PASSWORD -> "VARCHAR(40)";
|
||||
case BLOB -> "BLOB";
|
||||
};
|
||||
}
|
||||
}
|
@ -22,12 +22,18 @@
|
||||
package com.kingsrook.qqq.backend.module.rdbms.model.metadata;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.kingsrook.qqq.backend.core.actions.customizers.QCodeLoader;
|
||||
import com.kingsrook.qqq.backend.core.instances.QMetaDataVariableInterpreter;
|
||||
import com.kingsrook.qqq.backend.core.instances.assessment.Assessable;
|
||||
import com.kingsrook.qqq.backend.core.instances.assessment.QInstanceAssessor;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.QBackendMetaData;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.code.QCodeReference;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableMetaData;
|
||||
import com.kingsrook.qqq.backend.module.rdbms.RDBMSBackendModule;
|
||||
import com.kingsrook.qqq.backend.module.rdbms.strategy.BaseRDBMSActionStrategy;
|
||||
import com.kingsrook.qqq.backend.module.rdbms.strategy.RDBMSActionStrategyInterface;
|
||||
@ -36,7 +42,7 @@ import com.kingsrook.qqq.backend.module.rdbms.strategy.RDBMSActionStrategyInterf
|
||||
/*******************************************************************************
|
||||
** Meta-data to provide details of an RDBMS backend (e.g., connection params)
|
||||
*******************************************************************************/
|
||||
public class RDBMSBackendMetaData extends QBackendMetaData
|
||||
public class RDBMSBackendMetaData extends QBackendMetaData implements Assessable
|
||||
{
|
||||
private String vendor;
|
||||
private String hostName;
|
||||
@ -580,4 +586,25 @@ public class RDBMSBackendMetaData extends QBackendMetaData
|
||||
}
|
||||
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
**
|
||||
***************************************************************************/
|
||||
@Override
|
||||
public void assess(QInstanceAssessor qInstanceAssessor, QInstance qInstance)
|
||||
{
|
||||
List<QTableMetaData> tables = new ArrayList<>();
|
||||
for(QTableMetaData table : qInstance.getTables().values())
|
||||
{
|
||||
if(Objects.equals(getName(), table.getBackendName()))
|
||||
{
|
||||
tables.add(table);
|
||||
}
|
||||
}
|
||||
|
||||
if(!tables.isEmpty())
|
||||
{
|
||||
new RDBMSBackendAssessor(qInstanceAssessor, this, tables).assess();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -101,12 +101,6 @@ public class RDBMSTableMetaDataBuilder
|
||||
String schemaName = null;
|
||||
String tableNameForMetaDataQueries = tableName;
|
||||
|
||||
if(backendMetaData.getVendor().equals("h2"))
|
||||
{
|
||||
databaseName = databaseName.toUpperCase();
|
||||
tableNameForMetaDataQueries = tableName.toUpperCase();
|
||||
}
|
||||
|
||||
try(ResultSet tableResultSet = databaseMetaData.getTables(databaseName, schemaName, tableNameForMetaDataQueries, null))
|
||||
{
|
||||
if(!tableResultSet.next())
|
||||
|
@ -153,12 +153,22 @@ public class TestUtils
|
||||
*******************************************************************************/
|
||||
public static RDBMSBackendMetaData defineBackend()
|
||||
{
|
||||
return (new RDBMSBackendMetaData()
|
||||
RDBMSBackendMetaData rdbmsBackendMetaData = new RDBMSBackendMetaData()
|
||||
.withName(DEFAULT_BACKEND_NAME)
|
||||
.withVendor("h2")
|
||||
.withHostName("mem")
|
||||
.withDatabaseName("test_database")
|
||||
.withUsername("sa"));
|
||||
.withUsername("sa");
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// by default h2 up-shifts all names, which isn't how we expected //
|
||||
// things to be, so, tell it not to do that. //
|
||||
////////////////////////////////////////////////////////////////////
|
||||
String jdbcUrl = ConnectionManager.getJdbcUrl(rdbmsBackendMetaData);
|
||||
jdbcUrl += ";DATABASE_TO_UPPER=FALSE";
|
||||
rdbmsBackendMetaData.setJdbcUrl(jdbcUrl);
|
||||
|
||||
return rdbmsBackendMetaData;
|
||||
}
|
||||
|
||||
|
||||
|
@ -438,8 +438,8 @@ class QueryManagerTest extends BaseTest
|
||||
""");
|
||||
List<Map<String, Object>> rows = QueryManager.executeStatementForRows(connection, "SELECT * FROM test_table");
|
||||
assertNotNull(rows);
|
||||
assertEquals(47, rows.get(0).get("INT_COL"));
|
||||
assertEquals("Q", rows.get(0).get("CHAR_COL"));
|
||||
assertEquals(47, rows.get(0).get("int_col"));
|
||||
assertEquals("Q", rows.get(0).get("char_col"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,117 @@
|
||||
/*
|
||||
* QQQ - Low-code Application Framework for Engineers.
|
||||
* Copyright (C) 2021-2025. Kingsrook, LLC
|
||||
* 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States
|
||||
* contact@kingsrook.com
|
||||
* https://github.com/Kingsrook/
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.kingsrook.qqq.backend.module.rdbms.model.metadata;
|
||||
|
||||
|
||||
import java.sql.Connection;
|
||||
import com.kingsrook.qqq.backend.core.context.QContext;
|
||||
import com.kingsrook.qqq.backend.core.instances.assessment.QInstanceAssessor;
|
||||
import com.kingsrook.qqq.backend.core.logging.QLogger;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.fields.QFieldMetaData;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.fields.QFieldType;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.tables.UniqueKey;
|
||||
import com.kingsrook.qqq.backend.module.rdbms.BaseTest;
|
||||
import com.kingsrook.qqq.backend.module.rdbms.TestUtils;
|
||||
import com.kingsrook.qqq.backend.module.rdbms.jdbc.ConnectionManager;
|
||||
import com.kingsrook.qqq.backend.module.rdbms.jdbc.QueryManager;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Unit test for RDBMSBackendAssessor
|
||||
*******************************************************************************/
|
||||
class RDBMSBackendAssessorTest extends BaseTest
|
||||
{
|
||||
private static final QLogger LOG = QLogger.getLogger(RDBMSBackendAssessorTest.class);
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void testSuccess() throws Exception
|
||||
{
|
||||
TestUtils.primeTestDatabase("prime-test-database.sql");
|
||||
QInstanceAssessor assessor = new QInstanceAssessor(QContext.getQInstance());
|
||||
assessor.assess();
|
||||
System.out.println(assessor.getSummary());
|
||||
assertEquals(0, assessor.getErrors().size());
|
||||
assertEquals(0, assessor.getWarnings().size());
|
||||
assertEquals(0, assessor.getExitCode());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void testTableIssues() throws Exception
|
||||
{
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// start from primed database, but make a few alters to it and the meta-data //
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
TestUtils.primeTestDatabase("prime-test-database.sql");
|
||||
ConnectionManager connectionManager = new ConnectionManager();
|
||||
try(Connection connection = connectionManager.getConnection(TestUtils.defineBackend()))
|
||||
{
|
||||
QueryManager.executeUpdate(connection, "ALTER TABLE person ADD COLUMN suffix VARCHAR(20)");
|
||||
QueryManager.executeUpdate(connection, "ALTER TABLE person ADD UNIQUE u_name (first_name, last_name)");
|
||||
}
|
||||
|
||||
QContext.getQInstance().getTable(TestUtils.TABLE_NAME_PERSON)
|
||||
.withField(new QFieldMetaData("middleName", QFieldType.STRING))
|
||||
.withUniqueKey(new UniqueKey("firstName", "middleName", "lastName"));
|
||||
|
||||
///////////////////////////
|
||||
// un-prime the database //
|
||||
///////////////////////////
|
||||
QInstanceAssessor assessor = new QInstanceAssessor(QContext.getQInstance());
|
||||
assessor.assess();
|
||||
LOG.info(assessor.getSummary());
|
||||
assertNotEquals(0, assessor.getErrors().size());
|
||||
assertNotEquals(0, assessor.getExitCode());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void testTotalFailure() throws Exception
|
||||
{
|
||||
///////////////////////////
|
||||
// un-prime the database //
|
||||
///////////////////////////
|
||||
TestUtils.primeTestDatabase("drop-test-database.sql");
|
||||
QInstanceAssessor assessor = new QInstanceAssessor(QContext.getQInstance());
|
||||
assessor.assess();
|
||||
System.out.println(assessor.getSummary());
|
||||
assertNotEquals(0, assessor.getErrors().size());
|
||||
assertNotEquals(0, assessor.getExitCode());
|
||||
}
|
||||
|
||||
}
|
@ -122,6 +122,7 @@ public class SharingMetaDataProvider
|
||||
qInstance.addTable(new QTableMetaData()
|
||||
.withName(User.TABLE_NAME)
|
||||
.withPrimaryKeyField("id")
|
||||
.withBackendDetails(new RDBMSTableBackendDetails().withTableName("user"))
|
||||
.withBackendName(TestUtils.DEFAULT_BACKEND_NAME)
|
||||
.withFieldsFromEntity(User.class)
|
||||
.withRecordSecurityLock(new RecordSecurityLock()
|
||||
@ -132,6 +133,7 @@ public class SharingMetaDataProvider
|
||||
qInstance.addTable(new QTableMetaData()
|
||||
.withName(Group.TABLE_NAME)
|
||||
.withPrimaryKeyField("id")
|
||||
.withBackendDetails(new RDBMSTableBackendDetails().withTableName("group"))
|
||||
.withBackendName(TestUtils.DEFAULT_BACKEND_NAME)
|
||||
.withFieldsFromEntity(Group.class));
|
||||
QInstanceEnricher.setInferredFieldBackendNames(qInstance.getTable(Group.TABLE_NAME));
|
||||
@ -139,6 +141,7 @@ public class SharingMetaDataProvider
|
||||
qInstance.addTable(new QTableMetaData()
|
||||
.withName(Client.TABLE_NAME)
|
||||
.withPrimaryKeyField("id")
|
||||
.withBackendDetails(new RDBMSTableBackendDetails().withTableName("client"))
|
||||
.withBackendName(TestUtils.DEFAULT_BACKEND_NAME)
|
||||
.withFieldsFromEntity(Client.class));
|
||||
QInstanceEnricher.setInferredFieldBackendNames(qInstance.getTable(Client.TABLE_NAME));
|
||||
|
@ -0,0 +1,32 @@
|
||||
--
|
||||
-- QQQ - Low-code Application Framework for Engineers.
|
||||
-- Copyright (C) 2021-2022. Kingsrook, LLC
|
||||
-- 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States
|
||||
-- contact@kingsrook.com
|
||||
-- https://github.com/Kingsrook/
|
||||
--
|
||||
-- This program is free software: you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU Affero General Public License as
|
||||
-- published by the Free Software Foundation, either version 3 of the
|
||||
-- License, or (at your option) any later version.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU Affero General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU Affero General Public License
|
||||
-- along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS person;
|
||||
DROP TABLE IF EXISTS personal_id_card;
|
||||
DROP TABLE IF EXISTS carrier;
|
||||
DROP TABLE IF EXISTS line_item_extrinsic;
|
||||
DROP TABLE IF EXISTS order_line;
|
||||
DROP TABLE IF EXISTS item;
|
||||
DROP TABLE IF EXISTS `order`;
|
||||
DROP TABLE IF EXISTS order_instructions;
|
||||
DROP TABLE IF EXISTS warehouse_store_int;
|
||||
DROP TABLE IF EXISTS store;
|
||||
DROP TABLE IF EXISTS warehouse;
|
Reference in New Issue
Block a user