Skip to main content

pgevolve_core/ir/
mod.rs

1//! In-memory representation of a Postgres schema.
2//!
3//! The IR is the contract between every other component. Both the source-side
4//! parser and the catalog reader produce these types; the differ, dependency
5//! analyzer, and planner consume them.
6
7pub mod aggregate;
8pub mod canon;
9pub mod cast;
10pub mod catalog;
11pub mod cluster;
12pub mod collation;
13pub mod column;
14pub mod column_type;
15pub mod constraint;
16pub mod default_expr;
17pub mod default_privileges;
18pub mod difference;
19pub mod eq;
20pub mod extension;
21pub mod function;
22pub mod grant;
23pub mod index;
24pub mod partition;
25pub mod policy;
26pub mod publication;
27pub mod reloptions;
28pub mod schema;
29pub mod sequence;
30pub mod statistic;
31pub mod subscription;
32pub mod table;
33pub use function::*;
34pub mod procedure;
35pub use procedure::*;
36pub mod event_trigger;
37pub mod text_search;
38pub mod trigger;
39pub mod user_type;
40pub use user_type::*;
41pub mod view;
42pub use view::*;
43
44use thiserror::Error;
45
46/// Errors raised when constructing IR values.
47#[derive(Debug, Error)]
48pub enum IrError {
49    /// An identifier did not satisfy validation rules.
50    #[error("invalid identifier: {0}")]
51    InvalidIdentifier(String),
52
53    /// A type definition was not representable in our IR.
54    #[error("invalid column type: {0}")]
55    InvalidColumnType(String),
56
57    /// A required field was missing or empty.
58    #[error("missing required field: {0}")]
59    MissingField(&'static str),
60
61    /// A `PublicationScope::Selective` had no schemas and no tables.
62    #[error("publication {0:?}: empty Selective scope (no tables, no schemas)")]
63    EmptyPublication(crate::identifier::Identifier),
64    /// A `PublishedTable.columns` was `Some(vec![])`.
65    #[error("publication {0:?} table {1:?}: empty column list (use None to publish all columns)")]
66    EmptyColumnList(
67        crate::identifier::Identifier,
68        crate::identifier::QualifiedName,
69    ),
70    /// A `PublishKinds` had all four DML flags false.
71    #[error("publication {0:?}: empty publish bitset (must enable at least one DML kind)")]
72    EmptyPublishBitset(crate::identifier::Identifier),
73    /// A `PublishedTable.columns` contained a duplicate column name.
74    #[error("publication {0:?} table {1:?}: duplicate column {2:?} in column list")]
75    DuplicateColumnInPublication(
76        crate::identifier::Identifier,
77        crate::identifier::QualifiedName,
78        crate::identifier::Identifier,
79    ),
80
81    /// A `Subscription.publications` was empty.
82    #[error("subscription {0:?}: empty publication list (PG requires at least one)")]
83    EmptySubscriptionPublications(crate::identifier::Identifier),
84    /// A `Subscription.connection` was empty or whitespace-only.
85    #[error("subscription {0:?}: empty connection string")]
86    EmptyConnection(crate::identifier::Identifier),
87
88    /// A `StatisticKinds` had all three flags false.
89    #[error(
90        "statistic {0}: empty kinds bitset (must enable at least one of ndistinct, dependencies, mcv)"
91    )]
92    EmptyStatisticKinds(crate::identifier::QualifiedName),
93    /// A `Statistic.columns` was empty.
94    #[error("statistic {0}: empty column list")]
95    EmptyStatisticColumns(crate::identifier::QualifiedName),
96
97    /// Two event triggers share a name.
98    #[error("duplicate event trigger: {0}")]
99    DuplicateEventTrigger(crate::identifier::Identifier),
100
101    /// Two aggregates share the same `(qname, arg_types)` overload identity.
102    #[error("duplicate aggregate overload: {0} (same name and argument types)")]
103    DuplicateAggregate(crate::identifier::QualifiedName),
104
105    /// Two `TEXT SEARCH DICTIONARY` objects share the same `qname`.
106    #[error("duplicate text search dictionary: {0}")]
107    DuplicateTsDictionary(crate::identifier::QualifiedName),
108
109    /// Two `TEXT SEARCH CONFIGURATION` objects share the same `qname`.
110    #[error("duplicate text search configuration: {0}")]
111    DuplicateTsConfiguration(crate::identifier::QualifiedName),
112
113    /// Two casts share the same `(source, target)` identity.
114    #[error("duplicate cast ({src} AS {tgt})")]
115    DuplicateCast {
116        /// Source type of the duplicate cast.
117        src: crate::identifier::QualifiedName,
118        /// Target type of the duplicate cast.
119        tgt: crate::identifier::QualifiedName,
120    },
121
122    /// Two tablespaces share a name.
123    #[error("duplicate tablespace: {0}")]
124    DuplicateTablespace(crate::identifier::Identifier),
125
126    /// A `Collation` failed canon validation (e.g. nondeterministic libc).
127    #[error("collation {qname}: invalid — {reason}")]
128    InvalidCollation {
129        /// Schema-qualified collation name.
130        qname: crate::identifier::QualifiedName,
131        /// Why the collation is invalid.
132        reason: String,
133    },
134}