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 catalog;
10pub mod cluster;
11pub mod collation;
12pub mod column;
13pub mod column_type;
14pub mod constraint;
15pub mod default_expr;
16pub mod default_privileges;
17pub mod difference;
18pub mod eq;
19pub mod extension;
20pub mod function;
21pub mod grant;
22pub mod index;
23pub mod partition;
24pub mod policy;
25pub mod publication;
26pub mod reloptions;
27pub mod schema;
28pub mod sequence;
29pub mod statistic;
30pub mod subscription;
31pub mod table;
32pub use function::*;
33pub mod procedure;
34pub use procedure::*;
35pub mod event_trigger;
36pub mod trigger;
37pub mod user_type;
38pub use user_type::*;
39pub mod view;
40pub use view::*;
41
42use thiserror::Error;
43
44/// Errors raised when constructing IR values.
45#[derive(Debug, Error)]
46pub enum IrError {
47    /// An identifier did not satisfy validation rules.
48    #[error("invalid identifier: {0}")]
49    InvalidIdentifier(String),
50
51    /// A type definition was not representable in our IR.
52    #[error("invalid column type: {0}")]
53    InvalidColumnType(String),
54
55    /// A required field was missing or empty.
56    #[error("missing required field: {0}")]
57    MissingField(&'static str),
58
59    /// A `PublicationScope::Selective` had no schemas and no tables.
60    #[error("publication {0:?}: empty Selective scope (no tables, no schemas)")]
61    EmptyPublication(crate::identifier::Identifier),
62    /// A `PublishedTable.columns` was `Some(vec![])`.
63    #[error("publication {0:?} table {1:?}: empty column list (use None to publish all columns)")]
64    EmptyColumnList(
65        crate::identifier::Identifier,
66        crate::identifier::QualifiedName,
67    ),
68    /// A `PublishKinds` had all four DML flags false.
69    #[error("publication {0:?}: empty publish bitset (must enable at least one DML kind)")]
70    EmptyPublishBitset(crate::identifier::Identifier),
71    /// A `PublishedTable.columns` contained a duplicate column name.
72    #[error("publication {0:?} table {1:?}: duplicate column {2:?} in column list")]
73    DuplicateColumnInPublication(
74        crate::identifier::Identifier,
75        crate::identifier::QualifiedName,
76        crate::identifier::Identifier,
77    ),
78
79    /// A `Subscription.publications` was empty.
80    #[error("subscription {0:?}: empty publication list (PG requires at least one)")]
81    EmptySubscriptionPublications(crate::identifier::Identifier),
82    /// A `Subscription.connection` was empty or whitespace-only.
83    #[error("subscription {0:?}: empty connection string")]
84    EmptyConnection(crate::identifier::Identifier),
85
86    /// A `StatisticKinds` had all three flags false.
87    #[error(
88        "statistic {0}: empty kinds bitset (must enable at least one of ndistinct, dependencies, mcv)"
89    )]
90    EmptyStatisticKinds(crate::identifier::QualifiedName),
91    /// A `Statistic.columns` was empty.
92    #[error("statistic {0}: empty column list")]
93    EmptyStatisticColumns(crate::identifier::QualifiedName),
94
95    /// Two event triggers share a name.
96    #[error("duplicate event trigger: {0}")]
97    DuplicateEventTrigger(crate::identifier::Identifier),
98
99    /// Two aggregates share the same `(qname, arg_types)` overload identity.
100    #[error("duplicate aggregate overload: {0} (same name and argument types)")]
101    DuplicateAggregate(crate::identifier::QualifiedName),
102
103    /// Two tablespaces share a name.
104    #[error("duplicate tablespace: {0}")]
105    DuplicateTablespace(crate::identifier::Identifier),
106
107    /// A `Collation` failed canon validation (e.g. nondeterministic libc).
108    #[error("collation {qname}: invalid — {reason}")]
109    InvalidCollation {
110        /// Schema-qualified collation name.
111        qname: crate::identifier::QualifiedName,
112        /// Why the collation is invalid.
113        reason: String,
114    },
115}