1use crate::analysis::expr_ir::ExprIr;
3use crate::ast::identifiers::{Ident, QualifiedName};
4
5#[derive(Clone, Debug, PartialEq)]
6pub enum PersistenceFact {
7 Permanent,
8 Temporary,
9 Unlogged,
10}
11
12#[derive(Clone, Debug, PartialEq)]
13pub enum SearchPathTarget {
14 Default,
15 Schemas(Vec<String>),
16}
17
18#[derive(Clone, Debug, PartialEq)]
19pub enum TypeCreationKind {
20 Enum,
21 Range,
22 Composite,
23 Base,
24}
25
26#[derive(Clone, Debug, PartialEq)]
27pub enum StatementFact {
28 CreateSchema {
29 name: QualifiedName,
30 if_not_exists: bool,
31 },
32 AlterSchema {
33 name: QualifiedName,
34 new_name: Option<Ident>,
35 },
36 DropSchema {
37 names: Vec<QualifiedName>,
38 if_exists: bool,
39 cascade: bool,
40 },
41 CreateTable {
42 name: QualifiedName,
43 if_not_exists: bool,
44 as_select: bool,
45 persistence: PersistenceFact,
46 columns: Vec<ColumnFact>,
47 foreign_keys: Vec<FkFact>,
48 table_constraints: Vec<TableConstraintFact>,
49 partition_by: Option<String>,
50 partition_of: Option<QualifiedName>,
51 },
52 CreateView {
53 name: QualifiedName,
54 or_replace: bool,
55 depends_on: Vec<QualifiedName>,
56 },
57 AlterView {
58 name: QualifiedName,
59 new_name: Option<Ident>,
60 },
61 CreateMaterializedView {
62 name: QualifiedName,
63 depends_on: Vec<QualifiedName>,
64 },
65 AlterMaterializedView {
66 name: QualifiedName,
67 new_name: Option<Ident>,
68 },
69 RefreshMaterializedView {
70 name: QualifiedName,
71 concurrently: bool,
72 },
73 CreateIndex {
74 name: QualifiedName,
75 relation: QualifiedName,
76 if_not_exists: bool,
77 concurrently: bool,
78 using_method: Option<String>,
79 has_predicate: bool,
80 },
81 CreatePolicy {
82 name: String,
83 table: QualifiedName,
84 },
85 DropPolicy {
86 name: String,
87 table: QualifiedName,
88 if_exists: bool,
89 },
90 CreateTrigger {
91 name: String,
92 table: QualifiedName,
93 },
94 DropTrigger {
95 name: String,
96 table: QualifiedName,
97 if_exists: bool,
98 },
99 AlterTable {
100 name: QualifiedName,
101 actions: Vec<AlterTableActionFact>,
102 },
103 AlterIndex {
104 name: QualifiedName,
105 actions: Vec<AlterIndexActionFact>,
106 },
107 CreateType(CreateTypeFact),
108 AlterType(AlterTypeFact),
109 CreateDomain {
110 name: QualifiedName,
111 base_type: String,
112 },
113 AlterDomain {
114 name: QualifiedName,
115 },
116 DropDomain {
117 names: Vec<QualifiedName>,
118 if_exists: bool,
119 },
120 CreateSequence {
121 name: QualifiedName,
122 if_not_exists: bool,
123 owned_by: Option<(QualifiedName, String)>,
124 },
125 AlterSequence {
126 name: QualifiedName,
127 owned_by: Option<(QualifiedName, String)>,
128 },
129 DropSequence {
130 names: Vec<QualifiedName>,
131 if_exists: bool,
132 },
133 DropTable {
134 name: QualifiedName,
135 if_exists: bool,
136 cascade: bool,
137 },
138 DropView {
139 names: Vec<QualifiedName>,
140 if_exists: bool,
141 },
142 DropMaterializedView {
143 names: Vec<QualifiedName>,
144 if_exists: bool,
145 },
146 DropIndex {
147 names: Vec<QualifiedName>,
148 if_exists: bool,
149 concurrently: bool,
150 },
151 SetSearchPath {
152 target: SearchPathTarget,
153 },
154 BeginTransaction,
155 CommitTransaction,
156 RollbackTransaction,
157 RollbackToSavepoint {
158 name: String,
159 },
160 Savepoint {
161 name: String,
162 },
163 ReleaseSavepoint {
164 name: String,
165 },
166 PrepareTransaction {
167 name: String,
168 },
169 SetTransaction,
170 SetConstraints,
171 OpaqueBlock,
172 Execute,
173 Vacuum {
174 is_full: bool,
175 },
176}
177
178#[derive(Clone, Debug, PartialEq)]
179pub enum AlterIndexActionFact {
180 RenameTo { new_name: Ident },
181}
182
183#[derive(Clone, Debug, PartialEq)]
184pub struct CreateTypeFact {
185 pub name: QualifiedName,
186 pub kind: TypeCreationKind,
187}
188
189#[derive(Clone, Debug, PartialEq)]
190pub struct AlterTypeFact {
191 pub name: QualifiedName,
192 pub actions: Vec<AlterTypeActionFact>,
193}
194
195#[derive(Clone, Debug, PartialEq)]
196pub enum AlterTypeActionFact {
197 AddValue { new_value: String },
198}
199
200#[derive(Clone, Debug, PartialEq)]
201pub struct ColumnFact {
202 pub name: String,
203 pub ty: Option<String>,
204 pub not_null: bool,
205 pub is_primary_key: bool,
206 pub default: Option<ExprIr>,
207}
208
209#[derive(Clone, Debug, PartialEq)]
210pub struct FkFact {
211 pub constraint_name: Option<String>,
212 pub references: QualifiedName,
213 pub from_columns: Vec<String>,
214 pub to_columns: Vec<String>,
215}
216
217#[derive(Clone, Debug, PartialEq)]
218pub enum TableConstraintFact {
219 PrimaryKey { columns: Vec<String> },
220 Unique { columns: Vec<String> },
221 Check,
222 Exclude,
223}
224
225#[derive(Clone, Debug, PartialEq)]
226pub enum AlterTableActionFact {
227 AddColumn {
228 name: String,
229 ty: Option<String>,
230 if_not_exists: bool,
231 not_null: bool,
232 default: Option<ExprIr>,
233 },
234 DropColumn {
235 name: String,
236 if_exists: bool,
237 },
238 RenameColumn {
239 from: Ident,
240 to: Ident,
241 },
242 RenameTo {
243 new_name: Ident,
244 },
245 AddForeignKey {
246 constraint_name: Option<String>,
247 references: QualifiedName,
248 from_columns: Vec<String>,
249 to_columns: Vec<String>,
250 not_valid: bool,
251 },
252 AlterConstraint {
253 name: String,
254 deferrable: bool,
255 },
256 RenameConstraint {
257 old_name: String,
258 new_name: String,
259 },
260 DropConstraint {
261 name: String,
262 },
263 AddCheckConstraint {
264 constraint_name: Option<String>,
265 not_valid: bool,
266 },
267 AddUniqueConstraint,
268 AddPrimaryKeyConstraint,
269 AddExcludeConstraint,
270 SetNotNull {
271 column: String,
272 },
273 DropNotNull {
274 column: String,
275 },
276 SetType {
277 column: String,
278 ty: String,
279 has_using: bool,
280 },
281 SetDefault {
282 column: String,
283 default: Option<ExprIr>,
284 },
285 ValidateConstraint {
286 constraint_name: String,
287 },
288 AttachPartition {
289 child: QualifiedName,
290 },
291 DetachPartition {
292 child: QualifiedName,
293 },
294 SetStorage {
295 column: String,
296 },
297 SetAccessMethod,
298}