feat: add isolated memory spaces
This commit is contained in:
@@ -4,6 +4,7 @@ import {
|
||||
FACTS_TABLE,
|
||||
FACT_EMBEDDINGS_TABLE,
|
||||
FACT_TOPICS_TABLE,
|
||||
SPACES_TABLE,
|
||||
TOPIC_ALIASES_TABLE,
|
||||
TOPIC_RELATIONS_TABLE,
|
||||
TOPICS_TABLE,
|
||||
@@ -14,23 +15,42 @@ export async function initializeSchema(
|
||||
db: Kysely<IdentityDatabaseSchema>,
|
||||
): Promise<void> {
|
||||
await db.schema
|
||||
.createTable(TOPICS_TABLE)
|
||||
.createTable(SPACES_TABLE)
|
||||
.ifNotExists()
|
||||
.addColumn('id', 'text', (column) => column.primaryKey())
|
||||
.addColumn('name', 'text', (column) => column.notNull())
|
||||
.addColumn('normalized_name', 'text', (column) => column.notNull().unique())
|
||||
.addColumn('category', 'text', (column) => column.notNull())
|
||||
.addColumn('granularity', 'text', (column) => column.notNull())
|
||||
.addColumn('description', 'text')
|
||||
.addColumn('metadata', 'text')
|
||||
.addColumn('created_at', 'text', (column) => column.notNull())
|
||||
.addColumn('updated_at', 'text', (column) => column.notNull())
|
||||
.execute();
|
||||
|
||||
await db.schema
|
||||
.createTable(TOPICS_TABLE)
|
||||
.ifNotExists()
|
||||
.addColumn('id', 'text', (column) => column.primaryKey())
|
||||
.addColumn('space_id', 'text', (column) =>
|
||||
column.notNull().references(`${SPACES_TABLE}.id`).onDelete('cascade'),
|
||||
)
|
||||
.addColumn('name', 'text', (column) => column.notNull())
|
||||
.addColumn('normalized_name', 'text', (column) => column.notNull())
|
||||
.addColumn('category', 'text', (column) => column.notNull())
|
||||
.addColumn('granularity', 'text', (column) => column.notNull())
|
||||
.addColumn('description', 'text')
|
||||
.addColumn('metadata', 'text')
|
||||
.addColumn('created_at', 'text', (column) => column.notNull())
|
||||
.addColumn('updated_at', 'text', (column) => column.notNull())
|
||||
.addUniqueConstraint('topics_space_normalized_name_key', ['space_id', 'normalized_name'])
|
||||
.execute();
|
||||
|
||||
await db.schema
|
||||
.createTable(FACTS_TABLE)
|
||||
.ifNotExists()
|
||||
.addColumn('id', 'text', (column) => column.primaryKey())
|
||||
.addColumn('space_id', 'text', (column) =>
|
||||
column.notNull().references(`${SPACES_TABLE}.id`).onDelete('cascade'),
|
||||
)
|
||||
.addColumn('statement', 'text', (column) => column.notNull())
|
||||
.addColumn('summary', 'text')
|
||||
.addColumn('source', 'text')
|
||||
@@ -88,14 +108,32 @@ export async function initializeSchema(
|
||||
.createTable(TOPIC_ALIASES_TABLE)
|
||||
.ifNotExists()
|
||||
.addColumn('id', 'text', (column) => column.primaryKey())
|
||||
.addColumn('space_id', 'text', (column) =>
|
||||
column.notNull().references(`${SPACES_TABLE}.id`).onDelete('cascade'),
|
||||
)
|
||||
.addColumn('topic_id', 'text', (column) =>
|
||||
column.notNull().references(`${TOPICS_TABLE}.id`).onDelete('cascade'),
|
||||
)
|
||||
.addColumn('alias', 'text', (column) => column.notNull())
|
||||
.addColumn('normalized_alias', 'text', (column) => column.notNull().unique())
|
||||
.addColumn('normalized_alias', 'text', (column) => column.notNull())
|
||||
.addColumn('is_primary', 'integer', (column) => column.notNull())
|
||||
.addColumn('created_at', 'text', (column) => column.notNull())
|
||||
.addColumn('updated_at', 'text', (column) => column.notNull())
|
||||
.addUniqueConstraint('topic_aliases_space_normalized_alias_key', ['space_id', 'normalized_alias'])
|
||||
.execute();
|
||||
|
||||
await db.schema
|
||||
.createIndex('topics_space_id_idx')
|
||||
.ifNotExists()
|
||||
.on(TOPICS_TABLE)
|
||||
.column('space_id')
|
||||
.execute();
|
||||
|
||||
await db.schema
|
||||
.createIndex('facts_space_id_idx')
|
||||
.ifNotExists()
|
||||
.on(FACTS_TABLE)
|
||||
.column('space_id')
|
||||
.execute();
|
||||
|
||||
await db.schema
|
||||
@@ -133,6 +171,13 @@ export async function initializeSchema(
|
||||
.column('child_topic_id')
|
||||
.execute();
|
||||
|
||||
await db.schema
|
||||
.createIndex('topic_aliases_space_id_idx')
|
||||
.ifNotExists()
|
||||
.on(TOPIC_ALIASES_TABLE)
|
||||
.column('space_id')
|
||||
.execute();
|
||||
|
||||
await db.schema
|
||||
.createIndex('topic_aliases_topic_id_idx')
|
||||
.ifNotExists()
|
||||
|
||||
Reference in New Issue
Block a user