diff --git a/migrations_sqlx/postgres/20250101000000_initial.sql b/migrations_sqlx/postgres/20250101000000_initial.sql index 1ecf6bb..09ed39f 100644 --- a/migrations_sqlx/postgres/20250101000000_initial.sql +++ b/migrations_sqlx/postgres/20250101000000_initial.sql @@ -1123,21 +1123,21 @@ END $$; -- without cross-database joins. See VectorStore trait for chunk operations. -- ====================================================================== --- Prompts +-- Templates -- ====================================================================== -- Reusable system prompt templates. DO $$ BEGIN - CREATE TYPE prompt_owner_type AS ENUM ('organization', 'team', 'project', 'user'); + CREATE TYPE template_owner_type AS ENUM ('organization', 'team', 'project', 'user'); EXCEPTION WHEN duplicate_object THEN null; END $$; -CREATE TABLE IF NOT EXISTS prompts ( +CREATE TABLE IF NOT EXISTS templates ( id UUID PRIMARY KEY NOT NULL, - -- Ownership (who can access this prompt) - owner_type prompt_owner_type NOT NULL, + -- Ownership (who can access this template) + owner_type template_owner_type NOT NULL, owner_id UUID NOT NULL, name VARCHAR(255) NOT NULL, description TEXT, @@ -1152,13 +1152,13 @@ CREATE TABLE IF NOT EXISTS prompts ( UNIQUE(owner_type, owner_id, name) ); -CREATE INDEX IF NOT EXISTS idx_prompts_owner ON prompts(owner_type, owner_id); --- Partial index for non-deleted prompts (most queries filter by deleted_at IS NULL) -CREATE INDEX IF NOT EXISTS idx_prompts_owner_active ON prompts(owner_type, owner_id) WHERE deleted_at IS NULL; -CREATE INDEX IF NOT EXISTS idx_prompts_name ON prompts(name); +CREATE INDEX IF NOT EXISTS idx_templates_owner ON templates(owner_type, owner_id); +-- Partial index for non-deleted templates (most queries filter by deleted_at IS NULL) +CREATE INDEX IF NOT EXISTS idx_templates_owner_active ON templates(owner_type, owner_id) WHERE deleted_at IS NULL; +CREATE INDEX IF NOT EXISTS idx_templates_name ON templates(name); DO $$ BEGIN - CREATE TRIGGER update_prompts_updated_at BEFORE UPDATE ON prompts FOR EACH ROW EXECUTE FUNCTION update_updated_at_column(); + CREATE TRIGGER update_templates_updated_at BEFORE UPDATE ON templates FOR EACH ROW EXECUTE FUNCTION update_updated_at_column(); EXCEPTION WHEN duplicate_object THEN null; END $$; diff --git a/migrations_sqlx/sqlite/20250101000000_initial.sql b/migrations_sqlx/sqlite/20250101000000_initial.sql index 0a602c2..c31b1de 100644 --- a/migrations_sqlx/sqlite/20250101000000_initial.sql +++ b/migrations_sqlx/sqlite/20250101000000_initial.sql @@ -916,14 +916,14 @@ CREATE INDEX IF NOT EXISTS idx_vector_store_files_deleted_at ON vector_store_fil -- without cross-database joins. See VectorStore trait for chunk operations. -- ====================================================================== --- Prompts +-- Templates -- ====================================================================== -- Reusable system prompt templates. -- owner_type: 'organization', 'team', 'project', 'user' -CREATE TABLE IF NOT EXISTS prompts ( +CREATE TABLE IF NOT EXISTS templates ( id TEXT PRIMARY KEY NOT NULL, - -- Ownership (who can access this prompt) + -- Ownership (who can access this template) owner_type TEXT NOT NULL CHECK (owner_type IN ('organization', 'team', 'project', 'user')), owner_id TEXT NOT NULL, name TEXT NOT NULL, @@ -939,10 +939,10 @@ CREATE TABLE IF NOT EXISTS prompts ( UNIQUE(owner_type, owner_id, name) ); -CREATE INDEX IF NOT EXISTS idx_prompts_owner ON prompts(owner_type, owner_id); --- Partial index for non-deleted prompts (most queries filter by deleted_at IS NULL) -CREATE INDEX IF NOT EXISTS idx_prompts_owner_active ON prompts(owner_type, owner_id) WHERE deleted_at IS NULL; -CREATE INDEX IF NOT EXISTS idx_prompts_name ON prompts(name); +CREATE INDEX IF NOT EXISTS idx_templates_owner ON templates(owner_type, owner_id); +-- Partial index for non-deleted templates (most queries filter by deleted_at IS NULL) +CREATE INDEX IF NOT EXISTS idx_templates_owner_active ON templates(owner_type, owner_id) WHERE deleted_at IS NULL; +CREATE INDEX IF NOT EXISTS idx_templates_name ON templates(name); -- ====================================================================== -- Service Accounts diff --git a/src/config/limits.rs b/src/config/limits.rs index 5868a0b..ba2cfe0 100644 --- a/src/config/limits.rs +++ b/src/config/limits.rs @@ -95,9 +95,9 @@ pub struct ResourceLimits { #[serde(default = "default_max_conversations_per_owner")] pub max_conversations_per_owner: u32, - /// Maximum prompts per owner (org/team/project/user). Default: 5,000. - #[serde(default = "default_max_prompts_per_owner")] - pub max_prompts_per_owner: u32, + /// Maximum templates per owner (org/team/project/user). Default: 5,000. + #[serde(default = "default_max_templates_per_owner")] + pub max_templates_per_owner: u32, /// Maximum domain verifications per SSO configuration. Default: 50. #[serde(default = "default_max_domains_per_sso_config")] @@ -146,7 +146,7 @@ impl Default for ResourceLimits { max_vector_stores_per_owner: default_max_vector_stores_per_owner(), max_files_per_vector_store: default_max_files_per_vector_store(), max_conversations_per_owner: default_max_conversations_per_owner(), - max_prompts_per_owner: default_max_prompts_per_owner(), + max_templates_per_owner: default_max_templates_per_owner(), max_domains_per_sso_config: default_max_domains_per_sso_config(), max_sso_group_mappings_per_org: default_max_sso_group_mappings_per_org(), max_members_per_org: default_max_members_per_org(), @@ -218,7 +218,7 @@ fn default_max_conversations_per_owner() -> u32 { 10_000 } -fn default_max_prompts_per_owner() -> u32 { +fn default_max_templates_per_owner() -> u32 { 5_000 } diff --git a/src/db/mod.rs b/src/db/mod.rs index 1e3c84a..4ad8c29 100644 --- a/src/db/mod.rs +++ b/src/db/mod.rs @@ -53,7 +53,7 @@ struct CachedRepos { vector_stores: Arc, files: Arc, teams: Arc, - prompts: Arc, + templates: Arc, #[cfg(feature = "sso")] sso_group_mappings: Arc, #[cfg(feature = "sso")] @@ -131,7 +131,7 @@ impl DbPool { vector_stores: Arc::new(sqlite::SqliteVectorStoresRepo::new(pool.clone())), files: Arc::new(sqlite::SqliteFilesRepo::new(pool.clone())), teams: Arc::new(sqlite::SqliteTeamRepo::new(pool.clone())), - prompts: Arc::new(sqlite::SqlitePromptRepo::new(pool.clone())), + templates: Arc::new(sqlite::SqliteTemplateRepo::new(pool.clone())), #[cfg(feature = "sso")] sso_group_mappings: Arc::new(sqlite::SqliteSsoGroupMappingRepo::new(pool.clone())), #[cfg(feature = "sso")] @@ -169,7 +169,7 @@ impl DbPool { vector_stores: Arc::new(sqlite::SqliteVectorStoresRepo::new(pool.clone())), files: Arc::new(sqlite::SqliteFilesRepo::new(pool.clone())), teams: Arc::new(sqlite::SqliteTeamRepo::new(pool.clone())), - prompts: Arc::new(sqlite::SqlitePromptRepo::new(pool.clone())), + templates: Arc::new(sqlite::SqliteTemplateRepo::new(pool.clone())), #[cfg(feature = "sso")] sso_group_mappings: unreachable!("SSO not supported in WASM builds"), #[cfg(feature = "sso")] @@ -244,7 +244,7 @@ impl DbPool { write_pool.clone(), read_pool.clone(), )), - prompts: Arc::new(postgres::PostgresPromptRepo::new( + templates: Arc::new(postgres::PostgresTemplateRepo::new( write_pool.clone(), read_pool.clone(), )), @@ -330,7 +330,7 @@ impl DbPool { vector_stores: Arc::new(sqlite::SqliteVectorStoresRepo::new(pool.clone())), files: Arc::new(sqlite::SqliteFilesRepo::new(pool.clone())), teams: Arc::new(sqlite::SqliteTeamRepo::new(pool.clone())), - prompts: Arc::new(sqlite::SqlitePromptRepo::new(pool.clone())), + templates: Arc::new(sqlite::SqliteTemplateRepo::new(pool.clone())), #[cfg(feature = "sso")] sso_group_mappings: Arc::new(sqlite::SqliteSsoGroupMappingRepo::new( pool.clone(), @@ -430,7 +430,7 @@ impl DbPool { write_pool.clone(), read_pool.clone(), )), - prompts: Arc::new(postgres::PostgresPromptRepo::new( + templates: Arc::new(postgres::PostgresTemplateRepo::new( write_pool.clone(), read_pool.clone(), )), @@ -581,9 +581,9 @@ impl DbPool { Arc::clone(&self.repos.teams) } - /// Get prompt repository - pub fn prompts(&self) -> Arc { - Arc::clone(&self.repos.prompts) + /// Get template repository + pub fn templates(&self) -> Arc { + Arc::clone(&self.repos.templates) } /// Get SSO group mapping repository diff --git a/src/db/postgres/mod.rs b/src/db/postgres/mod.rs index 11cfd33..4c6fc59 100644 --- a/src/db/postgres/mod.rs +++ b/src/db/postgres/mod.rs @@ -10,7 +10,6 @@ mod org_rbac_policies; mod org_sso_configs; mod organizations; mod projects; -mod prompts; mod providers; #[cfg(feature = "sso")] mod scim_configs; @@ -22,6 +21,7 @@ mod service_accounts; #[cfg(feature = "sso")] mod sso_group_mappings; mod teams; +mod templates; mod usage; mod users; mod vector_stores; @@ -38,7 +38,6 @@ pub use org_rbac_policies::PostgresOrgRbacPolicyRepo; pub use org_sso_configs::PostgresOrgSsoConfigRepo; pub use organizations::PostgresOrganizationRepo; pub use projects::PostgresProjectRepo; -pub use prompts::PostgresPromptRepo; pub use providers::PostgresDynamicProviderRepo; #[cfg(feature = "sso")] pub use scim_configs::PostgresOrgScimConfigRepo; @@ -50,6 +49,7 @@ pub use service_accounts::PostgresServiceAccountRepo; #[cfg(feature = "sso")] pub use sso_group_mappings::PostgresSsoGroupMappingRepo; pub use teams::PostgresTeamRepo; +pub use templates::PostgresTemplateRepo; pub use usage::PostgresUsageRepo; pub use users::PostgresUserRepo; pub use vector_stores::PostgresVectorStoresRepo; diff --git a/src/db/postgres/prompts.rs b/src/db/postgres/templates.rs similarity index 66% rename from src/db/postgres/prompts.rs rename to src/db/postgres/templates.rs index 4e407c4..81a2dc3 100644 --- a/src/db/postgres/prompts.rs +++ b/src/db/postgres/templates.rs @@ -8,19 +8,19 @@ use crate::{ db::{ error::{DbError, DbResult}, repos::{ - Cursor, CursorDirection, ListParams, ListResult, PageCursors, PromptRepo, + Cursor, CursorDirection, ListParams, ListResult, PageCursors, TemplateRepo, cursor_from_row, }, }, - models::{CreatePrompt, Prompt, PromptOwnerType, UpdatePrompt}, + models::{CreateTemplate, Template, TemplateOwnerType, UpdateTemplate}, }; -pub struct PostgresPromptRepo { +pub struct PostgresTemplateRepo { write_pool: PgPool, read_pool: PgPool, } -impl PostgresPromptRepo { +impl PostgresTemplateRepo { pub fn new(write_pool: PgPool, read_pool: Option) -> Self { let read_pool = read_pool.unwrap_or_else(|| write_pool.clone()); Self { @@ -29,10 +29,10 @@ impl PostgresPromptRepo { } } - /// Parse a Prompt from a database row. - fn parse_prompt(row: &sqlx::postgres::PgRow) -> DbResult { + /// Parse a Template from a database row. + fn parse_template(row: &sqlx::postgres::PgRow) -> DbResult