joncrlsn / pgdiff

Compares the PostgreSQL schema between two databases and generates SQL statements that can be run manually against the second database to make their schemas match.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Views, Functions, and Triggers

SparkeyG opened this issue · comments

Are there plans to add Views, Functions, and Triggers to pgdiff?

I don't have plans for Views, Functions, and Triggers mostly because I don't have a need to compare those. If I had SQL that could be used to generate one or all of these I'd be willing to add some comparisons.

Triggers:

SELECT event_object_table,
       trigger_name,
       event_manipulation,
       action_timing ,
       action_statement
FROM information_schema.triggers 
ORDER BY event_object_table,event_manipulation

Constraints:

SELECT pg_class.relname as table_name,
       conname as contraint_name
FROM pg_constraint
join pg_class
  on pg_class.oid = pg_constraint.conrelid
order by pg_class.relname

Functions

SELECT
    n.nspname AS schema,
    p.oid::regprocedure AS sproc_name,
    t.typname AS return_type,
    pg_get_functiondef(p.oid) as definition
FROM pg_proc p
   JOIN pg_type t on p.prorettype = t.oid
   JOIN pg_namespace n on n.oid = p.pronamespace
   JOIN pg_language l on p.prolang = l.oid and l.lanname in ('c','plpgsql', 'sql')
WHERE n.nspname = 'public'

Views

SELECT
    viewname, 
    definition 
FROM pg_views 
WHERE schemaname = 'public' 
ORDER BY viewname

SparkeyG, You are awesome, I'll make some time to add these.

This is on branch 0.9.1 which will be merged soon.