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