fixing tests and migration to the serialized deserialized JSONB2

This commit is contained in:
Priec
2025-09-17 21:19:41 +02:00
parent 095645a209
commit 73bc6dc99c

View File

@@ -5,6 +5,7 @@ use sqlx::{PgPool, Arguments, Row};
use sqlx::postgres::PgArguments; use sqlx::postgres::PgArguments;
use chrono::{DateTime, Utc}; use chrono::{DateTime, Utc};
use common::proto::komp_ac::tables_data::{PutTableDataRequest, PutTableDataResponse}; use common::proto::komp_ac::tables_data::{PutTableDataRequest, PutTableDataResponse};
use common::proto::komp_ac::table_definition::ColumnDefinition;
use std::sync::Arc; use std::sync::Arc;
use prost_types::value::Kind; use prost_types::value::Kind;
@@ -14,6 +15,7 @@ use std::collections::HashMap;
use crate::steel::server::execution::{self, Value}; use crate::steel::server::execution::{self, Value};
use crate::indexer::{IndexCommand, IndexCommandData}; use crate::indexer::{IndexCommand, IndexCommandData};
use crate::table_definition::models::map_field_type;
use tokio::sync::mpsc; use tokio::sync::mpsc;
use tracing::error; use tracing::error;
@@ -56,19 +58,20 @@ pub async fn put_table_data(
.map_err(|e| Status::internal(format!("Table lookup error: {}", e)))? .map_err(|e| Status::internal(format!("Table lookup error: {}", e)))?
.ok_or_else(|| Status::not_found("Table not found"))?; .ok_or_else(|| Status::not_found("Table not found"))?;
// Parse column definitions from JSON format // Parse column definitions from JSON format (now ColumnDefinition objects)
let columns_json: Vec<String> = serde_json::from_value(table_def.columns.clone()) let stored_columns: Vec<ColumnDefinition> = serde_json::from_value(table_def.columns.clone())
.map_err(|e| Status::internal(format!("Column parsing error: {}", e)))?; .map_err(|e| Status::internal(format!("Column parsing error: {}", e)))?;
// Convert ColumnDefinition → (name, sql_type)
let mut columns = Vec::new(); let mut columns = Vec::new();
for col_def in columns_json { for col_def in stored_columns {
let parts: Vec<&str> = col_def.splitn(2, ' ').collect(); let col_name = col_def.name.trim().to_string();
if parts.len() != 2 { let sql_type = map_field_type(&col_def.field_type)
return Err(Status::internal("Invalid column format")); .map_err(|e| Status::invalid_argument(format!(
} "Invalid type for column '{}': {}",
let name = parts[0].trim_matches('"').to_string(); col_name, e
let sql_type = parts[1].to_string(); )))?;
columns.push((name, sql_type)); columns.push((col_name, sql_type));
} }
// Build list of valid system columns (foreign keys and special columns) // Build list of valid system columns (foreign keys and special columns)