Skip to main content

dbschema/frontend/ast/
mod.rs

1use hcl::{Expression, Value};
2
3#[derive(Debug, Clone, Default)]
4pub struct Config {
5    pub providers: Vec<AstProvider>,
6    pub functions: Vec<AstFunction>,
7    pub procedures: Vec<AstProcedure>,
8    pub aggregates: Vec<AstAggregate>,
9    pub operators: Vec<AstOperator>,
10    pub triggers: Vec<AstTrigger>,
11    pub rules: Vec<AstRule>,
12    pub event_triggers: Vec<AstEventTrigger>,
13    pub extensions: Vec<AstExtension>,
14    pub collations: Vec<AstCollation>,
15    pub sequences: Vec<AstSequence>,
16    pub schemas: Vec<AstSchema>,
17    pub enums: Vec<AstEnum>,
18    pub domains: Vec<AstDomain>,
19    pub types: Vec<AstCompositeType>,
20    pub tables: Vec<AstTable>,
21    pub indexes: Vec<AstStandaloneIndex>,
22    pub statistics: Vec<AstStatistics>,
23    pub views: Vec<AstView>,
24    pub materialized: Vec<AstMaterializedView>,
25    pub policies: Vec<AstPolicy>,
26    pub roles: Vec<AstRole>,
27    pub tablespaces: Vec<AstTablespace>,
28    pub grants: Vec<AstGrant>,
29    pub foreign_data_wrappers: Vec<AstForeignDataWrapper>,
30    pub foreign_servers: Vec<AstForeignServer>,
31    pub foreign_tables: Vec<AstForeignTable>,
32    pub text_search_dictionaries: Vec<AstTextSearchDictionary>,
33    pub text_search_configurations: Vec<AstTextSearchConfiguration>,
34    pub text_search_templates: Vec<AstTextSearchTemplate>,
35    pub text_search_parsers: Vec<AstTextSearchParser>,
36    pub publications: Vec<AstPublication>,
37    pub subscriptions: Vec<AstSubscription>,
38    pub tests: Vec<AstTest>,
39    pub outputs: Vec<AstOutput>,
40}
41
42#[derive(Debug, Clone)]
43pub struct AstProvider {
44    pub provider_type: String,
45    pub version: Option<String>,
46}
47
48#[derive(Debug, Clone)]
49pub struct AstFunction {
50    pub name: String,
51    pub alt_name: Option<String>,
52    pub schema: Option<String>,
53    pub language: String,
54    pub parameters: Vec<String>,
55    pub returns: String,
56    pub replace: bool,
57    pub volatility: Option<String>,
58    pub strict: bool,
59    pub security: Option<String>,
60    pub cost: Option<f64>,
61    pub body: String,
62    pub comment: Option<String>,
63}
64
65#[derive(Debug, Clone)]
66pub struct AstProcedure {
67    pub name: String,
68    pub alt_name: Option<String>,
69    pub schema: Option<String>,
70    pub language: String,
71    pub parameters: Vec<String>,
72    pub replace: bool,
73    pub security: Option<String>,
74    pub body: String,
75    pub comment: Option<String>,
76}
77
78#[derive(Debug, Clone)]
79pub struct AstAggregate {
80    pub name: String,
81    pub alt_name: Option<String>,
82    pub schema: Option<String>,
83    pub inputs: Vec<String>,
84    pub sfunc: String,
85    pub stype: String,
86    pub finalfunc: Option<String>,
87    pub initcond: Option<String>,
88    pub parallel: Option<String>,
89    pub comment: Option<String>,
90}
91
92#[derive(Debug, Clone)]
93pub struct AstOperator {
94    pub name: String,
95    pub alt_name: Option<String>,
96    pub schema: Option<String>,
97    pub left: Option<String>,
98    pub right: Option<String>,
99    pub procedure: String,
100    pub commutator: Option<String>,
101    pub negator: Option<String>,
102    pub restrict: Option<String>,
103    pub join: Option<String>,
104    pub comment: Option<String>,
105}
106
107#[derive(Debug, Clone)]
108pub struct AstTrigger {
109    pub name: String,
110    pub alt_name: Option<String>,
111    pub schema: Option<String>,
112    pub table: String,
113    pub timing: String,
114    pub events: Vec<String>,
115    pub level: String,
116    pub function: String,
117    pub function_schema: Option<String>,
118    pub when: Option<String>,
119    pub comment: Option<String>,
120}
121
122#[derive(Debug, Clone)]
123pub struct AstRule {
124    pub name: String,
125    pub alt_name: Option<String>,
126    pub schema: Option<String>,
127    pub table: String,
128    pub event: String,
129    pub r#where: Option<String>,
130    pub instead: bool,
131    pub command: String,
132    pub comment: Option<String>,
133}
134
135#[derive(Debug, Clone)]
136pub struct AstEventTrigger {
137    pub name: String,
138    pub alt_name: Option<String>,
139    pub event: String,
140    pub tags: Vec<String>,
141    pub function: String,
142    pub function_schema: Option<String>,
143    pub comment: Option<String>,
144}
145
146#[derive(Debug, Clone)]
147pub struct AstExtension {
148    pub name: String,
149    pub alt_name: Option<String>,
150    pub if_not_exists: bool,
151    pub schema: Option<String>,
152    pub version: Option<String>,
153    pub comment: Option<String>,
154}
155
156#[derive(Debug, Clone)]
157pub struct AstCollation {
158    pub name: String,
159    pub alt_name: Option<String>,
160    pub schema: Option<String>,
161    pub if_not_exists: bool,
162    pub from: Option<String>,
163    pub locale: Option<String>,
164    pub lc_collate: Option<String>,
165    pub lc_ctype: Option<String>,
166    pub provider: Option<String>,
167    pub deterministic: Option<bool>,
168    pub version: Option<String>,
169    pub comment: Option<String>,
170}
171
172#[derive(Debug, Clone)]
173pub struct AstSequence {
174    pub name: String,
175    pub alt_name: Option<String>,
176    pub schema: Option<String>,
177    pub if_not_exists: bool,
178    pub r#as: Option<String>,
179    pub increment: Option<i64>,
180    pub min_value: Option<i64>,
181    pub max_value: Option<i64>,
182    pub start: Option<i64>,
183    pub cache: Option<i64>,
184    pub cycle: bool,
185    pub owned_by: Option<String>,
186    pub comment: Option<String>,
187}
188
189#[derive(Debug, Clone)]
190pub struct AstSchema {
191    pub name: String,
192    pub alt_name: Option<String>,
193    pub if_not_exists: bool,
194    pub authorization: Option<String>,
195    pub comment: Option<String>,
196}
197
198#[derive(Debug, Clone)]
199pub struct AstEnum {
200    pub name: String,
201    pub alt_name: Option<String>,
202    pub schema: Option<String>,
203    pub values: Vec<String>,
204    pub comment: Option<String>,
205}
206
207#[derive(Debug, Clone)]
208pub struct AstDomain {
209    pub name: String,
210    pub alt_name: Option<String>,
211    pub schema: Option<String>,
212    pub r#type: String,
213    pub not_null: bool,
214    pub default: Option<String>,
215    pub constraint: Option<String>,
216    pub check: Option<String>,
217    pub comment: Option<String>,
218}
219
220#[derive(Debug, Clone)]
221pub struct AstCompositeType {
222    pub name: String,
223    pub alt_name: Option<String>,
224    pub schema: Option<String>,
225    pub fields: Vec<AstCompositeTypeField>,
226    pub comment: Option<String>,
227}
228
229#[derive(Debug, Clone)]
230pub struct AstCompositeTypeField {
231    pub name: String,
232    pub r#type: String,
233}
234
235#[derive(Debug, Clone)]
236pub struct AstView {
237    pub name: String,
238    pub alt_name: Option<String>,
239    pub schema: Option<String>,
240    pub replace: bool,
241    pub sql: String,
242    pub comment: Option<String>,
243}
244
245#[derive(Debug, Clone)]
246pub struct AstMaterializedView {
247    pub name: String,
248    pub alt_name: Option<String>,
249    pub schema: Option<String>,
250    pub with_data: bool,
251    pub sql: String,
252    pub comment: Option<String>,
253}
254
255#[derive(Debug, Clone)]
256pub struct AstPolicy {
257    pub name: String,
258    pub alt_name: Option<String>,
259    pub schema: Option<String>,
260    pub table: String,
261    pub command: String,
262    pub r#as: Option<String>,
263    pub roles: Vec<String>,
264    pub using: Option<String>,
265    pub check: Option<String>,
266    pub comment: Option<String>,
267}
268
269#[derive(Debug, Clone)]
270pub struct AstRole {
271    pub name: String,
272    pub alt_name: Option<String>,
273    pub login: bool,
274    pub superuser: bool,
275    pub createdb: bool,
276    pub createrole: bool,
277    pub replication: bool,
278    pub password: Option<String>,
279    pub in_role: Vec<String>,
280    pub comment: Option<String>,
281}
282
283#[derive(Debug, Clone)]
284pub struct AstTablespace {
285    pub name: String,
286    pub alt_name: Option<String>,
287    pub location: String,
288    pub owner: Option<String>,
289    pub options: Vec<String>,
290    pub comment: Option<String>,
291}
292
293#[derive(Debug, Clone)]
294pub struct AstGrant {
295    pub name: String,
296    pub alt_name: Option<String>,
297    pub role: String,
298    pub privileges: Vec<String>,
299    pub schema: Option<String>,
300    pub table: Option<String>,
301    pub function: Option<String>,
302    pub database: Option<String>,
303    pub sequence: Option<String>,
304}
305
306#[derive(Debug, Clone)]
307pub struct AstForeignDataWrapper {
308    pub name: String,
309    pub alt_name: Option<String>,
310    pub handler: Option<String>,
311    pub validator: Option<String>,
312    pub options: Vec<String>,
313    pub comment: Option<String>,
314}
315
316#[derive(Debug, Clone)]
317pub struct AstForeignServer {
318    pub name: String,
319    pub alt_name: Option<String>,
320    pub wrapper: String,
321    pub r#type: Option<String>,
322    pub version: Option<String>,
323    pub options: Vec<String>,
324    pub comment: Option<String>,
325}
326
327#[derive(Debug, Clone)]
328pub struct AstForeignTable {
329    pub name: String,
330    pub alt_name: Option<String>,
331    pub schema: Option<String>,
332    pub server: String,
333    pub columns: Vec<AstColumn>,
334    pub options: Vec<String>,
335    pub comment: Option<String>,
336}
337
338#[derive(Debug, Clone)]
339pub struct AstTable {
340    pub name: String,
341    pub alt_name: Option<String>,
342    pub schema: Option<String>,
343    pub if_not_exists: bool,
344    pub columns: Vec<AstColumn>,
345    pub primary_key: Option<AstPrimaryKey>,
346    pub indexes: Vec<AstIndex>,
347    pub checks: Vec<AstCheck>,
348    pub foreign_keys: Vec<AstForeignKey>,
349    pub partition_by: Option<AstPartitionBy>,
350    pub partitions: Vec<AstPartition>,
351    pub back_references: Vec<AstBackReference>,
352    pub lint_ignore: Vec<String>,
353    pub comment: Option<String>,
354    pub map: Option<String>,
355}
356
357#[derive(Debug, Clone)]
358pub struct AstPartitionBy {
359    pub strategy: String,
360    pub columns: Vec<String>,
361}
362
363#[derive(Debug, Clone)]
364pub struct AstPartition {
365    pub name: String,
366    pub values: String,
367}
368
369#[derive(Debug, Clone)]
370pub struct AstBackReference {
371    pub name: String,
372    pub table: String,
373    pub relation_name: Option<String>,
374}
375
376#[derive(Debug, Clone)]
377pub struct AstColumn {
378    pub name: String,
379    pub r#type: String,
380    pub nullable: bool,
381    pub default: Option<String>,
382    pub db_type: Option<String>,
383    pub lint_ignore: Vec<String>,
384    pub comment: Option<String>,
385    pub count: usize,
386}
387
388#[derive(Debug, Clone)]
389pub struct AstPrimaryKey {
390    pub name: Option<String>,
391    pub columns: Vec<String>,
392}
393
394#[derive(Debug, Clone)]
395pub struct AstCheck {
396    pub name: Option<String>,
397    pub expression: String,
398}
399
400#[derive(Debug, Clone)]
401pub struct AstIndex {
402    pub name: Option<String>,
403    pub columns: Vec<String>,
404    pub expressions: Vec<String>,
405    pub r#where: Option<String>,
406    pub orders: Vec<String>,
407    pub operator_classes: Vec<String>,
408    pub unique: bool,
409}
410
411#[derive(Debug, Clone)]
412pub struct AstForeignKey {
413    pub name: Option<String>,
414    pub columns: Vec<String>,
415    pub ref_schema: Option<String>,
416    pub ref_table: String,
417    pub ref_columns: Vec<String>,
418    pub on_delete: Option<String>,
419    pub on_update: Option<String>,
420    pub back_reference_name: Option<String>,
421}
422
423#[derive(Debug, Clone)]
424pub struct AstStandaloneIndex {
425    pub name: String,
426    pub table: String,
427    pub schema: Option<String>,
428    pub columns: Vec<String>,
429    pub expressions: Vec<String>,
430    pub r#where: Option<String>,
431    pub orders: Vec<String>,
432    pub operator_classes: Vec<String>,
433    pub unique: bool,
434}
435
436#[derive(Debug, Clone)]
437pub struct AstStatistics {
438    pub name: String,
439    pub alt_name: Option<String>,
440    pub schema: Option<String>,
441    pub table: String,
442    pub columns: Vec<String>,
443    pub kinds: Vec<String>,
444    pub comment: Option<String>,
445}
446
447#[derive(Debug, Clone)]
448pub struct AstTextSearchDictionary {
449    pub name: String,
450    pub alt_name: Option<String>,
451    pub schema: Option<String>,
452    pub template: String,
453    pub options: Vec<String>,
454    pub comment: Option<String>,
455}
456
457#[derive(Debug, Clone)]
458pub struct AstTextSearchConfigurationMapping {
459    pub tokens: Vec<String>,
460    pub dictionaries: Vec<String>,
461}
462
463#[derive(Debug, Clone)]
464pub struct AstTextSearchConfiguration {
465    pub name: String,
466    pub alt_name: Option<String>,
467    pub schema: Option<String>,
468    pub parser: String,
469    pub mappings: Vec<AstTextSearchConfigurationMapping>,
470    pub comment: Option<String>,
471}
472
473#[derive(Debug, Clone)]
474pub struct AstTextSearchTemplate {
475    pub name: String,
476    pub alt_name: Option<String>,
477    pub schema: Option<String>,
478    pub init: Option<String>,
479    pub lexize: String,
480    pub comment: Option<String>,
481}
482
483#[derive(Debug, Clone)]
484pub struct AstTextSearchParser {
485    pub name: String,
486    pub alt_name: Option<String>,
487    pub schema: Option<String>,
488    pub start: String,
489    pub gettoken: String,
490    pub end: String,
491    pub headline: Option<String>,
492    pub lextypes: String,
493    pub comment: Option<String>,
494}
495
496#[derive(Debug, Clone)]
497pub struct AstPublication {
498    pub name: String,
499    pub alt_name: Option<String>,
500    pub all_tables: bool,
501    pub tables: Vec<AstPublicationTable>,
502    pub publish: Vec<String>,
503    pub comment: Option<String>,
504}
505
506#[derive(Debug, Clone)]
507pub struct AstPublicationTable {
508    pub schema: Option<String>,
509    pub table: String,
510}
511
512#[derive(Debug, Clone)]
513pub struct AstSubscription {
514    pub name: String,
515    pub alt_name: Option<String>,
516    pub connection: String,
517    pub publications: Vec<String>,
518    pub comment: Option<String>,
519}
520
521#[derive(Debug, Clone)]
522pub struct AstTest {
523    pub name: String,
524    pub setup: Vec<String>,
525    pub asserts: Vec<String>,
526    pub assert_fail: Vec<String>,
527    pub teardown: Vec<String>,
528}
529
530#[derive(Debug, Clone)]
531pub struct AstOutput {
532    pub name: String,
533    pub value: Value,
534}
535
536#[derive(Debug, Clone)]
537pub struct VarValidation {
538    pub condition: Expression,
539    pub error_message: Expression,
540}