inputing data for the client for the validation

This commit is contained in:
Priec
2025-09-12 23:06:42 +02:00
parent cec2361b00
commit e1ea44c68c
6 changed files with 178 additions and 0 deletions

View File

@@ -351,6 +351,29 @@ async fn execute_table_definition(
Status::internal(format!("Database error: {}", e))
})?;
for col_def in &columns {
// Column string looks like "\"name\" TYPE", split out identifier
let col_name = col_def.split_whitespace().next().unwrap_or("");
let clean_col = col_name.trim_matches('"');
// Default empty config — currently only character_limits block, none set.
let default_cfg = serde_json::json!({
"character_limits": { "min": 0, "max": 0, "warn_at": null, "count_mode": "CHARS" }
});
sqlx::query!(
r#"INSERT INTO table_validation_rules (table_def_id, data_key, config)
VALUES ($1, $2, $3)
ON CONFLICT (table_def_id, data_key) DO NOTHING"#,
table_def.id,
clean_col,
default_cfg
)
.execute(&mut **tx)
.await
.map_err(|e| Status::internal(format!("Failed to insert default validation rule for column {}: {}", clean_col, e)))?;
}
for (linked_id, is_required) in links {
sqlx::query!(
"INSERT INTO table_definition_links