Skip to content

Commit

Permalink
fix(central): schema names with - should be allowed (#4391)
Browse files Browse the repository at this point in the history
  • Loading branch information
mswertz authored Oct 29, 2024
1 parent 90565b5 commit 282d6d1
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 14 deletions.
4 changes: 2 additions & 2 deletions apps/central/src/components/SchemaCreateModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export default {
},
methods: {
validate(name) {
const simpleName = constants.TABLE_NAME_REGEX;
const simpleName = constants.SCHEMA_NAME_REGEX;
if (name === null) {
return undefined;
}
Expand All @@ -179,7 +179,7 @@ export default {
) {
return undefined;
} else {
return "Table name must start with a letter, followed by zero or more letters, numbers, spaces or underscores. A space immediately before or after an underscore is not allowed. The character limit is 31.";
return "Table name must start with a letter, followed by zero or more letters, numbers, spaces, dash or underscores. A space immediately before or after an underscore is not allowed. The character limit is 31.";
}
},
executeCreateSchema() {
Expand Down
1 change: 1 addition & 0 deletions apps/molgenis-components/src/components/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export default {
CODE_9: 57,
CODE_PERIOD: 46,
CODE_MINUS: 45,
SCHEMA_NAME_REGEX: /^(?!.* _|.*_ )[a-zA-Z][-a-zA-Z0-9 _]{0,62}$/,
TABLE_NAME_REGEX: /^(?!.* _|.*_ )[a-zA-Z][a-zA-Z0-9 _]{0,30}$/,
COLUMN_NAME_REGEX: /^(?!.* _|.*_ )[a-zA-Z][a-zA-Z0-9 _]{0,62}$/,
EMAIL_REGEX:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,49 +24,51 @@ public class TestImportExportAllExamples {

static Database db;

static String prefix = TestImportExportAllExamples.class.getSimpleName();

@BeforeAll
public static void setup() {
db = TestDatabaseFactory.getTestDatabase();
}

@Test
public void testArrayTypeTestExample() throws IOException {
SchemaMetadata schema1 = new SchemaMetadata("1");
SchemaMetadata schema1 = new SchemaMetadata(prefix + "1");
ArrayTypeTestExample.createSimpleTypeTest(schema1);
executeCompare(schema1);
}

@Test
public void testRefAndRefArrayExample() throws IOException {
SchemaMetadata schema1 = new SchemaMetadata("4");
SchemaMetadata schema1 = new SchemaMetadata(prefix + "4");
RefAndRefArrayTestExample.createRefAndRefArrayTestExample(schema1);
executeCompare(schema1);
}

@Test
public void testSimpleTypeTestExample() throws IOException {
SchemaMetadata schema1 = new SchemaMetadata("5");
SchemaMetadata schema1 = new SchemaMetadata(prefix + "5");
SimpleTypeTestExample.createSimpleTypeTest(schema1);
executeCompare(schema1);
}

@Test
public void testProductComponentPartsExample() throws IOException {
SchemaMetadata schema1 = new SchemaMetadata("6");
SchemaMetadata schema1 = new SchemaMetadata(prefix + "6");
ProductComponentPartsExample.create(schema1);
executeCompare(schema1);
}

@Test
public void testPetStoreExample() throws IOException {
SchemaMetadata schema1 = new SchemaMetadata("7");
SchemaMetadata schema1 = new SchemaMetadata(prefix + "7");
schema1.create(PetStoreLoader.getSchemaMetadata().getTables().toArray(new TableMetadata[0]));
executeCompare(schema1);
}

@Test
public void testDefaultValuesMetadata() throws IOException {
SchemaMetadata schema1 = new SchemaMetadata("8");
SchemaMetadata schema1 = new SchemaMetadata(prefix + "8");
schema1.create(table("test", column("id").setDefaultValue("bla")));
Schema result = executeCompare(schema1);
assertEquals(
Expand All @@ -85,7 +87,7 @@ public Schema executeCompare(SchemaMetadata schema1) throws IOException, Molgeni

CompareTools.assertEquals(schema1, schema2);

Schema schema3 = db.dropCreateSchema(getClass().getSimpleName() + schema1.getName());
Schema schema3 = db.dropCreateSchema(schema1.getName() + "_copy");
schema3.migrate(schema2);
return schema3;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

public class TestSchemaCreateDestroy {
private static Database db;
private static final String name = TestSchemaCreateDestroy.class.getName() + "Desc";
private static final String name = TestSchemaCreateDestroy.class.getSimpleName() + "Desc";

@BeforeAll
public static void setUp() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@ public class TestSchemaUpdate {
@BeforeAll
public static void setUp() {
db = TestDatabaseFactory.getTestDatabase();
db.dropCreateSchema(TestSchemaUpdate.class.getName(), desc);
db.dropCreateSchema(TestSchemaUpdate.class.getSimpleName(), desc);
}

@Test
public void testUpdateDescription() {
String descUpdate = "update me";
db.updateSchema(TestSchemaUpdate.class.getName(), descUpdate);
db.updateSchema(TestSchemaUpdate.class.getSimpleName(), descUpdate);
assertTrue(
db.getSchemaInfo(TestSchemaUpdate.class.getName()).description().contains(descUpdate));
assertFalse(db.getSchemaInfo(TestSchemaUpdate.class.getName()).description().contains(desc));
db.getSchemaInfo(TestSchemaUpdate.class.getSimpleName())
.description()
.contains(descUpdate));
assertFalse(
db.getSchemaInfo(TestSchemaUpdate.class.getSimpleName()).description().contains(desc));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ public class Constants {
};
protected static final Operator[] EQUALITY_OPERATORS = {EQUALS, NOT_EQUALS};

// n.b. we allow _SYSTEM_
protected static final String SCHEMA_NAME_REGEX = "^(?!.* _|.*_ )[a-zA-Z][-a-zA-Z0-9 _]{0,62}$";

protected static final String TABLE_NAME_REGEX = "^(?!.* _|.*_ )[a-zA-Z][a-zA-Z0-9 _]{0,30}$";

protected static final String COLUMN_NAME_REGEX = "^(?!.* _|.*_ )[a-zA-Z][a-zA-Z0-9 _]{0,62}$";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static org.molgenis.emx2.Constants.OIDC_CALLBACK_PATH;
import static org.molgenis.emx2.Constants.OIDC_LOGIN_PATH;
import static org.molgenis.emx2.TableMetadata.SCHEMA_NAME_MESSAGE;
import static org.molgenis.emx2.utils.TypeUtils.convertToPascalCase;

import java.util.*;
Expand Down Expand Up @@ -42,6 +43,10 @@ public SchemaMetadata(Database db, SchemaMetadata schema) {
}

private void validateSchemaName(String name) {
// we only allow _SYSTEM_
if (!name.matches(Constants.SCHEMA_NAME_REGEX) && !name.equals("_SYSTEM_")) {
throw new MolgenisException("Invalid schema name '" + name + SCHEMA_NAME_MESSAGE);
}
if (name == null || name.isEmpty())
throw new MolgenisException("Create schema failed: Schema name was null or empty");
if (name.equalsIgnoreCase(OIDC_LOGIN_PATH) || name.equalsIgnoreCase(OIDC_CALLBACK_PATH))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public class TableMetadata extends HasLabelsDescriptionsAndSettings<TableMetadat

public static final String TABLE_NAME_MESSAGE =
": Table name must start with a letter, followed by zero or more letters, numbers, spaces or underscores. A space immediately before or after an underscore is not allowed. The character limit is 31.";
public static final String SCHEMA_NAME_MESSAGE =
": Schema name must start with a letter, followed by zero or more letters, numbers, spaces, dash or underscores. A space immediately before or after an underscore is not allowed. The character limit is 31.";
// if a table extends another table (optional)
public String inheritName = null;
// to allow indicate that a table should be dropped
Expand Down

0 comments on commit 282d6d1

Please sign in to comment.