feat(personal): add isolated personal knowledge schema

This commit is contained in:
2026-07-12 01:46:39 +08:00
parent 2957f29326
commit f9a5516a1a
3 changed files with 147 additions and 0 deletions
@@ -0,0 +1,50 @@
package org.dromara.aihr.personal;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Tag;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Locale;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
@Tag("dev")
class PersonalSchemaContractTest {
private static final String SCHEMA_FILE = "aihr_personal_knowledge_mysql8.sql";
@Test
void personalKnowledgeSchemaIsOwnerScopedAndIndependent() throws IOException {
Path sqlPath = locateSqlDirectory().resolve(SCHEMA_FILE);
assertTrue(Files.isRegularFile(sqlPath), "Missing personal knowledge schema: " + sqlPath);
String sql = Files.readString(sqlPath).toLowerCase(Locale.ROOT);
assertTrue(sql.contains("create table if not exists `aihr_personal_space`"));
assertTrue(sql.contains("create table if not exists `aihr_personal_item`"));
assertTrue(sql.contains("create table if not exists `aihr_personal_fragment`"));
assertTrue(sql.contains("create table if not exists `aihr_personal_chat_session`"));
assertTrue(sql.contains("create table if not exists `aihr_personal_chat_message`"));
assertTrue(sql.contains("`owner_user_id`"), "Personal records must be owner scoped");
assertTrue(sql.contains("fulltext key"), "Personal fragments must provide full-text search");
assertFalse(sql.contains("alter table aihr_knowledge_fragment"),
"Personal schema must not mutate enterprise knowledge tables");
assertFalse(sql.contains("alter table `aihr_knowledge_fragment`"),
"Personal schema must not mutate enterprise knowledge tables");
}
private Path locateSqlDirectory() {
Path current = Path.of("").toAbsolutePath().normalize();
while (current != null) {
Path candidate = current.resolve("backend/script/sql");
if (Files.isDirectory(candidate)) {
return candidate;
}
current = current.getParent();
}
throw new IllegalStateException("Unable to locate backend/script/sql from "
+ Path.of("").toAbsolutePath());
}
}