use of org.molgenis.emx2.SchemaMetadata in project molgenis-emx2 by molgenis.
the class TestGetSetAllTypesOnRows method addContents.
private void addContents(SchemaMetadata m, List<ColumnType> columnTypes) {
TableMetadata t = m.create(table("TypeTest"));
for (ColumnType columnType : columnTypes) {
t.add(column("test" + columnType).setType(columnType).setRequired(true));
t.add(column("test" + columnType + "_nullable").setType(columnType));
t.add(column("test" + columnType + "_readonly").setType(columnType).setReadonly(true));
}
}
use of org.molgenis.emx2.SchemaMetadata in project molgenis-emx2 by molgenis.
the class TestMergeDrop method testDrop.
@Test
public void testDrop() {
SchemaMetadata newSchema = new SchemaMetadata();
newSchema.create(table("Person", column("name")));
schema.migrate(newSchema);
// idempotent
schema.migrate(newSchema);
assertNotNull(schema.getTable("Person"));
newSchema = new SchemaMetadata();
newSchema.create(table("Person"));
newSchema.getTableMetadata("Person").drop();
schema.migrate(newSchema);
// should be idempotent
schema.migrate(newSchema);
assertNull(schema.getTable("Person"));
// now more complex, with dependency
newSchema = new SchemaMetadata();
newSchema.create(table("Person", column("name").setPkey()));
newSchema.create(table("Pet", column("name").setPkey(), column("owner").setType(ColumnType.REF).setRefTable("Person")));
schema.migrate(newSchema);
// should be idempotent so repeat
schema.migrate(newSchema);
assertNotNull(schema.getTable("Person"));
assertNotNull(schema.getTable("Pet"));
schema.getTable("Person").insert(row("name", "Donald"));
schema.getTable("Pet").insert(row("name", "Pluto", "owner", "Donald"));
// should fail
newSchema = new SchemaMetadata();
try {
newSchema.create(table("Person"));
newSchema.getTableMetadata("Person").drop();
schema.migrate(newSchema);
fail("should fail because of foreign key");
} catch (Exception e) {
// fine
}
// should succeed
newSchema.create(table("Pet"));
newSchema.getTableMetadata("Pet").drop();
schema.migrate(newSchema);
// should be idempotent so repeat
schema.migrate(newSchema);
assertNull(schema.getTable("Person"));
assertNull(schema.getTable("Pet"));
}
use of org.molgenis.emx2.SchemaMetadata in project molgenis-emx2 by molgenis.
the class RefAndRefArrayTestExample method createRefAndRefArrayTestExample.
public static void createRefAndRefArrayTestExample(SchemaMetadata schema) {
ColumnType[] columnTypes = new ColumnType[] { UUID, STRING, BOOL, INT, DECIMAL, TEXT, DATE, DATETIME };
for (ColumnType columnType : columnTypes) {
String aTableName = columnType.toString() + "_A";
String fieldName = "AKeyOf" + columnType;
schema.create(table(aTableName).add(column(fieldName).setType(columnType).setPkey()));
String bTableName = columnType.toString() + "_B";
String refFromBToA = "RefToAKeyOf" + columnType;
String refArrayFromBToA = "RefArrayToAKeyOf" + columnType;
schema.create(table(bTableName).add(column(refFromBToA).setType(REF).setRefTable(aTableName)).add(column(refArrayFromBToA).setType(REF_ARRAY).setRefTable(aTableName)));
}
}
use of org.molgenis.emx2.SchemaMetadata in project molgenis-emx2 by molgenis.
the class SimpleTypeTestExample method createSimpleTypeTest.
public static void createSimpleTypeTest(SchemaMetadata schema) {
TableMetadata typeTestTable = table(TYPE_TEST).add(column("id").setPkey());
ColumnType[] columnTypes = new ColumnType[] { UUID, STRING, BOOL, INT, LONG, DECIMAL, TEXT, DATE, DATETIME };
for (ColumnType columnType : columnTypes) {
typeTestTable.add(column("Test " + columnType.toString().toLowerCase()).setType(columnType).setRequired(true));
typeTestTable.add(column("Test " + columnType.toString().toLowerCase() + " nillable").setType(columnType));
}
schema.create(typeTestTable);
}
use of org.molgenis.emx2.SchemaMetadata in project molgenis-emx2 by molgenis.
the class GraphqlSchemaFieldFactory method changeTables.
private void changeTables(Schema schema, DataFetchingEnvironment dataFetchingEnvironment) throws IOException {
Object tables = dataFetchingEnvironment.getArgument(GraphqlConstants.TABLES);
// tables
if (tables != null) {
Map tableMap = Map.of("tables", tables);
String json = JsonUtil.getWriter().writeValueAsString(tableMap);
SchemaMetadata otherSchema = jsonToSchema(json);
schema.migrate(otherSchema);
}
}
Aggregations