feat: add PostgreSQL schema isolation for playground environment
- Create schema.rs utility module with table_name() function - Add schema prefix to all SQL queries in postgres_db.rs - Support dev schema for playground, public for production - Add DATABASE_SCHEMA, MONGODB_DATABASE, QDRANT_COLLECTION config - Fix 40+ functions including videos, chunks, frames, vectors, etc. - Update Cargo dependencies
This commit is contained in:
@@ -78,6 +78,15 @@ pub static SERVER_PORT: Lazy<u16> = Lazy::new(|| {
|
||||
pub static REDIS_KEY_PREFIX: Lazy<String> =
|
||||
Lazy::new(|| env::var("MOMENTRY_REDIS_PREFIX").unwrap_or_else(|_| "momentry:".to_string()));
|
||||
|
||||
pub static DATABASE_SCHEMA: Lazy<String> =
|
||||
Lazy::new(|| env::var("DATABASE_SCHEMA").unwrap_or_else(|_| "public".to_string()));
|
||||
|
||||
pub static MONGODB_DATABASE: Lazy<String> =
|
||||
Lazy::new(|| env::var("MONGODB_DATABASE").unwrap_or_else(|_| "momentry".to_string()));
|
||||
|
||||
pub static QDRANT_COLLECTION: Lazy<String> =
|
||||
Lazy::new(|| env::var("QDRANT_COLLECTION").unwrap_or_else(|_| "momentry_rule1".to_string()));
|
||||
|
||||
pub mod processor {
|
||||
use super::*;
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
use anyhow::Result;
|
||||
use async_trait::async_trait;
|
||||
|
||||
pub mod schema;
|
||||
|
||||
use crate::core::chunk::Chunk;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
30
src/core/db/schema.rs
Normal file
30
src/core/db/schema.rs
Normal file
@@ -0,0 +1,30 @@
|
||||
use crate::core::config::DATABASE_SCHEMA;
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
pub static SCHEMA_PREFIX: Lazy<String> = Lazy::new(|| {
|
||||
let schema = DATABASE_SCHEMA.as_str();
|
||||
if schema == "public" {
|
||||
String::new()
|
||||
} else {
|
||||
format!("{}.", schema)
|
||||
}
|
||||
});
|
||||
|
||||
pub fn table_name(table: &str) -> String {
|
||||
let prefix = SCHEMA_PREFIX.as_str();
|
||||
if prefix.is_empty() {
|
||||
table.to_string()
|
||||
} else {
|
||||
format!("{}{}", prefix, table)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_table_name_public() {
|
||||
assert_eq!(table_name("videos"), "videos");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user