fixed working table creation properly well, ready to be unit tested in the future, but its amazing now
This commit is contained in:
@@ -182,14 +182,19 @@ async fn generate_table_sql(
|
|||||||
let mut link_info = Vec::new();
|
let mut link_info = Vec::new();
|
||||||
for (linked_id, required) in links {
|
for (linked_id, required) in links {
|
||||||
let linked_table = get_table_name_by_id(db_pool, *linked_id).await?;
|
let linked_table = get_table_name_by_id(db_pool, *linked_id).await?;
|
||||||
let base_name = linked_table.split('_').last().unwrap_or(&linked_table);
|
|
||||||
|
// Extract base name after year prefix
|
||||||
|
let base_name = linked_table.split_once('_')
|
||||||
|
.map(|(_, rest)| rest)
|
||||||
|
.unwrap_or(&linked_table)
|
||||||
|
.to_string();
|
||||||
let null_clause = if *required { "NOT NULL" } else { "" };
|
let null_clause = if *required { "NOT NULL" } else { "" };
|
||||||
system_columns.push(
|
system_columns.push(
|
||||||
format!("\"{0}_id\" BIGINT {1} REFERENCES \"{2}\"(id)",
|
format!("\"{0}_id\" BIGINT {1} REFERENCES \"{2}\"(id)",
|
||||||
base_name, null_clause, linked_table
|
base_name, null_clause, linked_table
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
link_info.push((base_name.to_string(), linked_table));
|
link_info.push((base_name, linked_table));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Combine all columns
|
// Combine all columns
|
||||||
|
|||||||
Reference in New Issue
Block a user