Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions migrations_sqlx/postgres/20250101000000_initial.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 $$;

Expand Down
14 changes: 7 additions & 7 deletions migrations_sqlx/sqlite/20250101000000_initial.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
10 changes: 5 additions & 5 deletions src/config/limits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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
}

Expand Down
18 changes: 9 additions & 9 deletions src/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ struct CachedRepos {
vector_stores: Arc<dyn VectorStoresRepo>,
files: Arc<dyn FilesRepo>,
teams: Arc<dyn TeamRepo>,
prompts: Arc<dyn PromptRepo>,
templates: Arc<dyn TemplateRepo>,
#[cfg(feature = "sso")]
sso_group_mappings: Arc<dyn SsoGroupMappingRepo>,
#[cfg(feature = "sso")]
Expand Down Expand Up @@ -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")]
Expand Down Expand Up @@ -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")]
Expand Down Expand Up @@ -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(),
)),
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
)),
Expand Down Expand Up @@ -581,9 +581,9 @@ impl DbPool {
Arc::clone(&self.repos.teams)
}

/// Get prompt repository
pub fn prompts(&self) -> Arc<dyn PromptRepo> {
Arc::clone(&self.repos.prompts)
/// Get template repository
pub fn templates(&self) -> Arc<dyn TemplateRepo> {
Arc::clone(&self.repos.templates)
}

/// Get SSO group mapping repository
Expand Down
4 changes: 2 additions & 2 deletions src/db/postgres/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Loading
Loading