migration is now holding the target table information

This commit is contained in:
filipriec
2025-03-15 13:53:34 +01:00
parent 79f57ddaed
commit d87cc3b5b9
4 changed files with 13 additions and 20 deletions

View File

@@ -19,7 +19,6 @@ fn validate_target_column(
let columns: Vec<String> = serde_json::from_value(table_columns.clone())
.map_err(|e| format!("Invalid column data: {}", e))?;
// Extract column name and type
let column_info: Vec<(&str, &str)> = columns
.iter()
.filter_map(|c| {
@@ -30,7 +29,6 @@ fn validate_target_column(
})
.collect();
// Find the target column
let column_type = column_info
.iter()
.find(|(name, _)| *name == target)
@@ -65,26 +63,22 @@ pub async fn post_table_script(
// Parse and transform the script
let parser = SyntaxParser::new();
let parsed_script = parser.parse(&request.script);
// Extract dependencies
let (source_tables, source_columns) = parser.extract_dependencies(&request.script);
// Store script in database with column type and profile_id
// Store script in database with automatic target_table
let script_record = sqlx::query!(
r#"INSERT INTO table_scripts
(table_definitions_id, target_column, target_column_type,
script, source_tables, source_columns, description, profile_id)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
(table_definitions_id, target_table, target_column,
target_column_type, script, description, profile_id)
VALUES ($1, $2, $3, $4, $5, $6, $7)
RETURNING id"#,
request.table_definition_id,
table_def.table_name, // Auto-populate target_table from table_def
request.target_column,
column_type,
parsed_script, // Store transformed script
&Vec::from_iter(source_tables),
&Vec::from_iter(source_columns),
parsed_script,
request.description,
table_def.profile_id
)
)
.fetch_one(db_pool)
.await
.map_err(|e| match e {