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 trigger;
38pub mod user_type;
39pub use user_type::*;
40pub mod view;
41pub use view::*;
42
43use thiserror::Error;
44
45/// Errors raised when constructing IR values.
46#[derive(Debug, Error)]
47pub enum IrError {
48    /// An identifier did not satisfy validation rules.
49    #[error("invalid identifier: {0}")]
50    InvalidIdentifier(String),
51
52    /// A type definition was not representable in our IR.
53    #[error("invalid column type: {0}")]
54    InvalidColumnType(String),
55
56    /// A required field was missing or empty.
57    #[error("missing required field: {0}")]
58    MissingField(&'static str),
59
60    /// A `PublicationScope::Selective` had no schemas and no tables.
61    #[error("publication {0:?}: empty Selective scope (no tables, no schemas)")]
62    EmptyPublication(crate::identifier::Identifier),
63    /// A `PublishedTable.columns` was `Some(vec![])`.
64    #[error("publication {0:?} table {1:?}: empty column list (use None to publish all columns)")]
65    EmptyColumnList(
66        crate::identifier::Identifier,
67        crate::identifier::QualifiedName,
68    ),
69    /// A `PublishKinds` had all four DML flags false.
70    #[error("publication {0:?}: empty publish bitset (must enable at least one DML kind)")]
71    EmptyPublishBitset(crate::identifier::Identifier),
72    /// A `PublishedTable.columns` contained a duplicate column name.
73    #[error("publication {0:?} table {1:?}: duplicate column {2:?} in column list")]
74    DuplicateColumnInPublication(
75        crate::identifier::Identifier,
76        crate::identifier::QualifiedName,
77        crate::identifier::Identifier,
78    ),
79
80    /// A `Subscription.publications` was empty.
81    #[error("subscription {0:?}: empty publication list (PG requires at least one)")]
82    EmptySubscriptionPublications(crate::identifier::Identifier),
83    /// A `Subscription.connection` was empty or whitespace-only.
84    #[error("subscription {0:?}: empty connection string")]
85    EmptyConnection(crate::identifier::Identifier),
86
87    /// A `StatisticKinds` had all three flags false.
88    #[error(
89        "statistic {0}: empty kinds bitset (must enable at least one of ndistinct, dependencies, mcv)"
90    )]
91    EmptyStatisticKinds(crate::identifier::QualifiedName),
92    /// A `Statistic.columns` was empty.
93    #[error("statistic {0}: empty column list")]
94    EmptyStatisticColumns(crate::identifier::QualifiedName),
95
96    /// Two event triggers share a name.
97    #[error("duplicate event trigger: {0}")]
98    DuplicateEventTrigger(crate::identifier::Identifier),
99
100    /// Two aggregates share the same `(qname, arg_types)` overload identity.
101    #[error("duplicate aggregate overload: {0} (same name and argument types)")]
102    DuplicateAggregate(crate::identifier::QualifiedName),
103
104    /// Two casts share the same `(source, target)` identity.
105    #[error("duplicate cast ({src} AS {tgt})")]
106    DuplicateCast {
107        /// Source type of the duplicate cast.
108        src: crate::identifier::QualifiedName,
109        /// Target type of the duplicate cast.
110        tgt: crate::identifier::QualifiedName,
111    },
112
113    /// Two tablespaces share a name.
114    #[error("duplicate tablespace: {0}")]
115    DuplicateTablespace(crate::identifier::Identifier),
116
117    /// A `Collation` failed canon validation (e.g. nondeterministic libc).
118    #[error("collation {qname}: invalid — {reason}")]
119    InvalidCollation {
120        /// Schema-qualified collation name.
121        qname: crate::identifier::QualifiedName,
122        /// Why the collation is invalid.
123        reason: String,
124    },
125}