feat: add topic hierarchy APIs

This commit is contained in:
2026-05-11 11:46:10 +09:00
parent d95ac8c1a0
commit ba03ecb85b
9 changed files with 223 additions and 2 deletions

View File

@@ -16,7 +16,7 @@ afterEach(async () => {
});
describe('initializeSchema', () => {
it('creates the topics, facts, and fact_topics tables', async () => {
it('creates the topics, facts, fact_topics, and topic_relations tables', async () => {
const connection = await createDatabase({ client: 'sqlite', filename: ':memory:' });
openConnections.push(connection.destroy);
@@ -34,6 +34,7 @@ describe('initializeSchema', () => {
expect(tableNames).toContain('topics');
expect(tableNames).toContain('facts');
expect(tableNames).toContain('fact_topics');
expect(tableNames).toContain('topic_relations');
});
it('creates the expected columns for each table', async () => {
@@ -45,6 +46,7 @@ describe('initializeSchema', () => {
const topicsColumns = await sql<{ name: string }>`PRAGMA table_info(topics)`.execute(connection.db);
const factsColumns = await sql<{ name: string }>`PRAGMA table_info(facts)`.execute(connection.db);
const factTopicsColumns = await sql<{ name: string }>`PRAGMA table_info(fact_topics)`.execute(connection.db);
const topicRelationsColumns = await sql<{ name: string }>`PRAGMA table_info(topic_relations)`.execute(connection.db);
expect(topicsColumns.rows.map((row) => row.name)).toEqual([
'id',
@@ -76,6 +78,13 @@ describe('initializeSchema', () => {
'position',
'created_at',
]);
expect(topicRelationsColumns.rows.map((row) => row.name)).toEqual([
'parent_topic_id',
'child_topic_id',
'relation',
'created_at',
]);
});
it('is idempotent when called more than once', async () => {