Skip to content

Commit 5b3499e

Browse files
committed
Fix same_schema to ignore some non-logical schema based values:
operators - Use text descriptions for result type and operands; ignore related oids triggers - Include table name in key to prevent false positive when another table has a trigger with the same name. Use textual trigger definition; ignore tgqual represe functions - Use text function definition; ignore oid based types and defaults. constraints - Include table name in key to prevent false positive when another table has a constraint with the same name. Use text constraint definition; ignore oid based values. sequence - Ignore last_value; I'm confused as to why we'd want to know this on a schema check. But if required could be added back in with an optional filter instead. indexes - Ignore reltablespace oid; we check the tablespace name anyway. Ignore indkey attnum which can differ when tables have been altered differently but are otherwis
1 parent 1a25cff commit 5b3499e

File tree

1 file changed

+33
-16
lines changed

1 file changed

+33
-16
lines changed

check_postgres.pl

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,25 +1066,34 @@ package check_postgres;
10661066
},
10671067
operator => {
10681068
SQL => q{
1069-
SELECT o.*, o.oid, nspname||'.'||o.oprname AS name, quote_ident(o.oprname) AS safename,
1070-
usename AS owner, nspname AS schema,
1069+
SELECT o.*, o.oid, n.nspname||'.'||o.oprname AS name, quote_ident(o.oprname) AS safename,
1070+
usename AS owner, n.nspname AS schema,
10711071
t1.typname AS resultname,
1072-
t2.typname AS leftname, t3.typname AS rightname
1072+
t2.typname AS leftname, t3.typname AS rightname,
1073+
t4.typname AS resultname,
1074+
nneg.nspname||'.'||neg.oprname AS negname,
1075+
ncom.nspname||'.'||com.oprname AS comname
10731076
FROM pg_operator o
10741077
JOIN pg_user u ON (u.usesysid = o.oprowner)
10751078
JOIN pg_namespace n ON (n.oid = o.oprnamespace)
10761079
JOIN pg_proc p1 ON (p1.oid = o.oprcode)
10771080
JOIN pg_type t1 ON (t1.oid = o.oprresult)
10781081
LEFT JOIN pg_type t2 ON (t2.oid = o.oprleft)
1079-
LEFT JOIN pg_type t3 ON (t3.oid = o.oprright)},
1082+
LEFT JOIN pg_type t3 ON (t3.oid = o.oprright)
1083+
LEFT JOIN pg_type t4 ON (t4.oid = o.oprresult)
1084+
LEFT JOIN pg_operator neg ON (o.oprnegate = neg.oid)
1085+
LEFT JOIN pg_namespace nneg ON (nneg.oid = neg.oprnamespace)
1086+
LEFT JOIN pg_operator com ON (o.oprcom = com.oid)
1087+
LEFT JOIN pg_namespace ncom ON (ncom.oid = com.oprnamespace)},
10801088
exclude => 'system',
10811089
},
10821090
trigger => {
10831091
SQL => q{
1084-
SELECT t.*, n1.nspname||'.'||t.tgname AS name, quote_ident(t.tgname) AS safename, quote_ident(usename) AS owner,
1092+
SELECT t.*, n1.nspname||'.'||c1.relname||'.'||t.tgname AS name, quote_ident(t.tgname) AS safename, quote_ident(usename) AS owner,
10851093
n1.nspname AS tschema, c1.relname AS tname,
10861094
n2.nspname AS cschema, c2.relname AS cname,
1087-
n3.nspname AS procschema, p.proname AS procname
1095+
n3.nspname AS procschema, p.proname AS procname,
1096+
pg_get_triggerdef(t.oid) AS triggerdef
10881097
FROM pg_trigger t
10891098
JOIN pg_class c1 ON (c1.oid = t.tgrelid)
10901099
JOIN pg_user u ON (u.usesysid = c1.relowner)
@@ -1099,17 +1108,20 @@ package check_postgres;
10991108
SQL => q{
11001109
SELECT p.*, p.oid, nspname||'.'||p.proname AS name, quote_ident(p.proname) AS safename,
11011110
md5(prosrc) AS source_checksum,
1102-
usename AS owner, nspname AS schema
1111+
usename AS owner, nspname AS schema,
1112+
pg_get_function_arguments(p.oid) AS function_arguments
11031113
FROM pg_proc p
11041114
JOIN pg_user u ON (u.usesysid = p.proowner)
11051115
JOIN pg_namespace n ON (n.oid = p.pronamespace)},
11061116
exclude => 'system',
11071117
},
11081118
constraint => {
11091119
SQL => q{
1110-
SELECT c.*, c.oid, n.nspname||'.'||c.conname AS name, quote_ident(c.conname) AS safename,
1111-
n.nspname AS schema, relname AS tname
1120+
SELECT c.*, c.oid, n.nspname||'.'||c1.relname||'.'||c.conname AS name, quote_ident(c.conname) AS safename,
1121+
n.nspname AS schema, r.relname AS tname,
1122+
pg_get_constraintdef(c.oid) AS constraintdef
11121123
FROM pg_constraint c
1124+
JOIN pg_class c1 ON (c1.oid = c.conrelid)
11131125
JOIN pg_namespace n ON (n.oid = c.connamespace)
11141126
JOIN pg_class r ON (r.oid = c.conrelid)
11151127
JOIN pg_namespace n2 ON (n2.oid = r.relnamespace)},
@@ -6728,19 +6740,24 @@ sub check_same_schema {
67286740
my @catalog_items = (
67296741
[user => 'usesysid', 'useconfig' ],
67306742
[language => 'laninline,lanplcallfoid,lanvalidator', '' ],
6731-
[operator => '', '' ],
6743+
[operator => 'oprleft,oprright,oprresult,oprnegate,
6744+
oprcom', '' ],
67326745
[type => '', '' ],
67336746
[schema => '', '' ],
6734-
[function => 'source_checksum,prolang,prorettype', '' ],
6747+
[function => 'source_checksum,prolang,prorettype,
6748+
proargtypes,proallargtypes,provariadic,
6749+
proargdefaults', '' ],
67356750
[table => 'reltype,relfrozenxid,relminmxid,relpages,
67366751
reltuples,relnatts,relallvisible', '' ],
67376752
[view => 'reltype', '' ],
6738-
[sequence => 'reltype,log_cnt,relnatts,is_called', '' ],
6753+
[sequence => 'reltype,log_cnt,relnatts,is_called,
6754+
last_value', '' ],
67396755
[index => 'relpages,reltuples,indpred,indclass,
6740-
indexprs,indcheckxmin', '' ],
6741-
[trigger => '', '' ],
6742-
[constraint => 'conbin', '' ],
6743-
[column => 'atttypid,attnum,attbyval', '' ],
6756+
indexprs,indcheckxmin,reltablespace,
6757+
indkey', '' ],
6758+
[trigger => 'tgqual,tgconstraint', '' ],
6759+
[constraint => 'conbin,conindid,conkey,confkey', '' ],
6760+
[column => 'atttypid,attnum,attbyval,attndims', '' ],
67446761
);
67456762

67466763
## Where we store all the information, per-database

0 commit comments

Comments
 (0)