steel validation in progress

This commit is contained in:
filipriec
2025-03-08 10:20:08 +01:00
parent 66c29d8d65
commit 53ab9ad7d7
8 changed files with 40 additions and 71 deletions

View File

@@ -2,8 +2,29 @@
use tonic::Status;
use sqlx::{PgPool, Error as SqlxError};
use common::proto::multieko2::table_script::{PostTableScriptRequest, TableScriptResponse};
use crate::steel::handlers::evaluator::validate_target_column;
use crate::steel::validation::script::validate_script;
use serde_json::Value;
const SYSTEM_COLUMNS: &[&str] = &["id", "deleted", "created_at"];
fn validate_target_column(
table_name: &str,
target: &str,
table_columns: &Value,
) -> Result<(), String> {
if SYSTEM_COLUMNS.contains(&target) {
return Err(format!("Cannot override system column: {}", target));
}
let columns: Vec<String> = serde_json::from_value(table_columns.clone())
.map_err(|e| format!("Invalid column data: {}", e))?;
if !columns.iter().any(|c| c == target) {
return Err(format!("Target column {} not defined in table {}", target, table_name));
}
Ok(())
}
pub async fn post_table_script(
db_pool: &PgPool,