gluesql_core/executor/alter/
error.rs

1use {
2    super::table::Referencing,
3    crate::ast::{DataType, Expr},
4    serde::Serialize,
5    std::fmt::Debug,
6    thiserror::Error,
7};
8
9#[derive(Error, Serialize, Debug, PartialEq, Eq)]
10pub enum AlterError {
11    // CREATE TABLE
12    #[error("table already exists: {0}")]
13    TableAlreadyExists(String),
14
15    #[error("function already exists: {0}")]
16    FunctionAlreadyExists(String),
17
18    #[error("function does not exist: {0}")]
19    FunctionNotFound(String),
20
21    // CREATE INDEX, DROP TABLE
22    #[error("table does not exist: {0}")]
23    TableNotFound(String),
24
25    #[error("CTAS source table does not exist: {0}")]
26    CtasSourceTableNotFound(String),
27
28    // validate column def
29    #[error("column '{0}' of data type '{1:?}' is unsupported for unique constraint")]
30    UnsupportedDataTypeForUniqueColumn(String, DataType),
31
32    // validate index expr
33    #[error("unsupported index expr: {0:#?}")]
34    UnsupportedIndexExpr(Box<Expr>),
35
36    // validate index expr
37    #[error("unsupported unnamed argument")]
38    UnsupportedUnnamedArg,
39
40    #[error("identifier not found: {0:#?}")]
41    IdentifierNotFound(Box<Expr>),
42
43    #[error("duplicate column name: {0}")]
44    DuplicateColumnName(String),
45
46    #[error("duplicate arg name: {0}")]
47    DuplicateArgName(String),
48
49    #[error("non-default argument should not follow the default argument")]
50    NonDefaultArgumentFollowsDefaultArgument,
51
52    #[error("foreign table not found: {0}")]
53    ReferencedTableNotFound(String),
54
55    #[error("referenced column not found: {0}")]
56    ReferencedColumnNotFound(String),
57
58    #[error("referencing column not found: {0}")]
59    ReferencingColumnNotFound(String),
60
61    #[error(
62        "referencing column '{referencing_column}' of data type '{referencing_column_type}' does not match referenced column '{referenced_column}' of data type '{referenced_column_type}'"
63    )]
64    ForeignKeyDataTypeMismatch {
65        referencing_column: String,
66        referencing_column_type: DataType,
67        referenced_column: String,
68        referenced_column_type: DataType,
69    },
70
71    #[error(
72        "referenced column '{referenced_table}.{referenced_column}' is not unique, cannot be used as foreign key"
73    )]
74    ReferencingNonPKColumn {
75        referenced_table: String,
76        referenced_column: String,
77    },
78
79    #[error("cannot drop table '{referenced_table_name}' due to referencing tables: '{}'", referencings.iter().map(ToString::to_string).collect::<Vec<_>>().join(", "))]
80    CannotDropTableWithReferencing {
81        referenced_table_name: String,
82        referencings: Vec<Referencing>,
83    },
84
85    #[error("cannot drop column '{}.{}' referenced by '{}'", referencing.foreign_key.referenced_table_name, referencing.foreign_key.referenced_column_name, referencing)]
86    CannotAlterReferencedColumn { referencing: Referencing },
87
88    #[error("cannot drop column '{}.{}' referencing with '{}'", referencing.table_name, referencing.foreign_key.referencing_column_name, referencing)]
89    CannotAlterReferencingColumn { referencing: Referencing },
90
91    #[error("unreachable")]
92    Unreachable,
93}