more changes and more fixes, 3 more tests to go

This commit is contained in:
filipriec
2025-06-22 12:48:36 +02:00
parent 92d5eb4844
commit f4286ac3c9
6 changed files with 428 additions and 29 deletions

View File

@@ -332,9 +332,7 @@ async fn generate_table_sql(
indexes: &[String],
links: &[(i64, bool)],
) -> Result<(String, Vec<String>), Status> {
// Quote the schema name
let qualified_table = format!("\"{}\".\"{}\"", profile_name, table_name);
let mut system_columns = vec![
"id BIGSERIAL PRIMARY KEY".to_string(),
"deleted BOOLEAN NOT NULL DEFAULT FALSE".to_string(),
@@ -342,17 +340,13 @@ async fn generate_table_sql(
for (linked_id, required) in links {
let linked_table = get_table_name_by_id(tx, *linked_id).await?;
// Quote the schema name here too
let qualified_linked_table = format!("\"{}\".\"{}\"", profile_name, linked_table);
let base_name = linked_table.split_once('_')
.map(|(_, rest)| rest)
.unwrap_or(&linked_table)
.to_string();
let null_clause = if *required { "NOT NULL" } else { "" };
// Simply use the full table name - no truncation!
let null_clause = if *required { "NOT NULL" } else { "" };
system_columns.push(
format!("\"{0}_id\" BIGINT {1} REFERENCES {2}(id)",
base_name, null_clause, qualified_linked_table
format!("\"{}_id\" BIGINT {} REFERENCES {}(id)",
linked_table, null_clause, qualified_linked_table
)
);
}
@@ -372,13 +366,9 @@ async fn generate_table_sql(
let mut all_indexes = Vec::new();
for (linked_id, _) in links {
let linked_table = get_table_name_by_id(tx, *linked_id).await?;
let base_name = linked_table.split_once('_')
.map(|(_, rest)| rest)
.unwrap_or(&linked_table)
.to_string();
all_indexes.push(format!(
"CREATE INDEX \"idx_{}_{}_fk\" ON {} (\"{}_id\")",
table_name, base_name, qualified_table, base_name
table_name, linked_table, qualified_table, linked_table
));
}