PgSchemaManager
Manages the PostgreSQL schema for permission-based RAG.
Creates and maintains the database tables required for:
- Principal ID mapping (users and groups to integers)
- Collection hierarchy with permissions
- Extended vectors table with collection_id and readable_by
Attributes
- Graph
-
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
PgSchemaManager.type
Members list
Value members
Concrete methods
Create a default public collection for migrating existing data.
Create a default public collection for migrating existing data.
This creates a "default" collection that is:
- Public (empty queryable_by)
- A leaf collection (can contain documents)
Value parameters
- conn
-
Database connection
Attributes
- Returns
-
The ID of the default collection, or error
Drop all permission-related tables and sequences.
Drop all permission-related tables and sequences.
WARNING: This is destructive and will delete all permission data. Only use for testing or complete reset.
Value parameters
- conn
-
Database connection
- tableName
-
The name of the vectors table (to remove permission columns)
Attributes
- Returns
-
Success or error
Extend an existing vectors table with permission columns.
Extend an existing vectors table with permission columns.
Adds:
- collection_id column (foreign key to llm4s_collections)
- readable_by column (array of principal IDs)
- Indexes for efficient filtering
Value parameters
- conn
-
Database connection
- tableName
-
The name of the vectors table to extend
Attributes
- Returns
-
Success or error
Initialize the permission schema in the database.
Initialize the permission schema in the database.
This creates:
- llm4s_principals table for user/group ID mapping
- llm4s_group_id_seq sequence for negative group IDs
- llm4s_collections table for the collection hierarchy
- Indexes for efficient querying
Value parameters
- conn
-
Database connection
Attributes
- Returns
-
Success or error
Check if the permission schema is already initialized.
Check if the permission schema is already initialized.
Value parameters
- conn
-
Database connection
Attributes
- Returns
-
True if schema exists, false otherwise
Migrate existing vectors to the default collection.
Migrate existing vectors to the default collection.
Updates all vectors that don't have a collection_id to use the default collection.
Value parameters
- conn
-
Database connection
- defaultCollectionId
-
The ID of the default collection
- tableName
-
The name of the vectors table
Attributes
- Returns
-
Number of migrated vectors, or error
Run the full migration: initialize schema, extend vectors, create default collection, migrate data.
Run the full migration: initialize schema, extend vectors, create default collection, migrate data.
Value parameters
- conn
-
Database connection
- tableName
-
The name of the vectors table
Attributes
- Returns
-
Migration stats or error