table name

This commit is contained in:
Filipriec
2026-08-25 13:01:32 +02:00
parent ed01d1ec5b
commit aea54f8d33
12 changed files with 135 additions and 45 deletions

View File

@@ -579,7 +579,7 @@ impl ColumnDraft {
return Ok(None);
}
if self.catalog.is_link(&column_type) {
let target = self.link_table_input.trim().to_ascii_lowercase();
let target = self.link_table_input.trim();
return Ok((!target.is_empty()).then(|| format!("{column_type}({target})")));
}
let Some(group) = self.pending_group() else {
@@ -1209,8 +1209,28 @@ pub(crate) fn validate_table_name(
locale: crate::i18n::Locale,
value: &str,
) -> Option<String> {
if let Some(error) = validate_identifier(locale, value, "label-table-name", true) {
return Some(error);
let label = crate::tr!(locale, "label-table-name");
if value.is_empty() {
return Some(crate::tr!(locale, "error-identifier-empty", "label" => label));
}
if value != value.trim() {
return Some(crate::tr!(locale, "error-identifier-whitespace", "label" => label));
}
if !value.chars().all(|character| {
character.is_ascii_alphanumeric() || matches!(character, '_' | '-')
}) {
return Some(crate::tr!(locale, "error-table-name-charset", "label" => label));
}
if !value
.chars()
.next()
.is_some_and(|character| character.is_ascii_alphanumeric())
|| !value
.chars()
.last()
.is_some_and(|character| character.is_ascii_alphanumeric())
{
return Some(crate::tr!(locale, "error-table-name-boundary", "label" => label));
}
if value.len() > MAX_TABLE_NAME_LENGTH {
// The limit is arithmetic, not a literal: it moves when a system column
@@ -1221,7 +1241,10 @@ pub(crate) fn validate_table_name(
"limit" => MAX_TABLE_NAME_LENGTH as i64,
));
}
if RESERVED_TABLE_NAMES.contains(&value) {
let canonical = common::alias::canonical_table_name(value);
if RESERVED_TABLE_NAMES.contains(&canonical.as_str())
|| crate::system_column::is_system_column(&canonical)
{
return Some(crate::tr!(
locale,
"schema-err-table-name-reserved",
@@ -2305,6 +2328,12 @@ pub(crate) mod tests {
.unwrap_or_else(|| panic!("`{name}` should be reserved"));
assert!(error.contains(name), "{error}");
}
assert_eq!(validate_table_name(crate::i18n::Locale::default(), "Custom_Exchange_Rates"),
validate_table_name(crate::i18n::Locale::default(), "custom_exchange_rates"));
assert_eq!(validate_table_name(crate::i18n::Locale::default(), "2026-Sales_Q4"), None);
for name in ["_sales", "sales_", "-sales", "sales-"] {
assert!(validate_table_name(crate::i18n::Locale::default(), name).is_some());
}
assert_eq!(validate_table_name(crate::i18n::Locale::default(), "invoice"), None);
}
}