use of org.neo4j.internal.schema.SchemaRule in project neo4j by neo4j.
the class TransactionRecordState method schemaRuleDelete.
void schemaRuleDelete(long ruleId, SchemaRule rule) {
RecordProxy<SchemaRecord, SchemaRule> proxy = recordChangeSet.getSchemaRuleChanges().getOrLoad(ruleId, rule, cursorContext);
SchemaRecord record = proxy.forReadingData();
if (record.inUse()) {
record = proxy.forChangingData();
record.setInUse(false);
getAndDeletePropertyChain(record);
}
// Index schema rules may be deleted twice, if they were owned by a constraint; once for dropping the index, and then again as part of
// dropping the constraint. So we keep this method idempotent.
}
use of org.neo4j.internal.schema.SchemaRule in project neo4j by neo4j.
the class SchemaRuleMigrationTest method constraintsWithoutNamesMustBeGivenGeneratedOnes.
@Test
void constraintsWithoutNamesMustBeGivenGeneratedOnes() throws KernelException {
SchemaRule rule = ConstraintDescriptorFactory.uniqueForSchema(SchemaDescriptor.forLabel(1, 2)).withId(1);
srcTokenHolders.labelTokens().setInitialTokens(List.of(new NamedToken("Label", 1)));
srcTokenHolders.propertyKeyTokens().setInitialTokens(List.of(new NamedToken("prop", 2)));
when(src.getAll(any())).thenReturn(List.of(rule));
RecordStorageMigrator.migrateSchemaRules(srcTokenHolders, src, dst, NULL);
assertEquals(1, writtenRules.size());
assertEquals("constraint_952591e6", writtenRules.get(0).getName());
}
use of org.neo4j.internal.schema.SchemaRule in project neo4j by neo4j.
the class SchemaRuleMigrationTest method mustEnsureThatMigratedSchemaRuleNamesAreUnique.
@Test
void mustEnsureThatMigratedSchemaRuleNamesAreUnique() throws KernelException {
SchemaRule rule1 = IndexPrototype.forSchema(SchemaDescriptor.forLabel(1, 2)).withName("a").materialise(1);
SchemaRule rule2 = IndexPrototype.forSchema(SchemaDescriptor.forLabel(1, 3)).withName("a").materialise(2);
srcTokenHolders.labelTokens().setInitialTokens(List.of(new NamedToken("Label", 1)));
srcTokenHolders.propertyKeyTokens().setInitialTokens(List.of(new NamedToken("a", 2), new NamedToken("b", 3)));
when(src.getAll(any())).thenReturn(List.of(rule1, rule2));
RecordStorageMigrator.migrateSchemaRules(srcTokenHolders, src, dst, NULL);
long distinctNames = writtenRules.stream().map(SchemaRule::getName).distinct().count();
assertEquals(2, distinctNames);
}
use of org.neo4j.internal.schema.SchemaRule in project neo4j by neo4j.
the class SchemaRuleMigrationTest method mustEnsureUniqueNamesEvenWhenOldNamesMatchesNewDefaults.
@Test
void mustEnsureUniqueNamesEvenWhenOldNamesMatchesNewDefaults() throws KernelException {
SchemaRule rule1 = ConstraintDescriptorFactory.uniqueForSchema(SchemaDescriptor.forLabel(1, 2)).withId(1);
SchemaRule rule2 = ConstraintDescriptorFactory.uniqueForSchema(SchemaDescriptor.forLabel(1, 2)).withId(2);
srcTokenHolders.labelTokens().setInitialTokens(List.of(new NamedToken("Label", 1)));
srcTokenHolders.propertyKeyTokens().setInitialTokens(List.of(new NamedToken("prop", 2), new NamedToken("bla", 3)));
when(src.getAll(any())).thenReturn(List.of(rule1, rule2));
RecordStorageMigrator.migrateSchemaRules(srcTokenHolders, src, dst, NULL);
assertEquals(2, writtenRules.size());
Set<String> names = writtenRules.stream().map(SchemaRule::getName).collect(Collectors.toSet());
// Collisions in generated names (however fantastically unlikely) must be resolved by appending a count.
assertEquals(Set.of("constraint_952591e6", "constraint_952591e6_1"), names);
}
use of org.neo4j.internal.schema.SchemaRule in project neo4j by neo4j.
the class SchemaStore35Test method storeAndLoadAllRules.
@Test
void storeAndLoadAllRules() {
// GIVEN
long indexId = store.nextId(NULL);
long constraintId = store.nextId(NULL);
Collection<SchemaRule> rules = Arrays.asList(uniqueIndexRule(indexId, constraintId, 2, 5, 3), constraintUniqueRule(constraintId, indexId, 2, 5, 3), indexRule(store.nextId(NULL), 0, 5), indexRule(store.nextId(NULL), 1, 6, 10, 99), constraintExistsRule(store.nextId(NULL), 5, 1));
for (SchemaRule rule : rules) {
storeRule(rule);
}
// WHEN
SchemaStorage35 storage35 = new SchemaStorage35(store);
Collection<SchemaRule> readRules = asCollection(storage35.getAll(NULL));
// THEN
assertEquals(rules, readRules);
}
Aggregations