compiled with the profile to be schemas
This commit is contained in:
@@ -9,24 +9,24 @@ pub async fn delete_table_data(
|
||||
request: DeleteTableDataRequest,
|
||||
) -> Result<DeleteTableDataResponse, Status> {
|
||||
// Lookup profile
|
||||
let profile = sqlx::query!(
|
||||
"SELECT id FROM profiles WHERE name = $1",
|
||||
let schema = sqlx::query!(
|
||||
"SELECT id FROM schemas WHERE name = $1",
|
||||
request.profile_name
|
||||
)
|
||||
.fetch_optional(db_pool)
|
||||
.await
|
||||
.map_err(|e| Status::internal(format!("Profile lookup error: {}", e)))?;
|
||||
|
||||
let profile_id = match profile {
|
||||
Some(p) => p.id,
|
||||
let schema_id = match schema {
|
||||
Some(s) => s.id,
|
||||
None => return Err(Status::not_found("Profile not found")),
|
||||
};
|
||||
|
||||
// Verify table exists in profile
|
||||
let table_exists = sqlx::query!(
|
||||
"SELECT 1 AS exists FROM table_definitions
|
||||
WHERE profile_id = $1 AND table_name = $2",
|
||||
profile_id,
|
||||
WHERE schema_id = $1 AND table_name = $2",
|
||||
schema_id,
|
||||
request.table_name
|
||||
)
|
||||
.fetch_optional(db_pool)
|
||||
|
||||
@@ -15,21 +15,21 @@ pub async fn get_table_data(
|
||||
let record_id = request.id;
|
||||
|
||||
// Lookup profile
|
||||
let profile = sqlx::query!(
|
||||
"SELECT id FROM profiles WHERE name = $1",
|
||||
let schema = sqlx::query!(
|
||||
"SELECT id FROM schemas WHERE name = $1",
|
||||
profile_name
|
||||
)
|
||||
.fetch_optional(db_pool)
|
||||
.await
|
||||
.map_err(|e| Status::internal(format!("Profile lookup error: {}", e)))?;
|
||||
|
||||
let profile_id = profile.ok_or_else(|| Status::not_found("Profile not found"))?.id;
|
||||
let schema_id = schema.ok_or_else(|| Status::not_found("Profile not found"))?.id;
|
||||
|
||||
// Lookup table_definition
|
||||
let table_def = sqlx::query!(
|
||||
r#"SELECT id, columns FROM table_definitions
|
||||
WHERE profile_id = $1 AND table_name = $2"#,
|
||||
profile_id,
|
||||
WHERE schema_id = $1 AND table_name = $2"#,
|
||||
schema_id,
|
||||
table_name
|
||||
)
|
||||
.fetch_optional(db_pool)
|
||||
|
||||
@@ -18,22 +18,22 @@ pub async fn get_table_data_by_position(
|
||||
return Err(Status::invalid_argument("Position must be at least 1"));
|
||||
}
|
||||
|
||||
let profile = sqlx::query!(
|
||||
"SELECT id FROM profiles WHERE name = $1",
|
||||
let schema = sqlx::query!(
|
||||
"SELECT id FROM schemas WHERE name = $1",
|
||||
profile_name
|
||||
)
|
||||
.fetch_optional(db_pool)
|
||||
.await
|
||||
.map_err(|e| Status::internal(format!("Profile lookup error: {}", e)))?;
|
||||
|
||||
let profile_id = profile.ok_or_else(|| Status::not_found("Profile not found"))?.id;
|
||||
let schema_id = schema.ok_or_else(|| Status::not_found("Profile not found"))?.id;
|
||||
|
||||
let table_exists = sqlx::query_scalar!(
|
||||
r#"SELECT EXISTS(
|
||||
SELECT 1 FROM table_definitions
|
||||
WHERE profile_id = $1 AND table_name = $2
|
||||
WHERE schema_id = $1 AND table_name = $2
|
||||
) AS "exists!""#,
|
||||
profile_id,
|
||||
schema_id,
|
||||
table_name
|
||||
)
|
||||
.fetch_one(db_pool)
|
||||
|
||||
@@ -12,15 +12,15 @@ pub async fn get_table_data_count(
|
||||
// We still need to verify that the table is logically defined for the profile.
|
||||
// The schema qualifier handles *how* to access it physically, but this check
|
||||
// ensures the request is valid in the context of the application's definitions.
|
||||
let profile = sqlx::query!(
|
||||
"SELECT id FROM profiles WHERE name = $1",
|
||||
let schema = sqlx::query!(
|
||||
"SELECT id FROM schemas WHERE name = $1",
|
||||
request.profile_name
|
||||
)
|
||||
.fetch_optional(db_pool)
|
||||
.await
|
||||
.map_err(|e| Status::internal(format!("Profile lookup error for '{}': {}", request.profile_name, e)))?;
|
||||
|
||||
let profile_id = match profile {
|
||||
let schema_id = match schema {
|
||||
Some(p) => p.id,
|
||||
None => return Err(Status::not_found(format!("Profile '{}' not found", request.profile_name))),
|
||||
};
|
||||
@@ -28,9 +28,9 @@ pub async fn get_table_data_count(
|
||||
let table_defined_for_profile = sqlx::query_scalar!(
|
||||
r#"SELECT EXISTS(
|
||||
SELECT 1 FROM table_definitions
|
||||
WHERE profile_id = $1 AND table_name = $2
|
||||
) AS "exists!" "#, // Added AS "exists!" for clarity with sqlx macro
|
||||
profile_id,
|
||||
WHERE schema_id = $1 AND table_name = $2
|
||||
) AS "exists!" "#,
|
||||
schema_id,
|
||||
request.table_name
|
||||
)
|
||||
.fetch_one(db_pool)
|
||||
|
||||
@@ -25,21 +25,21 @@ pub async fn post_table_data(
|
||||
let table_name = request.table_name;
|
||||
|
||||
// Lookup profile
|
||||
let profile = sqlx::query!(
|
||||
"SELECT id FROM profiles WHERE name = $1",
|
||||
let schema = sqlx::query!(
|
||||
"SELECT id FROM schemas WHERE name = $1",
|
||||
profile_name
|
||||
)
|
||||
.fetch_optional(db_pool)
|
||||
.await
|
||||
.map_err(|e| Status::internal(format!("Profile lookup error: {}", e)))?;
|
||||
|
||||
let profile_id = profile.ok_or_else(|| Status::not_found("Profile not found"))?.id;
|
||||
let schema_id = schema.ok_or_else(|| Status::not_found("Profile not found"))?.id;
|
||||
|
||||
// Lookup table_definition
|
||||
let table_def = sqlx::query!(
|
||||
r#"SELECT id, columns FROM table_definitions
|
||||
WHERE profile_id = $1 AND table_name = $2"#,
|
||||
profile_id,
|
||||
WHERE schema_id = $1 AND table_name = $2"#,
|
||||
schema_id,
|
||||
table_name
|
||||
)
|
||||
.fetch_optional(db_pool)
|
||||
@@ -132,7 +132,8 @@ pub async fn post_table_data(
|
||||
|
||||
let context = SteelContext {
|
||||
current_table: table_name.clone(),
|
||||
profile_id,
|
||||
schema_id,
|
||||
schema_name: profile_name.clone(),
|
||||
row_data: string_data_for_scripts.clone(),
|
||||
db_pool: Arc::new(db_pool.clone()),
|
||||
};
|
||||
|
||||
@@ -21,21 +21,21 @@ pub async fn put_table_data(
|
||||
}
|
||||
|
||||
// Lookup profile
|
||||
let profile = sqlx::query!(
|
||||
"SELECT id FROM profiles WHERE name = $1",
|
||||
let schema = sqlx::query!(
|
||||
"SELECT id FROM schemas WHERE name = $1",
|
||||
profile_name
|
||||
)
|
||||
.fetch_optional(db_pool)
|
||||
.await
|
||||
.map_err(|e| Status::internal(format!("Profile lookup error: {}", e)))?;
|
||||
|
||||
let profile_id = profile.ok_or_else(|| Status::not_found("Profile not found"))?.id;
|
||||
let schema_id = schema.ok_or_else(|| Status::not_found("Profile not found"))?.id;
|
||||
|
||||
// Lookup table_definition
|
||||
let table_def = sqlx::query!(
|
||||
r#"SELECT id, columns FROM table_definitions
|
||||
WHERE profile_id = $1 AND table_name = $2"#,
|
||||
profile_id,
|
||||
WHERE schema_id = $1 AND table_name = $2"#,
|
||||
schema_id,
|
||||
table_name
|
||||
)
|
||||
.fetch_optional(db_pool)
|
||||
|
||||
Reference in New Issue
Block a user