now not creating tables with the year_ prefix and living in the gen schema by default

This commit is contained in:
filipriec
2025-06-17 11:45:55 +02:00
parent 3eb9523103
commit 8ebe74484c
8 changed files with 82 additions and 41 deletions

View File

@@ -38,7 +38,12 @@ pub async fn delete_table_data(
}
// Qualify table name with schema
let qualified_table = qualify_table_name_for_data(&request.table_name)?;
let qualified_table = qualify_table_name_for_data(
db_pool,
&request.profile_name,
&request.table_name,
)
.await?;
// Perform soft delete using qualified table name
let query = format!(

View File

@@ -88,7 +88,12 @@ pub async fn get_table_data(
// --- END OF FIX ---
// Qualify table name with schema
let qualified_table = qualify_table_name_for_data(&table_name)?;
let qualified_table = qualify_table_name_for_data(
db_pool,
&profile_name,
&table_name,
)
.await?;
let sql = format!(
"SELECT {} FROM {} WHERE id = $1 AND deleted = false",

View File

@@ -45,7 +45,12 @@ pub async fn get_table_data_by_position(
}
// Qualify table name with schema
let qualified_table = qualify_table_name_for_data(&table_name)?;
let qualified_table = qualify_table_name_for_data(
db_pool,
&profile_name,
&table_name,
)
.await?;
let id_result = sqlx::query_scalar(
&format!(

View File

@@ -47,7 +47,12 @@ pub async fn get_table_data_count(
}
// 2. QUALIFY THE TABLE NAME using the imported function
let qualified_table_name = qualify_table_name_for_data(&request.table_name)?;
let qualified_table = qualify_table_name_for_data(
db_pool,
&request.profile_name,
&request.table_name,
)
.await?;
// 3. USE THE QUALIFIED NAME in the SQL query
let query_sql = format!(
@@ -56,7 +61,7 @@ pub async fn get_table_data_count(
FROM {}
WHERE deleted = FALSE
"#,
qualified_table_name // Use the schema-qualified name here
qualified_table
);
// The rest of the logic remains largely the same, but error messages can be more specific.
@@ -81,14 +86,14 @@ pub async fn get_table_data_count(
// even though it was defined in table_definitions. This is an inconsistency.
return Err(Status::internal(format!(
"Table '{}' is defined but does not physically exist in the database as {}.",
request.table_name, qualified_table_name
request.table_name, qualified_table
)));
}
}
// For other errors, provide a general message.
Err(Status::internal(format!(
"Count query failed for table {}: {}",
qualified_table_name, e
qualified_table, e
)))
}
}

View File

@@ -7,8 +7,7 @@ use chrono::{DateTime, Utc};
use common::proto::multieko2::tables_data::{PostTableDataRequest, PostTableDataResponse};
use std::collections::HashMap;
use std::sync::Arc;
use crate::shared::schema_qualifier::qualify_table_name_for_data;
use prost_types::value::Kind; // NEW: Import the Kind enum
use prost_types::value::Kind;
use crate::steel::server::execution::{self, Value};
use crate::steel::server::functions::SteelContext;
@@ -261,7 +260,12 @@ pub async fn post_table_data(
}
// Qualify table name with schema
let qualified_table = qualify_table_name_for_data(&table_name)?;
let qualified_table = crate::shared::schema_qualifier::qualify_table_name_for_data(
db_pool,
&profile_name,
&table_name,
)
.await?;
let sql = format!(
"INSERT INTO {} ({}) VALUES ({}) RETURNING id",

View File

@@ -161,7 +161,12 @@ pub async fn put_table_data(
params.add(record_id)
.map_err(|e| Status::internal(format!("Failed to add record_id parameter: {}", e)))?;
let qualified_table = qualify_table_name_for_data(&table_name)?;
let qualified_table = qualify_table_name_for_data(
db_pool,
&profile_name,
&table_name,
)
.await?;
let set_clause = set_clauses.join(", ");
let sql = format!(
"UPDATE {} SET {} WHERE id = ${} AND deleted = FALSE RETURNING id",