Skip to main content

uqa_sql/schema/removal/
tables.rs

1//
2// Unified Query Algebra
3//
4// Copyright (c) 2023-2026 Cognica, Inc.
5//
6
7//! The table a foreign key references, and the table a table DDL statement names.
8use crate::schema::dependencies::rewrites::stored_relation_reference_matches;
9use uqa_core::RelationIdentity;
10pub fn foreign_key_targets(
11    foreign_key: &crate::ast::ForeignKey,
12    target: &RelationIdentity,
13) -> bool {
14    stored_relation_reference_matches(&foreign_key.ref_table, target)
15}
16pub fn resolved_table_ddl_target(
17    resolved: Option<(String, &str)>,
18    action: &str,
19) -> Result<Option<String>, String> {
20    match resolved {
21        Some((canonical, "table")) => Ok(Some(canonical)),
22        Some((canonical, kind)) => Err(format!(
23            "{action}: relation `{canonical}` is a {kind}, not a table"
24        )),
25        None => Ok(None),
26    }
27}
28
29#[cfg(test)]
30mod tests;