Skip to content

Commit

Permalink
Reformat the whole tree (#10)
Browse files Browse the repository at this point in the history
Run cargo fmt, and also fix a warning about unnecessary curly braces.
  • Loading branch information
rjuju authored Feb 15, 2025
1 parent b7538c5 commit bf4bfce
Show file tree
Hide file tree
Showing 27 changed files with 2,839 additions and 2,851 deletions.
724 changes: 364 additions & 360 deletions src/compare.rs

Large diffs are not rendered by default.

207 changes: 99 additions & 108 deletions src/extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,7 @@ use pg_proc::Routine;
mod pg_type;
use pg_type::Type;

use crate::{
compare::*,
CompareStruct,
pgdiff::SchemaDiff,
pgtype::ExecutedQueries,
};
use crate::{compare::*, pgdiff::SchemaDiff, pgtype::ExecutedQueries, CompareStruct};

mod pg_aggregate;
mod pg_attribute;
Expand All @@ -43,120 +38,116 @@ mod pg_index;
mod pg_policy;
mod pg_range;
mod pg_rewrite;
mod pg_trigger;
mod pg_statistic_ext;
mod pg_trigger;

CompareStruct! {
Extension {
relations: Option<BTreeMap<String, Relation>>,
extension_config: ExtConfig,
routines: Option<BTreeMap<String, Routine>>,
event_triggers: Option<BTreeMap<String, EventTrigger>>,
operators: Option<BTreeMap<String, Operator>>,
types: Option<BTreeMap<String, Type>>,
casts: Option<BTreeMap<String, Cast>>,
foreign_data_wrappers: Option<BTreeMap<String, ForeignDataWrapper>>,
namespaces: Option<BTreeMap<String, Namespace>>,
opclasses: Option<BTreeMap<String, OpClass>>,
opfamilies: Option<BTreeMap<String, OpFamily>>,
extra_queries: ExecutedQueries,
}
Extension {
relations: Option<BTreeMap<String, Relation>>,
extension_config: ExtConfig,
routines: Option<BTreeMap<String, Routine>>,
event_triggers: Option<BTreeMap<String, EventTrigger>>,
operators: Option<BTreeMap<String, Operator>>,
types: Option<BTreeMap<String, Type>>,
casts: Option<BTreeMap<String, Cast>>,
foreign_data_wrappers: Option<BTreeMap<String, ForeignDataWrapper>>,
namespaces: Option<BTreeMap<String, Namespace>>,
opclasses: Option<BTreeMap<String, OpClass>>,
opfamilies: Option<BTreeMap<String, OpFamily>>,
extra_queries: ExecutedQueries,
}
}

impl Extension {
pub fn snapshot(extname: &str, client: &mut Transaction, pgver: u32)
-> Self
{
let extension_config = ExtConfig::snapshot(client, extname);
pub fn snapshot(extname: &str, client: &mut Transaction, pgver: u32) -> Self {
let extension_config = ExtConfig::snapshot(client, extname);

let mut ext = Extension {
ident: String::from(extname),
relations: None,
extension_config,
routines: None,
event_triggers: None,
operators: None,
types: None,
casts: None,
foreign_data_wrappers: None,
namespaces: None,
opclasses: None,
opfamilies: None,
extra_queries: ExecutedQueries::new(),
};
let mut ext = Extension {
ident: String::from(extname),
relations: None,
extension_config,
routines: None,
event_triggers: None,
operators: None,
types: None,
casts: None,
foreign_data_wrappers: None,
namespaces: None,
opclasses: None,
opfamilies: None,
extra_queries: ExecutedQueries::new(),
};

client.execute("SET search_path TO pg_catalog", &[])
.expect("Could not secure search_path");
client
.execute("SET search_path TO pg_catalog", &[])
.expect("Could not secure search_path");

let dependencies = client.query(
"SELECT classid::regclass::text, array_agg(objid) \
FROM pg_depend d \
JOIN pg_extension e ON e.oid = d.refobjid
WHERE refclassid::regclass::text = 'pg_extension' \
AND e.extname = $1 \
GROUP BY 1", &[&extname]
).expect("Could get the list of refclassid");
let dependencies = client
.query(
"SELECT classid::regclass::text, array_agg(objid) \
FROM pg_depend d \
JOIN pg_extension e ON e.oid = d.refobjid
WHERE refclassid::regclass::text = 'pg_extension' \
AND e.extname = $1 \
GROUP BY 1",
&[&extname],
)
.expect("Could get the list of refclassid");

for dependency in dependencies {
let classid: &str = dependency.get(0);
let objids: Vec<u32> = dependency.get(1);
for dependency in dependencies {
let classid: &str = dependency.get(0);
let objids: Vec<u32> = dependency.get(1);

match classid {
"pg_cast" => {
ext.casts = Some(Cast::snapshot(client,
objids, pgver));
},
"pg_class" => {
ext.relations = Some(Relation::snapshot(client,
objids, pgver));
},
"pg_event_trigger" => {
assert!(pgver >= PG_9_3,
"Event triggers were introduced in PostgreSQL 9.3");
ext.event_triggers = Some(EventTrigger::snapshot(client,
objids, pgver));
},
"pg_foreign_data_wrapper" => {
ext.foreign_data_wrappers = Some(
ForeignDataWrapper::snapshot(client, objids, pgver));
},
"pg_namespace" => {
ext.namespaces = Some(Namespace::snapshot(client,
objids, pgver));
},
"pg_opclass" => {
ext.opclasses = Some(OpClass::snapshot(client,
objids, pgver));
},
"pg_opfamily" => {
ext.opfamilies = Some(OpFamily::snapshot(client,
objids, pgver));
},
"pg_operator" => {
ext.operators = Some(Operator::snapshot(client,
objids, pgver));
},
"pg_proc" => {
ext.routines = Some(Routine::snapshot(client,
objids, pgver));
},
"pg_type" => {
ext.types = Some(Type::snapshot(client,
objids, pgver));
},
_ => {
println!("Classid \"{}\" not handled", classid);
},
}
}
match classid {
"pg_cast" => {
ext.casts = Some(Cast::snapshot(client, objids, pgver));
}
"pg_class" => {
ext.relations = Some(Relation::snapshot(client, objids, pgver));
}
"pg_event_trigger" => {
assert!(
pgver >= PG_9_3,
"Event triggers were introduced in PostgreSQL 9.3"
);
ext.event_triggers = Some(EventTrigger::snapshot(client, objids, pgver));
}
"pg_foreign_data_wrapper" => {
ext.foreign_data_wrappers =
Some(ForeignDataWrapper::snapshot(client, objids, pgver));
}
"pg_namespace" => {
ext.namespaces = Some(Namespace::snapshot(client, objids, pgver));
}
"pg_opclass" => {
ext.opclasses = Some(OpClass::snapshot(client, objids, pgver));
}
"pg_opfamily" => {
ext.opfamilies = Some(OpFamily::snapshot(client, objids, pgver));
}
"pg_operator" => {
ext.operators = Some(Operator::snapshot(client, objids, pgver));
}
"pg_proc" => {
ext.routines = Some(Routine::snapshot(client, objids, pgver));
}
"pg_type" => {
ext.types = Some(Type::snapshot(client, objids, pgver));
}
_ => {
println!("Classid \"{}\" not handled", classid);
}
}
}

client.execute("RESET search_path", &[])
.expect("Could not reset the search_path");
client
.execute("RESET search_path", &[])
.expect("Could not reset the search_path");

ext
}
ext
}

pub fn set_extra_queries(&mut self, extra_queries: ExecutedQueries) {
self.extra_queries = extra_queries;
}
pub fn set_extra_queries(&mut self, extra_queries: ExecutedQueries) {
self.extra_queries = extra_queries;
}
}
98 changes: 47 additions & 51 deletions src/extension/pg_aggregate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,62 +5,58 @@
use postgres::{Row, Transaction};

use crate::{
compare::*,
DbStruct,
elog::*,
pgdiff::SchemaDiff,
pgtype::*,
opr_prototype,
proc_prototype,
compare::*, elog::*, opr_prototype, pgdiff::SchemaDiff, pgtype::*, proc_prototype, DbStruct,
};

DbStruct! {
Aggregate:aggname:Aggregate {
aggname: Name = (proc_prototype!("a.aggfnoid")),
aggkind: Char {PG_9_4..},
aggnumdirectargs: Smallint {PG_9_4..},
aggtransfn: Text = (proc_prototype!("a.aggtransfn")),
aggfinalfn: Option<Text> = (proc_prototype!("a.aggfinalfn")),
aggcombinefn: Option<Text> = (proc_prototype!("a.aggcombinefn")) {PG_9_6..},
aggserialfn: Option<Text> = (proc_prototype!("a.aggserialfn")) {PG_9_6..},
aggdeserialfn: Option<Text> = (proc_prototype!("a.aggdeserialfn")) {PG_9_6..},
aggmtransfn: Option<Text> = (proc_prototype!("a.aggmtransfn")) {PG_9_4..},
aggminvtransfn: Option<Text> = (proc_prototype!("a.aggminvtransfn")) {PG_9_4..},
aggmfinalfn: Option<Text> = (proc_prototype!("a.aggmfinalfn")) {PG_9_4..},
aggfinalextra: Bool {PG_9_4..},
aggmfinalextra: Bool {PG_9_4..},
aggfinalmodify: Char {PG_11..},
aggmfinalmodify: Char {PG_11..},
aggsortop: Option<Text> = (opr_prototype!("o")),
aggtranstype: Text = ("aggtranstype::regtype::text"),
aggtransspace: Integer {PG_9_4..},
aggmtranstype: Option<Text> = ("aggmtranstype::regtype::text") {PG_9_4..},
aggmtransspace: Integer {PG_9_4..},
agginitval: Option<Text>,
aggminitval: Option<Text> {PG_9_4..},
comment: Option<Text> = ("obj_description(a.aggfnoid, 'pg_aggregate')"),
}
Aggregate:aggname:Aggregate {
aggname: Name = (proc_prototype!("a.aggfnoid")),
aggkind: Char {PG_9_4..},
aggnumdirectargs: Smallint {PG_9_4..},
aggtransfn: Text = (proc_prototype!("a.aggtransfn")),
aggfinalfn: Option<Text> = (proc_prototype!("a.aggfinalfn")),
aggcombinefn: Option<Text> = (proc_prototype!("a.aggcombinefn")) {PG_9_6..},
aggserialfn: Option<Text> = (proc_prototype!("a.aggserialfn")) {PG_9_6..},
aggdeserialfn: Option<Text> = (proc_prototype!("a.aggdeserialfn")) {PG_9_6..},
aggmtransfn: Option<Text> = (proc_prototype!("a.aggmtransfn")) {PG_9_4..},
aggminvtransfn: Option<Text> = (proc_prototype!("a.aggminvtransfn")) {PG_9_4..},
aggmfinalfn: Option<Text> = (proc_prototype!("a.aggmfinalfn")) {PG_9_4..},
aggfinalextra: Bool {PG_9_4..},
aggmfinalextra: Bool {PG_9_4..},
aggfinalmodify: Char {PG_11..},
aggmfinalmodify: Char {PG_11..},
aggsortop: Option<Text> = (opr_prototype!("o")),
aggtranstype: Text = ("aggtranstype::regtype::text"),
aggtransspace: Integer {PG_9_4..},
aggmtranstype: Option<Text> = ("aggmtranstype::regtype::text") {PG_9_4..},
aggmtransspace: Integer {PG_9_4..},
agginitval: Option<Text>,
aggminitval: Option<Text> {PG_9_4..},
comment: Option<Text> = ("obj_description(a.aggfnoid, 'pg_aggregate')"),
}
}

impl Aggregate {
pub fn snap_one_aggregate(client: &mut Transaction, oid: u32, pgver: u32)
-> Option<Aggregate>
{
let sql = format!("SELECT {} \
FROM pg_aggregate a \
LEFT JOIN pg_operator o ON o.oid = a.aggsortop \
WHERE a.aggfnoid = $1",
Aggregate::tlist(pgver).join(", "),
);

let row = match client.query_opt(&sql[..], &[&oid]) {
Ok(r) => { r },
Err(e) => { elog(ERROR, &format!("{}", e)); panic!(); },
};
pub fn snap_one_aggregate(client: &mut Transaction, oid: u32, pgver: u32) -> Option<Aggregate> {
let sql = format!(
"SELECT {} \
FROM pg_aggregate a \
LEFT JOIN pg_operator o ON o.oid = a.aggsortop \
WHERE a.aggfnoid = $1",
Aggregate::tlist(pgver).join(", "),
);

match row {
None => { None },
Some(r) => { Some(Aggregate::from_row(&r)) },
}
}
let row = match client.query_opt(&sql[..], &[&oid]) {
Ok(r) => r,
Err(e) => {
elog(ERROR, &format!("{}", e));
panic!();
}
};

match row {
None => None,
Some(r) => Some(Aggregate::from_row(&r)),
}
}
}
Loading

0 comments on commit bf4bfce

Please sign in to comment.